diff --git a/editor/src/messages/tool/tool_messages/line_tool.rs b/editor/src/messages/tool/tool_messages/line_tool.rs index 7e8fa5be97..b0ace3426f 100644 --- a/editor/src/messages/tool/tool_messages/line_tool.rs +++ b/editor/src/messages/tool/tool_messages/line_tool.rs @@ -432,7 +432,9 @@ fn generate_line(tool_data: &mut LineToolData, snap_data: SnapData, lock_angle: #[cfg(test)] 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 glam::DAffine2; use graph_craft::document::value::TaggedValue; 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}"); + } } diff --git a/editor/src/test_utils.rs b/editor/src/test_utils.rs index 0ce439c57b..a91ab49c8e 100644 --- a/editor/src/test_utils.rs +++ b/editor/src/test_utils.rs @@ -8,6 +8,7 @@ use crate::messages::tool::tool_messages::tool_prelude::Key; use crate::messages::tool::utility_types::ToolType; use crate::node_graph_executor::Instrumented; use crate::node_graph_executor::NodeRuntime; +use crate::test_utils::test_prelude::LayerNodeIdentifier; use glam::DVec2; use graph_craft::document::DocumentNode; use graphene_core::InputAccessor; @@ -239,6 +240,9 @@ impl EditorTestUtils { self.press(Key::Enter, ModifierKeys::empty()).await; } + pub async fn get_selected_layer(&mut self) -> Option { + self.active_document().network_interface.selected_nodes().selected_layers(self.active_document().metadata()).next() + } } pub trait FrontendMessageTestUtils {