-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply rotations to any figure (#168)
* Apply rotations to any figure * add changelog * apply rotations to curves too
- Loading branch information
1 parent
4591369
commit 202e7f4
Showing
17 changed files
with
246 additions
and
196 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"penpot-exporter": minor | ||
--- | ||
|
||
Implement rotation for any arbitrary figure |
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
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
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
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,33 @@ | ||
import { ShapeBaseAttributes } from '@ui/lib/types/shapes/shape'; | ||
|
||
export const translateRotation = ( | ||
transform: Transform, | ||
rotation: number | ||
): Pick<ShapeBaseAttributes, 'transform' | 'transformInverse' | 'rotation'> => ({ | ||
rotation: -rotation < 0 ? -rotation + 360 : -rotation, | ||
transform: { | ||
a: transform[0][0], | ||
b: transform[1][0], | ||
c: transform[0][1], | ||
d: transform[1][1], | ||
e: 0, | ||
f: 0 | ||
}, | ||
transformInverse: { | ||
a: transform[0][0], | ||
b: transform[0][1], | ||
c: transform[1][0], | ||
d: transform[1][1], | ||
e: 0, | ||
f: 0 | ||
} | ||
}); | ||
|
||
export const translateZeroRotation = (): Pick< | ||
ShapeBaseAttributes, | ||
'transform' | 'transformInverse' | 'rotation' | ||
> => ({ | ||
rotation: 0, | ||
transform: undefined, | ||
transformInverse: undefined | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './translateCommandsToSegments'; | ||
export * from './translateLineNode'; | ||
export * from './translatePathNode'; | ||
export * from './translateCommands'; | ||
export * from './translateNonRotatedCommands'; | ||
export * from './translateRotatedCommands'; | ||
export * from './translateWindingRule'; |
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,18 @@ | ||
import { Command } from 'svg-path-parser'; | ||
|
||
import { hasRotation } from '@plugin/utils'; | ||
|
||
import { translateNonRotatedCommands } from '.'; | ||
import { translateRotatedCommands } from './translateRotatedCommands'; | ||
|
||
export const translateCommands = (node: LayoutMixin, commands: Command[], baseRotation: number) => { | ||
if (hasRotation(node.rotation + baseRotation) && node.absoluteBoundingBox) { | ||
return translateRotatedCommands(commands, node.absoluteTransform, node.absoluteBoundingBox); | ||
} | ||
|
||
return translateNonRotatedCommands( | ||
commands, | ||
node.absoluteTransform[0][2], | ||
node.absoluteTransform[1][2] | ||
); | ||
}; |
57 changes: 0 additions & 57 deletions
57
plugin-src/translators/vectors/translateCommandsToSegments.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.