Add Line tool tests for drawing within a transformed artboard (#2572)
* Adding tests for artboard with transform * Hypercube changes suggested
This commit is contained in:
parent
1a5bef1d13
commit
b45f7ef0c7
|
|
@ -432,7 +432,9 @@ fn generate_line(tool_data: &mut LineToolData, snap_data: SnapData, lock_angle:
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_line_tool {
|
mod test_line_tool {
|
||||||
|
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
|
||||||
use crate::{messages::tool::common_functionality::graph_modification_utils::NodeGraphLayer, test_utils::test_prelude::*};
|
use crate::{messages::tool::common_functionality::graph_modification_utils::NodeGraphLayer, test_utils::test_prelude::*};
|
||||||
|
use glam::DAffine2;
|
||||||
use graph_craft::document::value::TaggedValue;
|
use graph_craft::document::value::TaggedValue;
|
||||||
|
|
||||||
async fn get_line_node_inputs(editor: &mut EditorTestUtils) -> Option<(DVec2, DVec2)> {
|
async fn get_line_node_inputs(editor: &mut EditorTestUtils) -> Option<(DVec2, DVec2)> {
|
||||||
|
|
@ -561,4 +563,42 @@ mod test_line_tool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_line_tool_with_transformed_artboard() {
|
||||||
|
let mut editor = EditorTestUtils::create();
|
||||||
|
editor.new_document().await;
|
||||||
|
editor.drag_tool(ToolType::Artboard, 0., 0., 200., 200., ModifierKeys::empty()).await;
|
||||||
|
|
||||||
|
let artboard_id = editor.get_selected_layer().await.expect("Should have selected the artboard");
|
||||||
|
|
||||||
|
editor
|
||||||
|
.handle_message(GraphOperationMessage::TransformChange {
|
||||||
|
layer: artboard_id,
|
||||||
|
transform: DAffine2::from_angle(45.0_f64.to_radians()),
|
||||||
|
transform_in: TransformIn::Local,
|
||||||
|
skip_rerender: false,
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
editor.drag_tool(ToolType::Line, 50., 50., 150., 150., ModifierKeys::empty()).await;
|
||||||
|
|
||||||
|
let (start_input, end_input) = get_line_node_inputs(&mut editor).await.expect("Line was not created successfully within transformed artboard");
|
||||||
|
// The line should still be diagonal with equal change in x and y
|
||||||
|
let line_vector = end_input - start_input;
|
||||||
|
// Verifying the line is approximately 100*sqrt(2) units in length (diagonal of 100x100 square)
|
||||||
|
let line_length = line_vector.length();
|
||||||
|
assert!(
|
||||||
|
(line_length - 141.42).abs() < 1.0, // 100 * sqrt(2) ~= 141.42
|
||||||
|
"Line length should be approximately 141.42 units. Got: {line_length}"
|
||||||
|
);
|
||||||
|
assert!((line_vector.x - 100.0).abs() < 1.0, "X-component of line vector should be approximately 100. Got: {}", line_vector.x);
|
||||||
|
assert!(
|
||||||
|
(line_vector.y.abs() - 100.0).abs() < 1.0,
|
||||||
|
"Absolute Y-component of line vector should be approximately 100. Got: {}",
|
||||||
|
line_vector.y.abs()
|
||||||
|
);
|
||||||
|
let angle_degrees = line_vector.angle_to(DVec2::X).to_degrees();
|
||||||
|
assert!((angle_degrees - (-45.0)).abs() < 1.0, "Line angle should be close to -45 degrees. Got: {angle_degrees}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::messages::tool::tool_messages::tool_prelude::Key;
|
||||||
use crate::messages::tool::utility_types::ToolType;
|
use crate::messages::tool::utility_types::ToolType;
|
||||||
use crate::node_graph_executor::Instrumented;
|
use crate::node_graph_executor::Instrumented;
|
||||||
use crate::node_graph_executor::NodeRuntime;
|
use crate::node_graph_executor::NodeRuntime;
|
||||||
|
use crate::test_utils::test_prelude::LayerNodeIdentifier;
|
||||||
use glam::DVec2;
|
use glam::DVec2;
|
||||||
use graph_craft::document::DocumentNode;
|
use graph_craft::document::DocumentNode;
|
||||||
use graphene_core::InputAccessor;
|
use graphene_core::InputAccessor;
|
||||||
|
|
@ -239,6 +240,9 @@ impl EditorTestUtils {
|
||||||
|
|
||||||
self.press(Key::Enter, ModifierKeys::empty()).await;
|
self.press(Key::Enter, ModifierKeys::empty()).await;
|
||||||
}
|
}
|
||||||
|
pub async fn get_selected_layer(&mut self) -> Option<LayerNodeIdentifier> {
|
||||||
|
self.active_document().network_interface.selected_nodes().selected_layers(self.active_document().metadata()).next()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FrontendMessageTestUtils {
|
pub trait FrontendMessageTestUtils {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue