@jscad/modeling
Version:
Constructive Solid Geometry (CSG) Library for JSCAD
37 lines (31 loc) • 1.38 kB
JavaScript
const test = require('ava')
const { appendBezier, fromPoints, toPoints } = require('./index')
const { comparePoints } = require('../../../test/helpers/')
test('appendBezier: appending to an empty path produces an error', (t) => {
const p1 = fromPoints({}, [])
t.throws(() => appendBezier({ controlPoints: [[12, 12]] }, p1),
{ message: 'the given path must contain one or more points (as the starting point for the bezier curve)' })
})
test('appendBezier: appending to a path produces a new path', (t) => {
const p1 = fromPoints({}, [[10, -20]])
const obs1 = appendBezier({ controlPoints: [[10, -10], [25, -10], [25, -20]], segments: 16 }, p1)
const pts = toPoints(obs1)
const exp = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
]
t.is(pts.length, 11)
t.true(comparePoints(pts, exp))
const obs2 = appendBezier({ controlPoints: [null, [25, -30], [40, -30], [40, -20]], segments: 16 }, obs1)
const pts2 = toPoints(obs2)
t.is(pts2.length, 23)
})