@@ -432,7 +432,9 @@ fn generate_line(tool_data: &mut LineToolData, snap_data: SnapData, lock_angle:
432
432
433
433
#[ cfg( test) ]
434
434
mod test_line_tool {
435
+ use crate :: messages:: portfolio:: document:: graph_operation:: utility_types:: TransformIn ;
435
436
use crate :: { messages:: tool:: common_functionality:: graph_modification_utils:: NodeGraphLayer , test_utils:: test_prelude:: * } ;
437
+ use glam:: DAffine2 ;
436
438
use graph_craft:: document:: value:: TaggedValue ;
437
439
438
440
async fn get_line_node_inputs ( editor : & mut EditorTestUtils ) -> Option < ( DVec2 , DVec2 ) > {
@@ -561,4 +563,42 @@ mod test_line_tool {
561
563
}
562
564
}
563
565
}
566
+
567
+ #[ tokio:: test]
568
+ async fn test_line_tool_with_transformed_artboard ( ) {
569
+ let mut editor = EditorTestUtils :: create ( ) ;
570
+ editor. new_document ( ) . await ;
571
+ editor. drag_tool ( ToolType :: Artboard , 0. , 0. , 200. , 200. , ModifierKeys :: empty ( ) ) . await ;
572
+
573
+ let artboard_id = editor. get_selected_layer ( ) . await . expect ( "Should have selected the artboard" ) ;
574
+
575
+ editor
576
+ . handle_message ( GraphOperationMessage :: TransformChange {
577
+ layer : artboard_id,
578
+ transform : DAffine2 :: from_angle ( 45.0_f64 . to_radians ( ) ) ,
579
+ transform_in : TransformIn :: Local ,
580
+ skip_rerender : false ,
581
+ } )
582
+ . await ;
583
+
584
+ editor. drag_tool ( ToolType :: Line , 50. , 50. , 150. , 150. , ModifierKeys :: empty ( ) ) . await ;
585
+
586
+ let ( start_input, end_input) = get_line_node_inputs ( & mut editor) . await . expect ( "Line was not created successfully within transformed artboard" ) ;
587
+ // The line should still be diagonal with equal change in x and y
588
+ let line_vector = end_input - start_input;
589
+ // Verifying the line is approximately 100*sqrt(2) units in length (diagonal of 100x100 square)
590
+ let line_length = line_vector. length ( ) ;
591
+ assert ! (
592
+ ( line_length - 141.42 ) . abs( ) < 1.0 , // 100 * sqrt(2) ~= 141.42
593
+ "Line length should be approximately 141.42 units. Got: {line_length}"
594
+ ) ;
595
+ assert ! ( ( line_vector. x - 100.0 ) . abs( ) < 1.0 , "X-component of line vector should be approximately 100. Got: {}" , line_vector. x) ;
596
+ assert ! (
597
+ ( line_vector. y. abs( ) - 100.0 ) . abs( ) < 1.0 ,
598
+ "Absolute Y-component of line vector should be approximately 100. Got: {}" ,
599
+ line_vector. y. abs( )
600
+ ) ;
601
+ let angle_degrees = line_vector. angle_to ( DVec2 :: X ) . to_degrees ( ) ;
602
+ assert ! ( ( angle_degrees - ( -45.0 ) ) . abs( ) < 1.0 , "Line angle should be close to -45 degrees. Got: {angle_degrees}" ) ;
603
+ }
564
604
}
0 commit comments