feat(plugin-flip): Support both X and Y axis
This commit is contained in:
parent
e509616ade
commit
12433ae11e
2 changed files with 20 additions and 11 deletions
|
@ -2,17 +2,25 @@
|
||||||
title: flip
|
title: flip
|
||||||
---
|
---
|
||||||
|
|
||||||
The `flip` macro flips (mirrors) an entire part vertically around the Y-axis.
|
The `flip` macro flips (mirrors) an entire part vertically around either the X-axis or the Y-axis.
|
||||||
It takes no arguments, and is provided by the [flip plugin](/reference/plugins/flip).
|
It is provided by the [flip plugin](/reference/plugins/flip).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
macro("flip")
|
macro("flip", {
|
||||||
|
axis: 'x'
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
| Property | Default | Type | Description |
|
||||||
|
|----------------:|---------|---------------------|-------------|
|
||||||
|
| `axis` | 'x' | The axis to flip around. Either `x` or `y` |
|
||||||
|
|
||||||
|
<Note>
|
||||||
|
|
||||||
Under the hood, this macro will:
|
Under the hood, this macro will:
|
||||||
|
|
||||||
- Go through all Points in your Part, and multiply their X-coordinate 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-coordinare 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-coordinate of the anchor point by -1
|
- Go through all the Snippets in your Part and multiply the (X or Y)-coordinate of the anchor point by -1
|
||||||
|
|
||||||
|
|
||||||
|
</Note>
|
||||||
|
|
|
@ -7,7 +7,8 @@ export default {
|
||||||
preRender: svg => svg.attributes.setIfUnset('freesewing:plugin-flip', version)
|
preRender: svg => svg.attributes.setIfUnset('freesewing:plugin-flip', version)
|
||||||
},
|
},
|
||||||
macros: {
|
macros: {
|
||||||
flip: function () {
|
flip: function(so) {
|
||||||
|
const axis = (so?.axis === 'y') ? 'y' : 'x'
|
||||||
let flipped = null
|
let flipped = null
|
||||||
const ops = ['from', 'to', 'cp1', 'cp2']
|
const ops = ['from', 'to', 'cp1', 'cp2']
|
||||||
for (const id in this.points) {
|
for (const id in this.points) {
|
||||||
|
@ -18,7 +19,7 @@ export default {
|
||||||
if (flipped === false) flipped = 1
|
if (flipped === false) flipped = 1
|
||||||
else 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)
|
this.points[id].attributes.set('flipped', flipped)
|
||||||
}
|
}
|
||||||
for (let id of Object.keys(this.paths)) {
|
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')
|
let wasFlipped = this.paths[id].ops[op][type].attributes.get('flipped')
|
||||||
if (wasFlipped !== false) wasFlipped = parseInt(wasFlipped)
|
if (wasFlipped !== false) wasFlipped = parseInt(wasFlipped)
|
||||||
if (wasFlipped !== flipped) {
|
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)
|
this.paths[id].ops[op][type].attributes.set('flipped', flipped)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +43,7 @@ export default {
|
||||||
// and not double flip the points flipped above
|
// and not double flip the points flipped above
|
||||||
let wasFlipped = this.snippets[id].anchor.attributes.get('flipped')
|
let wasFlipped = this.snippets[id].anchor.attributes.get('flipped')
|
||||||
if (wasFlipped !== false) wasFlipped = parseInt(wasFlipped)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue