@@ -536,7 +536,6 @@ fn delete_preview(tool_data: &mut SplineToolData, responses: &mut VecDeque<Messa
536
536
}
537
537
#[ cfg( test) ]
538
538
mod test_spline_tool {
539
- use crate :: messages:: input_mapper:: utility_types:: input_mouse:: { EditorMouseState , ScrollDelta } ;
540
539
use crate :: messages:: portfolio:: document:: graph_operation:: utility_types:: TransformIn ;
541
540
use crate :: messages:: tool:: tool_messages:: spline_tool:: find_spline;
542
541
use crate :: test_utils:: test_prelude:: * ;
@@ -548,7 +547,6 @@ mod test_spline_tool {
548
547
editor. new_document ( ) . await ;
549
548
550
549
editor. drag_tool ( ToolType :: Artboard , 0. , 0. , 500. , 500. , ModifierKeys :: empty ( ) ) . await ;
551
-
552
550
let document = editor. active_document ( ) ;
553
551
let artboard_layer = document. network_interface . selected_nodes ( ) . selected_layers ( document. metadata ( ) ) . next ( ) . unwrap ( ) ;
554
552
@@ -561,75 +559,53 @@ mod test_spline_tool {
561
559
} )
562
560
. await ;
563
561
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 ;
562
+ let spline_points = [ DVec2 :: new ( 100. , 100. ) , DVec2 :: new ( 200. , 150. ) , DVec2 :: new ( 300. , 100. ) ] ;
609
563
610
- // Execute the graph to ensure everything is processed
611
- let _instrumented = editor. eval_graph ( ) . await ;
564
+ editor. draw_spline ( & spline_points) . await ;
612
565
613
566
let document = editor. active_document ( ) ;
614
567
615
568
let mut layers = document. metadata ( ) . all_layers ( ) ;
616
-
617
569
layers. next ( ) ;
618
570
619
571
let spline_layer = layers. next ( ) . expect ( "Failed to find the spline layer" ) ;
620
-
621
572
assert ! ( find_spline( document, spline_layer) . is_some( ) , "Spline node not found in the layer" ) ;
622
573
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 ( ) ;
574
+ let vector_data = document. network_interface . compute_modified_vector ( spline_layer) . expect ( "Vector data not found for the spline layer" ) ;
627
575
628
576
// Verify we have the correct number of points and segments
629
577
let point_count = vector_data. point_domain . ids ( ) . len ( ) ;
630
578
let segment_count = vector_data. segment_domain . ids ( ) . len ( ) ;
631
579
632
580
assert_eq ! ( point_count, 3 , "Expected 3 points in the spline, found {}" , point_count) ;
633
581
assert_eq ! ( segment_count, 2 , "Expected 2 segments in the spline, found {}" , segment_count) ;
582
+
583
+ let layer_to_viewport = document. metadata ( ) . transform_to_viewport ( spline_layer) ;
584
+
585
+ let points_in_viewport: Vec < DVec2 > = vector_data
586
+ . point_domain
587
+ . ids ( )
588
+ . iter ( )
589
+ . filter_map ( |& point_id| {
590
+ let position = vector_data. point_domain . position_from_id ( point_id) ?;
591
+ Some ( layer_to_viewport. transform_point2 ( position) )
592
+ } )
593
+ . collect ( ) ;
594
+
595
+ // Verify each point position is close to the expected position
596
+ let epsilon = 1e-10 ;
597
+ for ( i, expected_point) in spline_points. iter ( ) . enumerate ( ) {
598
+ let actual_point = points_in_viewport[ i] ;
599
+ let distance = ( actual_point - * expected_point) . length ( ) ;
600
+
601
+ assert ! (
602
+ distance < epsilon,
603
+ "Point {} position mismatch: expected {:?}, got {:?} (distance: {})" ,
604
+ i,
605
+ expected_point,
606
+ actual_point,
607
+ distance
608
+ ) ;
609
+ }
634
610
}
635
611
}
0 commit comments