@@ -537,6 +537,7 @@ fn delete_preview(tool_data: &mut SplineToolData, responses: &mut VecDeque<Messa
537
537
538
538
#[ cfg( test) ]
539
539
mod test_spline_tool {
540
+ use crate :: messages:: portfolio:: document:: graph_operation:: utility_types:: TransformIn ;
540
541
use crate :: messages:: tool:: tool_messages:: spline_tool:: find_spline;
541
542
use crate :: test_utils:: test_prelude:: * ;
542
543
use glam:: DAffine2 ;
@@ -806,7 +807,6 @@ mod test_spline_tool {
806
807
editor. new_document ( ) . await ;
807
808
808
809
editor. drag_tool ( ToolType :: Artboard , 0. , 0. , 500. , 500. , ModifierKeys :: empty ( ) ) . await ;
809
-
810
810
let document = editor. active_document ( ) ;
811
811
let artboard_layer = document. network_interface . selected_nodes ( ) . selected_layers ( document. metadata ( ) ) . next ( ) . unwrap ( ) ;
812
812
@@ -819,75 +819,53 @@ mod test_spline_tool {
819
819
} )
820
820
. await ;
821
821
822
- let spline_start = DVec2 :: new ( 100. , 100. ) ;
823
- let spline_mid = DVec2 :: new ( 200. , 150. ) ;
824
- let spline_end = DVec2 :: new ( 300. , 100. ) ;
822
+ let spline_points = [ DVec2 :: new ( 100. , 100. ) , DVec2 :: new ( 200. , 150. ) , DVec2 :: new ( 300. , 100. ) ] ;
825
823
826
- editor. select_tool ( ToolType :: Spline ) . await ;
827
- editor. move_mouse ( spline_start. x , spline_start. y , ModifierKeys :: empty ( ) , MouseKeys :: empty ( ) ) . await ;
828
- editor. left_mousedown ( spline_start. x , spline_start. y , ModifierKeys :: empty ( ) ) . await ;
829
- editor
830
- . mouseup (
831
- EditorMouseState {
832
- editor_position : spline_start,
833
- mouse_keys : MouseKeys :: empty ( ) ,
834
- scroll_delta : ScrollDelta :: default ( ) ,
835
- } ,
836
- ModifierKeys :: empty ( ) ,
837
- )
838
- . await ;
839
-
840
- editor. move_mouse ( spline_mid. x , spline_mid. y , ModifierKeys :: empty ( ) , MouseKeys :: empty ( ) ) . await ;
841
- editor. left_mousedown ( spline_mid. x , spline_mid. y , ModifierKeys :: empty ( ) ) . await ;
842
- editor
843
- . mouseup (
844
- EditorMouseState {
845
- editor_position : spline_mid,
846
- mouse_keys : MouseKeys :: empty ( ) ,
847
- scroll_delta : ScrollDelta :: default ( ) ,
848
- } ,
849
- ModifierKeys :: empty ( ) ,
850
- )
851
- . await ;
852
-
853
- editor. move_mouse ( spline_end. x , spline_end. y , ModifierKeys :: empty ( ) , MouseKeys :: empty ( ) ) . await ;
854
- editor. left_mousedown ( spline_end. x , spline_end. y , ModifierKeys :: empty ( ) ) . await ;
855
- editor
856
- . mouseup (
857
- EditorMouseState {
858
- editor_position : spline_end,
859
- mouse_keys : MouseKeys :: empty ( ) ,
860
- scroll_delta : ScrollDelta :: default ( ) ,
861
- } ,
862
- ModifierKeys :: empty ( ) ,
863
- )
864
- . await ;
865
-
866
- editor. press ( Key :: Enter , ModifierKeys :: empty ( ) ) . await ;
867
-
868
- // Execute the graph to ensure everything is processed
869
- let _instrumented = editor. eval_graph ( ) . await ;
824
+ editor. draw_spline ( & spline_points) . await ;
870
825
871
826
let document = editor. active_document ( ) ;
872
827
873
828
let mut layers = document. metadata ( ) . all_layers ( ) ;
874
-
875
829
layers. next ( ) ;
876
830
877
831
let spline_layer = layers. next ( ) . expect ( "Failed to find the spline layer" ) ;
878
-
879
832
assert ! ( find_spline( document, spline_layer) . is_some( ) , "Spline node not found in the layer" ) ;
880
833
881
- let vector_data = document. network_interface . compute_modified_vector ( spline_layer) ;
882
- assert ! ( vector_data. is_some( ) , "Vector data not found for the spline layer" ) ;
883
-
884
- let vector_data = vector_data. unwrap ( ) ;
834
+ let vector_data = document. network_interface . compute_modified_vector ( spline_layer) . expect ( "Vector data not found for the spline layer" ) ;
885
835
886
836
// Verify we have the correct number of points and segments
887
837
let point_count = vector_data. point_domain . ids ( ) . len ( ) ;
888
838
let segment_count = vector_data. segment_domain . ids ( ) . len ( ) ;
889
839
890
840
assert_eq ! ( point_count, 3 , "Expected 3 points in the spline, found {}" , point_count) ;
891
841
assert_eq ! ( segment_count, 2 , "Expected 2 segments in the spline, found {}" , segment_count) ;
842
+
843
+ let layer_to_viewport = document. metadata ( ) . transform_to_viewport ( spline_layer) ;
844
+
845
+ let points_in_viewport: Vec < DVec2 > = vector_data
846
+ . point_domain
847
+ . ids ( )
848
+ . iter ( )
849
+ . filter_map ( |& point_id| {
850
+ let position = vector_data. point_domain . position_from_id ( point_id) ?;
851
+ Some ( layer_to_viewport. transform_point2 ( position) )
852
+ } )
853
+ . collect ( ) ;
854
+
855
+ // Verify each point position is close to the expected position
856
+ let epsilon = 1e-10 ;
857
+ for ( i, expected_point) in spline_points. iter ( ) . enumerate ( ) {
858
+ let actual_point = points_in_viewport[ i] ;
859
+ let distance = ( actual_point - * expected_point) . length ( ) ;
860
+
861
+ assert ! (
862
+ distance < epsilon,
863
+ "Point {} position mismatch: expected {:?}, got {:?} (distance: {})" ,
864
+ i,
865
+ expected_point,
866
+ actual_point,
867
+ distance
868
+ ) ;
869
+ }
892
870
}
893
871
}
0 commit comments