From 55e776db2cff9b17e4849c068d8f05f2325b6cdc Mon Sep 17 00:00:00 2001 From: Jonathan Haas Date: Fri, 12 Jul 2024 07:29:11 +0200 Subject: [PATCH] add unit tests for circleSegment method --- packages/core/tests/path.test.mjs | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/packages/core/tests/path.test.mjs b/packages/core/tests/path.test.mjs index 8eefcda4fd1..accf8fc66a7 100644 --- a/packages/core/tests/path.test.mjs +++ b/packages/core/tests/path.test.mjs @@ -3,6 +3,60 @@ import { round, Path, Point } from '../src/index.mjs' import { pathsProxy } from '../src/path.mjs' describe('Path', () => { + describe('circleSegment', () => { + it('Should draw a circleSegment', () => { + const points = {} + points.origin = new Point(10, 20) + // radius = 100 + points.start = points.origin.shift(77, 100) + + const test = new Path().move(points.start).circleSegment(90, points.origin) + + const endPoint = test.end() + const expectedEndPoint = points.start.rotate(90, points.origin) + + expect(round(endPoint.x)).to.equal(round(expectedEndPoint.x)) + expect(round(endPoint.y)).to.equal(round(expectedEndPoint.y)) + expect(endPoint.sitsOn(expectedEndPoint)).to.equal(true) + expect(Math.round(test.length())).to.equal(Math.round(Math.PI * 50)) + }) + + it('Should draw a circleSegment with negative angle', () => { + const points = {} + points.origin = new Point(10, 20) + // radius = 100 + points.start = points.origin.shift(-122, 100) + + const test = new Path().move(points.start).circleSegment(-45, points.origin) + + const endPoint = test.end() + const expectedEndPoint = points.start.rotate(-45, points.origin) + + expect(round(endPoint.x)).to.equal(round(expectedEndPoint.x)) + expect(round(endPoint.y)).to.equal(round(expectedEndPoint.y)) + expect(endPoint.sitsOn(expectedEndPoint)).to.equal(true) + expect(Math.round(test.length())).to.equal(Math.round(Math.PI * 25)) + }) + + it('Should draw a full circle', () => { + const points = {} + + points.origin = new Point(0, 0) + // radius = 100 + points.start = points.origin.shift(0, 100) + + const test = new Path().move(points.start).circleSegment(360, points.origin) + + const endPoint = test.end() + + expect(round(endPoint.x)).to.equal(round(points.start.x)) + expect(round(endPoint.y)).to.equal(round(points.start.y)) + expect(endPoint.sitsOn(points.start)).to.equal(true) + expect(Math.round(test.length())).to.equal(Math.round(Math.PI * 200)) + expect(test.ops.length).to.equal(5) // 1 move + 4 cubic curves + }) + }) + describe('smurve', () => { it('Should draw a smurve', () => { const points = {}