Fix a special case in the reduce function when pass1 created very short segments
Fixes #286 Also add testcase.
This commit is contained in:
parent
836e1b6c8e
commit
6f233441b3
2 changed files with 22 additions and 1 deletions
|
@ -38,7 +38,15 @@ class Bezier extends UpstreamBezier {
|
|||
const splitTs = []
|
||||
let t1 = 0
|
||||
|
||||
if (bezier._t2 - bezier._t1 < EPSILON || bezier.simple()) {
|
||||
// This is a inverted to return [] on NaN _tX values
|
||||
// since NaN compared with something is always false
|
||||
if (!(bezier._t2 - bezier._t1 >= EPSILON)) {
|
||||
// very short, ignore
|
||||
return []
|
||||
}
|
||||
|
||||
if (bezier.simple()) {
|
||||
// already simple
|
||||
return [bezier]
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,19 @@ describe('Path', () => {
|
|||
expect(round(bbox.bottomRight.y)).to.equal(38.26)
|
||||
})
|
||||
|
||||
it('Should offset a problematic curve', () => {
|
||||
// https://codeberg.org/freesewing/freesewing/issues/286
|
||||
const curve = new Path()
|
||||
.move(new Point(233.58820676923352, 437.7581608165166))
|
||||
.curve(
|
||||
new Point(231.23631634571132, 415.3814181707305),
|
||||
new Point(221.70910430613077, 371.13489592600627),
|
||||
new Point(219.35721388260856, 348.75815328022014)
|
||||
)
|
||||
const offset = curve.offset(10)
|
||||
expect(offset.length()).to.be.greaterThan(0)
|
||||
})
|
||||
|
||||
it('Should offset a curve where cp1 = start', () => {
|
||||
const curve = new Path().move(new Point(0, 0))._curve(new Point(123, 34), new Point(23, 4))
|
||||
const offset = curve.offset(10)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue