1
0
Fork 0

fix(core): Fix bug in path.shiftAlong

This bug would be triggered by an edge-case where we have a path
that is made up of multiple curves/lines.

If the distance to shift lies just beyond the end of one segment,
yet the remaining distance is smaller than the step (by default
that means smaller than 1/25mm) no point would be returned.

This closes #1140
This commit is contained in:
Joost De Cock 2021-06-22 18:24:11 +02:00
parent 736ce6d854
commit c463b10e43
5 changed files with 42 additions and 4 deletions

View file

@ -52,6 +52,12 @@
- Correctly load saved value for mm options See [#1136](https://github.com/freesewing/freesewing/issues/1136)
### core
#### Fixed
- Fix a bug in `path.shiftAlong` where no point is returned if the distance to shift is a fraction of one step (1/25mm) into a new path segment See [#1140](https://github.com/freesewing/freesewing/issues/1140)
### diana
#### Changed

View file

@ -46,6 +46,11 @@
components:
- Correctly load saved value for mm options
See [#1136](https://github.com/freesewing/freesewing/issues/1136)
core:
- Fix a bug in `path.shiftAlong` where no point is returned if the
distance to shift is a fraction of one step (1/25mm) into a new
path segment
See [#1140](https://github.com/freesewing/freesewing/issues/1140)
paco:
- The waistband was incorrectly using the cuff widht
See [#1113](https://github.com/freesewing/freesewing/issues/1113)

View file

@ -1,6 +1,12 @@
# Change log for: @freesewing/core
## 2.17.0 (NaN-NaN-NaN)
### Fixed
- Fix a bug in `path.shiftAlong` where no point is returned if the distance to shift is a fraction of one step (1/25mm) into a new path segment See [#1140](https://github.com/freesewing/freesewing/issues/1140)
## 2.15.2 (2021-04-28)
### Fixed

View file

@ -429,8 +429,9 @@ Path.prototype.shiftAlong = function (distance, stepsPerMm = 25) {
let op = this.ops[i]
if (op.type === 'line') {
let thisLen = op.to.dist(current)
if (Math.abs((len + thisLen) - distance) < 0.1) return op.to
if (len + thisLen > distance) return current.shiftTowards(op.to, distance - len)
else len += thisLen
len += thisLen
} else if (op.type === 'curve') {
let bezier = new Bezier(
{ x: current.x, y: current.y },
@ -439,9 +440,9 @@ Path.prototype.shiftAlong = function (distance, stepsPerMm = 25) {
{ x: op.to.x, y: op.to.y }
)
let thisLen = bezier.length()
if (len + thisLen > distance)
return shiftAlongBezier(distance - len, bezier, thisLen * stepsPerMm)
else len += thisLen
if (Math.abs((len + thisLen) - distance) < 0.1) return op.to
if (len + thisLen > distance) return shiftAlongBezier(distance - len, bezier, thisLen * stepsPerMm)
len += thisLen
}
current = op.to
}

View file

@ -775,3 +775,23 @@ it("Should overwrite a path attribute", () => {
expect(a.paths.line.attributes.get("class")).to.equal("overwritten");
});
it("Should move along a path even if it lands just on a joint", () => {
let pattern = new freesewing.Pattern();
pattern.parts.a = new pattern.Part();
let a = pattern.parts.a;
a.paths.curve = new a.Path()
.move(new a.Point(20.979322245694167, -219.8547313525503))
._curve(
new a.Point(35.33122482627704, -153.54225517257478),
new a.Point(61.99376179214562, -105.99242252587702)
)
.curve(
new a.Point(88.85254026593002, -58.092613773317105),
new a.Point(136.13264764576948, -11.692646171119936),
new a.Point(170.69593749999996, -4.180844669736632e-14)
)
a.points.test = a.paths.curve.shiftAlong(121.36690836797631)
expect(a.points.test).to.be.instanceOf(a.Point)
console.log({test: a.points.test})
})