@@ -980,3 +980,75 @@ fn zero_length() {
980
980
expect_nans ( sampler. sample ( 0.5 ) , 2 ) ;
981
981
expect_nans ( sampler. sample ( 1.0 ) , 2 ) ;
982
982
}
983
+
984
+
985
+ #[ test]
986
+ fn multiple_sub_paths ( ) {
987
+ let mut path = Path :: builder ( ) ;
988
+
989
+ path. begin ( point ( 0.0 , 0.0 ) ) ;
990
+ path. line_to ( point ( 10.0 , 0.0 ) ) ;
991
+ path. end ( false ) ;
992
+
993
+ path. begin ( point ( 10.0 , 10.0 ) ) ;
994
+ path. line_to ( point ( 20.0 , 10.0 ) ) ;
995
+ path. end ( false ) ;
996
+
997
+ let path = path. build ( ) ;
998
+ let measure = PathMeasurements :: from_path ( & path, 0.01 ) ;
999
+ let mut sampler = measure. create_sampler ( & path, SampleType :: Normalized ) ;
1000
+
1001
+ let mut dashes = Path :: builder ( ) ;
1002
+ sampler. split_range ( 0.0 .. 0.25 , & mut dashes) ;
1003
+ sampler. split_range ( 0.25 .. 0.5 , & mut dashes) ;
1004
+ // Avoid starting subpaths exactly on the join as we may begin with a zero-length subpath
1005
+ sampler. split_range ( 0.6 .. 0.75 , & mut dashes) ;
1006
+ sampler. split_range ( 0.75 .. 1.0 , & mut dashes) ;
1007
+ let dashes = dashes. build ( ) ;
1008
+
1009
+ let mut iter = dashes. iter ( ) ;
1010
+
1011
+ use crate :: path:: geom:: euclid:: approxeq:: ApproxEq ;
1012
+ fn expect_begin ( event : Option < path:: PathEvent > , pos : Point ) {
1013
+ std:: eprintln!( "- {:?}" , event) ;
1014
+ if let Some ( path:: PathEvent :: Begin { at } ) = event {
1015
+ assert ! ( at. approx_eq( & pos) , "Expected Begin {:?}, got {:?}" , pos, at) ;
1016
+ } else {
1017
+ panic ! ( "Expected begin, got {:?}" , event) ;
1018
+ }
1019
+ }
1020
+
1021
+ fn expect_end ( event : Option < path:: PathEvent > , pos : Point ) {
1022
+ std:: eprintln!( "- {:?}" , event) ;
1023
+ if let Some ( path:: PathEvent :: End { last, .. } ) = event {
1024
+ assert ! ( last. approx_eq( & pos) , "Expected End {:?}, got {:?}" , pos, last) ;
1025
+ } else {
1026
+ panic ! ( "Expected end, got {:?}" , event) ;
1027
+ }
1028
+ }
1029
+ fn expect_line ( event : Option < path:: PathEvent > , expect_from : Point , expect_to : Point ) {
1030
+ std:: eprintln!( "- {:?}" , event) ;
1031
+ if let Some ( path:: PathEvent :: Line { from, to } ) = event {
1032
+ assert ! ( from. approx_eq( & expect_from) , "Expected line {:?} {:?}, got {:?} {:?}" , expect_from, expect_to, from, to) ;
1033
+ assert ! ( to. approx_eq( & expect_to) , "Expected line {:?} {:?}, got {:?} {:?}" , expect_from, expect_to, from, to) ;
1034
+ } else {
1035
+ panic ! ( "Expected a line {:?} {:?}, got {:?}" , expect_from, expect_to, event) ;
1036
+ }
1037
+ }
1038
+
1039
+ expect_begin ( iter. next ( ) , point ( 0.0 , 0.0 ) ) ;
1040
+ expect_line ( iter. next ( ) , point ( 0.0 , 0.0 ) , point ( 5.0 , 0.0 ) ) ;
1041
+ expect_end ( iter. next ( ) , point ( 5.0 , 0.0 ) ) ;
1042
+
1043
+ expect_begin ( iter. next ( ) , point ( 5.0 , 0.0 ) ) ;
1044
+ expect_line ( iter. next ( ) , point ( 5.0 , 0.0 ) , point ( 10.0 , 0.0 ) ) ;
1045
+ expect_end ( iter. next ( ) , point ( 10.0 , 0.0 ) ) ;
1046
+
1047
+ expect_begin ( iter. next ( ) , point ( 12.0 , 10.0 ) ) ;
1048
+ expect_line ( iter. next ( ) , point ( 12.0 , 10.0 ) , point ( 15.0 , 10.0 ) ) ;
1049
+ expect_end ( iter. next ( ) , point ( 15.0 , 10.0 ) ) ;
1050
+
1051
+ expect_begin ( iter. next ( ) , point ( 15.0 , 10.0 ) ) ;
1052
+ expect_line ( iter. next ( ) , point ( 15.0 , 10.0 ) , point ( 20.0 , 10.0 ) ) ;
1053
+ expect_end ( iter. next ( ) , point ( 20.0 , 10.0 ) ) ;
1054
+ }
0 commit comments