@@ -6,59 +6,65 @@ import { SVGPathData } from '../index.js';
66// Here we have to round output before testing since there is some lil
77// differences across browsers.
88
9+ function testArcToCurve ( input : string ) {
10+ return new SVGPathData ( input ) . aToC ( ) . round ( ) . encode ( ) ;
11+ }
12+
913describe ( 'Converting elliptical arc commands to curves' , ( ) => {
1014 test ( 'should work sweepFlag on 0 and largeArcFlag on 0' , ( ) => {
1115 expect (
12- new SVGPathData ( 'M80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 Z' )
13- . aToC ( )
14- . round ( )
15- . encode ( ) ,
16+ testArcToCurve ( 'M80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 Z' ) ,
1617 ) . toEqual (
1718 'M80 80C80 104.8528137423857 100.1471862576143 125 125 125L125 80z' ,
1819 ) ;
1920 } ) ;
2021
2122 test ( 'should work sweepFlag on 1 and largeArcFlag on 0' , ( ) => {
2223 expect (
23- new SVGPathData ( 'M230 80 A 45 45, 0, 1, 0, 275 125 L 275 80 Z' )
24- . aToC ( )
25- . round ( )
26- . encode ( ) ,
24+ testArcToCurve ( 'M230 80 A 45 45, 0, 1, 0, 275 125 L 275 80 Z' ) ,
2725 ) . toEqual (
2826 'M230 80C205.1471862576143 80 185 100.1471862576143 185 125C185 149.8528137423857 205.1471862576143 170 230 170C254.8528137423857 170 275 149.8528137423857 275 125L275 80z' ,
2927 ) ;
3028 } ) ;
3129
3230 test ( 'should work sweepFlag on 0 and largeArcFlag on 1' , ( ) => {
3331 expect (
34- new SVGPathData ( 'M80 230 A 45 45, 0, 0, 1, 125 275 L 125 230 Z' )
35- . aToC ( )
36- . round ( )
37- . encode ( ) ,
32+ testArcToCurve ( 'M80 230 A 45 45, 0, 0, 1, 125 275 L 125 230 Z' ) ,
3833 ) . toEqual (
3934 'M80 230C104.8528137423857 230 125 250.1471862576143 125 275L125 230z' ,
4035 ) ;
4136 } ) ;
4237
4338 test ( 'should work sweepFlag on 1 and largeArcFlag on 1' , ( ) => {
4439 expect (
45- new SVGPathData ( 'M230 230 A 45 45, 0, 1, 1, 275 275 L 275 230 Z' )
46- . aToC ( )
47- . round ( )
48- . encode ( ) ,
40+ testArcToCurve ( 'M230 230 A 45 45, 0, 1, 1, 275 275 L 275 230 Z' ) ,
4941 ) . toEqual (
5042 'M230 230C230 205.1471862576143 250.1471862576143 185 275 185C299.8528137423857 185 320 205.1471862576143 320 230C320 254.8528137423857 299.8528137423857 275 275 275L275 230z' ,
5143 ) ;
5244 } ) ;
5345
5446 test ( 'should work sweepFlag on 0 and largeArcFlag on 0 with relative arc' , ( ) => {
5547 expect (
56- new SVGPathData ( 'M80 80 a 45 45, 0, 0, 0, 125 125 L 125 80 Z' )
57- . aToC ( )
58- . round ( )
59- . encode ( ) ,
48+ testArcToCurve ( 'M80 80 a 45 45, 0, 0, 0, 125 125 L 125 80 Z' ) ,
6049 ) . toEqual (
6150 'M80 80c-34.5177968644246 34.5177968644246 -34.5177968644246 90.4822031355754 0 125c34.5177968644246 34.5177968644246 90.4822031355754 34.5177968644246 125 0L125 80z' ,
6251 ) ;
6352 } ) ;
53+
54+ test ( 'should handle zero radius arcs by converting to lines' , ( ) => {
55+ // Zero y-radius
56+ expect ( testArcToCurve ( 'M0 0A80 0 0 0 0 125 125' ) ) . toEqual (
57+ 'M0 0C41.6666666666667 41.6666666666667 83.3333333333333 83.3333333333333 125 125' ,
58+ ) ;
59+
60+ // Zero x-radius
61+ expect ( testArcToCurve ( 'M0 0A0 80 0 0 0 125 125' ) ) . toEqual (
62+ 'M0 0C41.6666666666667 41.6666666666667 83.3333333333333 83.3333333333333 125 125' ,
63+ ) ;
64+
65+ // Both x and y radius zero
66+ expect ( testArcToCurve ( 'M0 0A0 0 0 0 0 125 125' ) ) . toEqual (
67+ 'M0 0C41.6666666666667 41.6666666666667 83.3333333333333 83.3333333333333 125 125' ,
68+ ) ;
69+ } ) ;
6470} ) ;
0 commit comments