diff --git a/markdown/dev/reference/api/macros/flip/en.md b/markdown/dev/reference/api/macros/flip/en.md index 917e8bf299b..b55081c8f0b 100644 --- a/markdown/dev/reference/api/macros/flip/en.md +++ b/markdown/dev/reference/api/macros/flip/en.md @@ -2,17 +2,25 @@ title: flip --- -The `flip` macro flips (mirrors) an entire part vertically around the Y-axis. -It takes no arguments, and is provided by the [flip plugin](/reference/plugins/flip). +The `flip` macro flips (mirrors) an entire part vertically around either the X-axis or the Y-axis. +It is provided by the [flip plugin](/reference/plugins/flip). ```js -macro("flip") +macro("flip", { + axis: 'x' +}) ``` +| Property | Default | Type | Description | +|----------------:|---------|---------------------|-------------| +| `axis` | 'x' | The axis to flip around. Either `x` or `y` | + + + Under the hood, this macro will: - - Go through all Points in your Part, and multiply their X-coordinate by -1 - - Go through all the Paths in your Part, and for each drawing operation will multiply the X-coordinare by -1 - - Go through all the Snippets in your Part and multiply the X-coordinate of the anchor point by -1 - + - Go through all Points in your Part, and multiply their (X or Y)-coordinate by -1 + - Go through all the Paths in your Part, and for each drawing operation will multiply the (X or Y)-coordinare by -1 + - Go through all the Snippets in your Part and multiply the (X or Y)-coordinate of the anchor point by -1 + diff --git a/packages/plugin-flip/src/index.js b/packages/plugin-flip/src/index.js index a20687fc80d..9e9a2cb88aa 100644 --- a/packages/plugin-flip/src/index.js +++ b/packages/plugin-flip/src/index.js @@ -7,7 +7,8 @@ export default { preRender: svg => svg.attributes.setIfUnset('freesewing:plugin-flip', version) }, macros: { - flip: function () { + flip: function(so) { + const axis = (so?.axis === 'y') ? 'y' : 'x' let flipped = null const ops = ['from', 'to', 'cp1', 'cp2'] for (const id in this.points) { @@ -18,7 +19,7 @@ export default { if (flipped === false) flipped = 1 else flipped += 1 } - this.points[id].x = this.points[id].x * -1 + this.points[id][axis] = this.points[id][axis] * -1 this.points[id].attributes.set('flipped', flipped) } for (let id of Object.keys(this.paths)) { @@ -30,7 +31,7 @@ export default { let wasFlipped = this.paths[id].ops[op][type].attributes.get('flipped') if (wasFlipped !== false) wasFlipped = parseInt(wasFlipped) if (wasFlipped !== flipped) { - this.paths[id].ops[op][type].x = this.paths[id].ops[op][type].x * -1 + this.paths[id].ops[op][type][axis] = this.paths[id].ops[op][type][axis] * -1 this.paths[id].ops[op][type].attributes.set('flipped', flipped) } } @@ -42,7 +43,7 @@ export default { // and not double flip the points flipped above let wasFlipped = this.snippets[id].anchor.attributes.get('flipped') if (wasFlipped !== false) wasFlipped = parseInt(wasFlipped) - if (wasFlipped !== flipped) this.snippets[id].anchor.x = this.snippets[id].anchor.x * -1 + if (wasFlipped !== flipped) this.snippets[id].anchor[axis] = this.snippets[id].anchor[axis] * -1 } } }