@@ -678,24 +678,6 @@ function filters(
678
678
}
679
679
}
680
680
681
- // convert going home to z
682
- // m 0 0 h 5 v 5 l -5 -5 -> m 0 0 h 5 v 5 z
683
- if (
684
- params . convertToZ &&
685
- ( isSafeToUseZ || next ?. command === 'Z' || next ?. command === 'z' ) &&
686
- ( command === 'l' || command === 'h' || command === 'v' )
687
- ) {
688
- if (
689
- // @ts -ignore
690
- Math . abs ( pathBase [ 0 ] - item . coords [ 0 ] ) < error &&
691
- // @ts -ignore
692
- Math . abs ( pathBase [ 1 ] - item . coords [ 1 ] ) < error
693
- ) {
694
- command = 'z' ;
695
- data = [ ] ;
696
- }
697
- }
698
-
699
681
// collapse repeated commands
700
682
// h 20 h 30 -> h 50
701
683
if (
@@ -733,9 +715,9 @@ function filters(
733
715
// @ts -ignore
734
716
prev . command === 'c' &&
735
717
// @ts -ignore
736
- data [ 0 ] === - ( prev . args [ 2 ] - prev . args [ 4 ] ) &&
718
+ Math . abs ( data [ 0 ] - - ( prev . args [ 2 ] - prev . args [ 4 ] ) ) < error &&
737
719
// @ts -ignore
738
- data [ 1 ] === - ( prev . args [ 3 ] - prev . args [ 5 ] )
720
+ Math . abs ( data [ 1 ] - - ( prev . args [ 3 ] - prev . args [ 5 ] ) ) < error
739
721
) {
740
722
command = 's' ;
741
723
data = data . slice ( 2 ) ;
@@ -746,9 +728,9 @@ function filters(
746
728
// @ts -ignore
747
729
prev . command === 's' &&
748
730
// @ts -ignore
749
- data [ 0 ] === - ( prev . args [ 0 ] - prev . args [ 2 ] ) &&
731
+ Math . abs ( data [ 0 ] - - ( prev . args [ 0 ] - prev . args [ 2 ] ) ) < error &&
750
732
// @ts -ignore
751
- data [ 1 ] === - ( prev . args [ 1 ] - prev . args [ 3 ] )
733
+ Math . abs ( data [ 1 ] - - ( prev . args [ 1 ] - prev . args [ 3 ] ) ) < error
752
734
) {
753
735
command = 's' ;
754
736
data = data . slice ( 2 ) ;
@@ -760,8 +742,8 @@ function filters(
760
742
prev . command !== 'c' &&
761
743
// @ts -ignore
762
744
prev . command !== 's' &&
763
- data [ 0 ] === 0 &&
764
- data [ 1 ] === 0
745
+ Math . abs ( data [ 0 ] ) < error &&
746
+ Math . abs ( data [ 1 ] ) < error
765
747
) {
766
748
command = 's' ;
767
749
data = data . slice ( 2 ) ;
@@ -775,9 +757,9 @@ function filters(
775
757
// @ts -ignore
776
758
prev . command === 'q' &&
777
759
// @ts -ignore
778
- data [ 0 ] === prev . args [ 2 ] - prev . args [ 0 ] &&
760
+ Math . abs ( data [ 0 ] - ( prev . args [ 2 ] - prev . args [ 0 ] ) ) < error &&
779
761
// @ts -ignore
780
- data [ 1 ] === prev . args [ 3 ] - prev . args [ 1 ]
762
+ Math . abs ( data [ 1 ] - ( prev . args [ 3 ] - prev . args [ 1 ] ) ) < error
781
763
) {
782
764
command = 't' ;
783
765
data = data . slice ( 2 ) ;
@@ -788,9 +770,9 @@ function filters(
788
770
// @ts -ignore
789
771
prev . command === 't' &&
790
772
// @ts -ignore
791
- data [ 2 ] === prev . args [ 0 ] &&
773
+ Math . abs ( data [ 2 ] - prev . args [ 0 ] ) < error &&
792
774
// @ts -ignore
793
- data [ 3 ] === prev . args [ 1 ]
775
+ Math . abs ( data [ 3 ] - prev . args [ 1 ] ) < error
794
776
) {
795
777
command = 't' ;
796
778
data = data . slice ( 2 ) ;
@@ -826,6 +808,24 @@ function filters(
826
808
}
827
809
}
828
810
811
+ // convert going home to z
812
+ // m 0 0 h 5 v 5 l -5 -5 -> m 0 0 h 5 v 5 z
813
+ if (
814
+ params . convertToZ &&
815
+ ( isSafeToUseZ || next ?. command === 'Z' || next ?. command === 'z' ) &&
816
+ ( command === 'l' || command === 'h' || command === 'v' )
817
+ ) {
818
+ if (
819
+ // @ts -ignore
820
+ Math . abs ( pathBase [ 0 ] - item . coords [ 0 ] ) < error &&
821
+ // @ts -ignore
822
+ Math . abs ( pathBase [ 1 ] - item . coords [ 1 ] ) < error
823
+ ) {
824
+ command = 'z' ;
825
+ data = [ ] ;
826
+ }
827
+ }
828
+
829
829
item . command = command ;
830
830
item . args = data ;
831
831
} else {
@@ -870,7 +870,8 @@ function convertToMixed(path, params) {
870
870
871
871
var command = item . command ,
872
872
data = item . args ,
873
- adata = data . slice ( ) ;
873
+ adata = data . slice ( ) ,
874
+ rdata = data . slice ( ) ;
874
875
875
876
if (
876
877
command === 'm' ||
@@ -898,9 +899,10 @@ function convertToMixed(path, params) {
898
899
}
899
900
900
901
roundData ( adata ) ;
902
+ roundData ( rdata ) ;
901
903
902
904
var absoluteDataStr = cleanupOutData ( adata , params ) ,
903
- relativeDataStr = cleanupOutData ( data , params ) ;
905
+ relativeDataStr = cleanupOutData ( rdata , params ) ;
904
906
905
907
// Convert to absolute coordinates if it's shorter or forceAbsolutePath is true.
906
908
// v-20 -> V0
0 commit comments