1
0
Fork 0

add(core): Add Path.rotate(...) function analogue to Point.rotate(...)

This commit is contained in:
Jonathan Haas 2024-04-05 14:13:22 +02:00
parent 7e694de977
commit 849563d1ec
No known key found for this signature in database
GPG key ID: 0E7873037C5924E8
4 changed files with 119 additions and 1 deletions

View file

@ -371,6 +371,20 @@ describe('Path', () => {
expect(rev.ops[2].type).to.equal('line')
})
it('Should rotate a path', () => {
const test = new Path()
.move(new Point(123, 456))
.line(new Point(12, 23))
.curve(new Point(0, 40), new Point(123, 34), new Point(230, 4))
.close()
let deg = 60
let rotationOrigin = new Point(42, 100)
let rotated = test.rotate(deg, rotationOrigin, true)
expect(test.length()).to.equal(rotated.length())
expect(test.ops[0].to.rotate(deg, rotationOrigin).x).to.equal(rotated.ops[0].to.x)
expect(test.ops[0].to.rotate(deg, rotationOrigin).y).to.equal(rotated.ops[0].to.y)
})
it('Should find the edges of a path', () => {
const test = new Path()
.move(new Point(45, 60))
@ -916,6 +930,21 @@ describe('Path', () => {
expect(invalid).to.equal(true)
})
it('Should log a warning when calling rotate with an origin that is not a point', () => {
let invalid = false
const log = { warn: () => (invalid = true) }
const test = new Path().__withLog(log).move(new Point(123, 456)).line(new Point(12, 23))
expect(invalid).to.equal(false)
let deg = 60
try {
test.rotate(deg, 'someOrigin')
} catch (err) {
expect('' + err).to.contain('Cannot read properties of')
}
expect(invalid).to.equal(true)
})
it('Should add a noop operation', () => {
const p1 = new Path().noop()
expect(p1.ops.length).to.equal(1)