Added flip extension
This commit is contained in:
parent
2ab27300e0
commit
5dda2bedc3
16
extensions/fablabchemnitz/flip.inx
Normal file
16
extensions/fablabchemnitz/flip.inx
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>Flip</name>
|
||||
<id>fablabchemnitz.de.Flip</id>
|
||||
<effect>
|
||||
<object-type>path</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="FabLab Chemnitz">
|
||||
<submenu name="Modify existing Path(s)"/>
|
||||
</submenu>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command reldir="inx" interpreter="python">flip.py</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
38
extensions/fablabchemnitz/flip.py
Normal file
38
extensions/fablabchemnitz/flip.py
Normal file
@ -0,0 +1,38 @@
|
||||
import math
|
||||
from inkex import EffectExtension, PathElement, transforms as T
|
||||
|
||||
# https://en.wikipedia.org/wiki/Rotations_and_reflections_in_two_dimensions
|
||||
def reflection_matrix(theta):
|
||||
theta2 = 2 * theta
|
||||
return [
|
||||
[math.cos(theta2), math.sin(theta2), 0],
|
||||
[math.sin(theta2), -math.cos(theta2), 0],
|
||||
]
|
||||
|
||||
def svg_matrix_order(mat):
|
||||
((a, c, e), (b, d, f)) = mat
|
||||
return a, b, c, d, e, f
|
||||
|
||||
class FlipPath(EffectExtension):
|
||||
"""Extension to flip a path about the line from the start to end node"""
|
||||
|
||||
def effect(self):
|
||||
for node in self.svg.selection.filter(PathElement).values():
|
||||
points = list(node.path.end_points)
|
||||
if len(points) < 2 or points[0] == points[-1]:
|
||||
continue
|
||||
start = points[0]
|
||||
end = points[-1]
|
||||
v = end - start
|
||||
theta = math.atan2(v.y, v.x)
|
||||
|
||||
# transforms go in reverse order
|
||||
mat = T.Transform()
|
||||
mat.add_translate(start)
|
||||
mat.add_matrix(*svg_matrix_order(reflection_matrix(theta)))
|
||||
mat.add_translate(-start)
|
||||
|
||||
node.path = node.path.transform(mat)
|
||||
|
||||
if __name__ == '__main__':
|
||||
FlipPath().run()
|
@ -11,8 +11,7 @@
|
||||
<option value="cross">Cross</option>
|
||||
<option value="square">Square</option>
|
||||
<option value="triangle">Triangle</option></param>
|
||||
<label> </label>
|
||||
<label> </label>
|
||||
<spacer/>
|
||||
<label>v1.1.0</label>
|
||||
</page>
|
||||
<page name="corners" gui-text="Corners">
|
||||
|
Reference in New Issue
Block a user