add(core): Add Path.rotate(...) function analogue to Point.rotate(...)
This commit is contained in:
parent
7e694de977
commit
849563d1ec
4 changed files with 119 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue