@@ -534,3 +534,102 @@ fn delete_preview(tool_data: &mut SplineToolData, responses: &mut VecDeque<Messa
534
534
tool_data. preview_point = None ;
535
535
tool_data. preview_segment = None ;
536
536
}
537
+ #[ cfg( test) ]
538
+ mod test_spline_tool {
539
+ use crate :: messages:: input_mapper:: utility_types:: input_mouse:: { EditorMouseState , ScrollDelta } ;
540
+ use crate :: messages:: portfolio:: document:: graph_operation:: utility_types:: TransformIn ;
541
+ use crate :: messages:: tool:: tool_messages:: spline_tool:: find_spline;
542
+ use crate :: test_utils:: test_prelude:: * ;
543
+ use glam:: DAffine2 ;
544
+
545
+ #[ tokio:: test]
546
+ async fn test_spline_tool_with_transformed_artboard ( ) {
547
+ let mut editor = EditorTestUtils :: create ( ) ;
548
+ editor. new_document ( ) . await ;
549
+
550
+ editor. drag_tool ( ToolType :: Artboard , 0. , 0. , 500. , 500. , ModifierKeys :: empty ( ) ) . await ;
551
+
552
+ let document = editor. active_document ( ) ;
553
+ let artboard_layer = document. network_interface . selected_nodes ( ) . selected_layers ( document. metadata ( ) ) . next ( ) . unwrap ( ) ;
554
+
555
+ editor
556
+ . handle_message ( GraphOperationMessage :: TransformSet {
557
+ layer : artboard_layer,
558
+ transform : DAffine2 :: from_scale_angle_translation ( DVec2 :: new ( 1.5 , 1.2 ) , 30.0_f64 . to_radians ( ) , DVec2 :: new ( 50.0 , 25.0 ) ) ,
559
+ transform_in : TransformIn :: Local ,
560
+ skip_rerender : false ,
561
+ } )
562
+ . await ;
563
+
564
+ let spline_start = DVec2 :: new ( 100. , 100. ) ;
565
+ let spline_mid = DVec2 :: new ( 200. , 150. ) ;
566
+ let spline_end = DVec2 :: new ( 300. , 100. ) ;
567
+
568
+ editor. select_tool ( ToolType :: Spline ) . await ;
569
+ editor. move_mouse ( spline_start. x , spline_start. y , ModifierKeys :: empty ( ) , MouseKeys :: empty ( ) ) . await ;
570
+ editor. left_mousedown ( spline_start. x , spline_start. y , ModifierKeys :: empty ( ) ) . await ;
571
+ editor
572
+ . mouseup (
573
+ EditorMouseState {
574
+ editor_position : spline_start,
575
+ mouse_keys : MouseKeys :: empty ( ) ,
576
+ scroll_delta : ScrollDelta :: default ( ) ,
577
+ } ,
578
+ ModifierKeys :: empty ( ) ,
579
+ )
580
+ . await ;
581
+
582
+ editor. move_mouse ( spline_mid. x , spline_mid. y , ModifierKeys :: empty ( ) , MouseKeys :: empty ( ) ) . await ;
583
+ editor. left_mousedown ( spline_mid. x , spline_mid. y , ModifierKeys :: empty ( ) ) . await ;
584
+ editor
585
+ . mouseup (
586
+ EditorMouseState {
587
+ editor_position : spline_mid,
588
+ mouse_keys : MouseKeys :: empty ( ) ,
589
+ scroll_delta : ScrollDelta :: default ( ) ,
590
+ } ,
591
+ ModifierKeys :: empty ( ) ,
592
+ )
593
+ . await ;
594
+
595
+ editor. move_mouse ( spline_end. x , spline_end. y , ModifierKeys :: empty ( ) , MouseKeys :: empty ( ) ) . await ;
596
+ editor. left_mousedown ( spline_end. x , spline_end. y , ModifierKeys :: empty ( ) ) . await ;
597
+ editor
598
+ . mouseup (
599
+ EditorMouseState {
600
+ editor_position : spline_end,
601
+ mouse_keys : MouseKeys :: empty ( ) ,
602
+ scroll_delta : ScrollDelta :: default ( ) ,
603
+ } ,
604
+ ModifierKeys :: empty ( ) ,
605
+ )
606
+ . await ;
607
+
608
+ editor. press ( Key :: Enter , ModifierKeys :: empty ( ) ) . await ;
609
+
610
+ // Execute the graph to ensure everything is processed
611
+ let _instrumented = editor. eval_graph ( ) . await ;
612
+
613
+ let document = editor. active_document ( ) ;
614
+
615
+ let mut layers = document. metadata ( ) . all_layers ( ) ;
616
+
617
+ layers. next ( ) ;
618
+
619
+ let spline_layer = layers. next ( ) . expect ( "Failed to find the spline layer" ) ;
620
+
621
+ assert ! ( find_spline( document, spline_layer) . is_some( ) , "Spline node not found in the layer" ) ;
622
+
623
+ let vector_data = document. network_interface . compute_modified_vector ( spline_layer) ;
624
+ assert ! ( vector_data. is_some( ) , "Vector data not found for the spline layer" ) ;
625
+
626
+ let vector_data = vector_data. unwrap ( ) ;
627
+
628
+ // Verify we have the correct number of points and segments
629
+ let point_count = vector_data. point_domain . ids ( ) . len ( ) ;
630
+ let segment_count = vector_data. segment_domain . ids ( ) . len ( ) ;
631
+
632
+ assert_eq ! ( point_count, 3 , "Expected 3 points in the spline, found {}" , point_count) ;
633
+ assert_eq ! ( segment_count, 2 , "Expected 2 segments in the spline, found {}" , segment_count) ;
634
+ }
635
+ }
0 commit comments