@@ -364,6 +364,45 @@ mod test_freehand {
364
364
. collect ( )
365
365
}
366
366
367
+ fn verify_path_points ( vector_data_list : & [ ( VectorData , DAffine2 ) ] , expected_captured_points : & [ DVec2 ] , tolerance : f64 ) -> Result < ( ) , String > {
368
+ if vector_data_list. len ( ) == 0 {
369
+ return Err ( "No vector data found after drawing" . to_string ( ) ) ;
370
+ }
371
+
372
+ let path_data = vector_data_list. iter ( ) . find ( |( data, _) | data. point_domain . ids ( ) . len ( ) > 0 ) . ok_or ( "Could not find path data" ) ?;
373
+
374
+ let ( vector_data, transform) = path_data;
375
+ let point_count = vector_data. point_domain . ids ( ) . len ( ) ;
376
+ let segment_count = vector_data. segment_domain . ids ( ) . len ( ) ;
377
+
378
+ let actual_positions: Vec < DVec2 > = vector_data
379
+ . point_domain
380
+ . ids ( )
381
+ . iter ( )
382
+ . filter_map ( |& point_id| {
383
+ let position = vector_data. point_domain . position_from_id ( point_id) ?;
384
+ Some ( transform. transform_point2 ( position) )
385
+ } )
386
+ . collect ( ) ;
387
+
388
+ if segment_count != point_count - 1 {
389
+ return Err ( format ! ( "Expected segments to be one less than points, got {} segments for {} points" , segment_count, point_count) ) ;
390
+ }
391
+
392
+ if point_count != expected_captured_points. len ( ) {
393
+ return Err ( format ! ( "Expected {} points, got {}" , expected_captured_points. len( ) , point_count) ) ;
394
+ }
395
+
396
+ for ( i, ( & expected, & actual) ) in expected_captured_points. iter ( ) . zip ( actual_positions. iter ( ) ) . enumerate ( ) {
397
+ let distance = ( expected - actual) . length ( ) ;
398
+ if distance >= tolerance {
399
+ return Err ( format ! ( "Point {} position mismatch: expected {:?}, got {:?} (distance: {})" , i, expected, actual, distance) ) ;
400
+ }
401
+ }
402
+
403
+ Ok ( ( ) )
404
+ }
405
+
367
406
#[ tokio:: test]
368
407
async fn test_freehand_transformed_artboard ( ) {
369
408
let mut editor = EditorTestUtils :: create ( ) ;
@@ -388,64 +427,11 @@ mod test_freehand {
388
427
let mouse_points = [ DVec2 :: new ( 150.0 , 100.0 ) , DVec2 :: new ( 200.0 , 150.0 ) , DVec2 :: new ( 250.0 , 130.0 ) , DVec2 :: new ( 300.0 , 170.0 ) ] ;
389
428
390
429
// Expected points that will actually be captured by the tool
391
- let expected_captured_points = [ DVec2 :: new ( 200.0 , 150.0 ) , DVec2 :: new ( 250.0 , 130.0 ) , DVec2 :: new ( 300.0 , 170.0 ) ] ;
392
-
393
- let first_point = mouse_points[ 0 ] ;
394
- editor. move_mouse ( first_point. x , first_point. y , ModifierKeys :: empty ( ) , MouseKeys :: empty ( ) ) . await ;
395
- editor. left_mousedown ( first_point. x , first_point. y , ModifierKeys :: empty ( ) ) . await ;
396
-
397
- for & point in & mouse_points[ 1 ..] {
398
- editor. move_mouse ( point. x , point. y , ModifierKeys :: empty ( ) , MouseKeys :: LEFT ) . await ;
399
- }
400
-
401
- editor
402
- . mouseup (
403
- EditorMouseState {
404
- editor_position : mouse_points[ mouse_points. len ( ) - 1 ] ,
405
- mouse_keys : MouseKeys :: empty ( ) ,
406
- scroll_delta : ScrollDelta :: default ( ) ,
407
- } ,
408
- ModifierKeys :: empty ( ) ,
409
- )
410
- . await ;
430
+ let expected_captured_points = & mouse_points[ 1 ..] ;
431
+ editor. drag_path ( & mouse_points, ModifierKeys :: empty ( ) ) . await ;
411
432
412
433
let vector_data_list = get_vector_data ( & mut editor) . await ;
413
-
414
- assert ! ( vector_data_list. len( ) > 0 , "No vector data found after drawing" ) ;
415
-
416
- let path_data = vector_data_list. iter ( ) . find ( |( data, _) | data. point_domain . ids ( ) . len ( ) > 0 ) . expect ( "Could not find path data" ) ;
417
-
418
- let ( vector_data, transform) = path_data;
419
-
420
- let point_count = vector_data. point_domain . ids ( ) . len ( ) ;
421
- let segment_count = vector_data. segment_domain . ids ( ) . len ( ) ;
422
-
423
- let actual_positions: Vec < DVec2 > = vector_data
424
- . point_domain
425
- . ids ( )
426
- . iter ( )
427
- . filter_map ( |& point_id| {
428
- let position = vector_data. point_domain . position_from_id ( point_id) ?;
429
- Some ( transform. transform_point2 ( position) )
430
- } )
431
- . collect ( ) ;
432
-
433
- assert_eq ! ( segment_count, point_count - 1 , "Expected segments to be one less than points" ) ;
434
-
435
- assert_eq ! ( point_count, expected_captured_points. len( ) , "Expected {} points, got {}" , expected_captured_points. len( ) , point_count) ;
436
-
437
- for ( i, ( & expected, & actual) ) in expected_captured_points. iter ( ) . zip ( actual_positions. iter ( ) ) . enumerate ( ) {
438
- let distance = ( expected - actual) . length ( ) ;
439
- let tolerance = 1.0 ;
440
- assert ! (
441
- distance < tolerance,
442
- "Point {} position mismatch: expected {:?}, got {:?} (distance: {})" ,
443
- i,
444
- expected,
445
- actual,
446
- distance
447
- ) ;
448
- }
434
+ verify_path_points ( & vector_data_list, expected_captured_points, 1.0 ) . expect ( "Path points verification failed" ) ;
449
435
}
450
436
451
437
#[ tokio:: test]
0 commit comments