Skip to content

Commit

Permalink
Fix Path.transform
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Nov 29, 2023
1 parent 907de4c commit b8893df
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,24 @@ export namespace Path {
* @returns The transformed path
*/
export function transform(path: Path, matrix: mat2d): Path {
return path.map(([command, ...points]) => {
switch (command) {
return path.map(seg => {
switch (seg[0]) {
case 'M':
case 'L':
case 'Q':
case 'T':
case 'C':
case 'S':
return [
command,
...(points as vec2[]).map(p => vec2.transformMat2d(p, matrix)),
seg[0],
...(seg.slice(1) as vec2[]).map(p =>
vec2.transformMat2d(p, matrix)
),
]
case 'H':
return [
command,
vec2.transformMat2d([points[0] as number, 0], matrix)[0],
]
return ['L', vec2.transformMat2d([seg[1], 0], matrix)[0]]
case 'V':
return [
command,
vec2.transformMat2d([0, points[0] as number], matrix)[0],
]
return ['L', vec2.transformMat2d([0, seg[1]], matrix)[0]]
case 'A':
throw new Error('Not implemented')
case 'Z':
Expand Down

0 comments on commit b8893df

Please sign in to comment.