-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add path2Array function (#113)
* feat: add path2Array function * chore: bump v3.3.7
- Loading branch information
Showing
5 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { path2Array, PathArray } from '../../../src'; | ||
|
||
describe('string to path', () => { | ||
it('should transform path to array correctly.', () => { | ||
const str = 'M10 10L100 100l10 10h20v20'; | ||
|
||
expect(path2Array(str)).toEqual([ | ||
['M', 10, 10], | ||
['L', 100, 100], | ||
['l', 10, 10], | ||
['h', 20], | ||
['v', 20], | ||
]); | ||
|
||
function getCirclePath(cx: number, cy: number, rx: number, ry: number): PathArray { | ||
return [ | ||
// ['M', cx, cy - ry], | ||
// ['A', rx, ry, 0, 1, 1, cx, cy + ry], | ||
// ['A', rx, ry, 0, 1, 1, cx, cy - ry], | ||
['M', cx - rx, ry], | ||
['A', rx, ry, 0, 1, 0, cx + rx, ry], | ||
['A', rx, ry, 0, 1, 0, cx - rx, ry], | ||
['Z'], | ||
]; | ||
} | ||
|
||
expect(path2Array('M-100 100A100 100 0 1 0 100 100A100 100 0 1 0 -100 100Z')).toEqual( | ||
getCirclePath(0, 0, 100, 100), | ||
); | ||
|
||
expect( | ||
path2Array( | ||
'M2 4A2 2 0 0 0 0 6V12A2 2 0 0 0 2 14H14A2 2 0 0 0 16 12V6A2 2 0 0 0 14 4H12.828A2 2 0 0 1 11.414 3.414L10.586 2.586A2 2 0 0 0 9.172 2H6.828A2 2 0 0 0 5.414 2.586L4.586 3.414A2 2 0 0 1 3.172 4H2ZM10.5 8.5A2.5 2.5 0 0 0 5.5 8.5A2.5 2.5 0 1 0 10.5 8.5ZM2.5 6A0.5 0.5 0 0 1 2.5 5A0.5 0.5 0 1 1 2.5 6ZM11.5 8.5A3.5 3.5 0 1 1 4.5 8.5A3.5 3.5 0 0 1 11.5 8.5Z', | ||
), | ||
).toEqual([ | ||
['M', 2, 4], | ||
['A', 2, 2, 0, 0, 0, 0, 6], | ||
['V', 12], | ||
['A', 2, 2, 0, 0, 0, 2, 14], | ||
['H', 14], | ||
['A', 2, 2, 0, 0, 0, 16, 12], | ||
['V', 6], | ||
['A', 2, 2, 0, 0, 0, 14, 4], | ||
['H', 12.828], | ||
['A', 2, 2, 0, 0, 1, 11.414, 3.414], | ||
['L', 10.586, 2.586], | ||
['A', 2, 2, 0, 0, 0, 9.172, 2], | ||
['H', 6.828], | ||
['A', 2, 2, 0, 0, 0, 5.414, 2.586], | ||
['L', 4.586, 3.414], | ||
['A', 2, 2, 0, 0, 1, 3.172, 4], | ||
['H', 2], | ||
['Z'], | ||
['M', 10.5, 8.5], | ||
['A', 2.5, 2.5, 0, 0, 0, 5.5, 8.5], | ||
['A', 2.5, 2.5, 0, 1, 0, 10.5, 8.5], | ||
['Z'], | ||
['M', 2.5, 6], | ||
['A', 0.5, 0.5, 0, 0, 1, 2.5, 5], | ||
['A', 0.5, 0.5, 0, 1, 1, 2.5, 6], | ||
['Z'], | ||
['M', 11.5, 8.5], | ||
['A', 3.5, 3.5, 0, 1, 1, 4.5, 8.5], | ||
['A', 3.5, 3.5, 0, 0, 1, 11.5, 8.5], | ||
['Z'], | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { parsePathString } from '../parser/parse-path-string'; | ||
import type { PathArray } from '../types'; | ||
|
||
export function path2Array(pathInput: string): PathArray { | ||
return parsePathString(pathInput) as PathArray; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters