diff --git a/src/geometry/shape/edge/util.ts b/src/geometry/shape/edge/util.ts index 233e5615a6..1994543fce 100644 --- a/src/geometry/shape/edge/util.ts +++ b/src/geometry/shape/edge/util.ts @@ -9,24 +9,12 @@ import { Point } from '../../../interface'; * @returns */ export function getCPath(from: Point, to: Point) { - const points = []; - points.push({ - x: from.x, - y: (from.y * 1) / 2 + (to.y * 1) / 2, - }); - - points.push({ - x: to.x, - y: (from.y * 1) / 2 + (to.y * 1) / 2, - }); - points.push(to); - - const sub = ['C']; - each(points, (point) => { - sub.push(point.x, point.y); - }); - - return sub; + return [ + 'C', + (from.x * 1) / 2 + (to.x * 1) / 2, from.y, + (from.x * 1) / 2 + (to.x * 1) / 2, to.y, + to.x, to.y, + ]; } /** diff --git a/tests/unit/geometry/shape/util/c-path-spec.ts b/tests/unit/geometry/shape/util/c-path-spec.ts new file mode 100644 index 0000000000..fd1b8dbfaf --- /dev/null +++ b/tests/unit/geometry/shape/util/c-path-spec.ts @@ -0,0 +1,10 @@ +import { getCPath } from '../../../../../src/geometry/shape/edge/util'; + +describe('getCPath', () => { + test('getCPath', () => { + expect(getCPath({ x: 10, y: 10 }, { x: 100, y: 100 })).toEqual(['C', 55, 10 ,55, 100, 100, 100]); + expect(getCPath({ x: 10, y: 100 }, { x: 100, y: 10 })).toEqual(['C', 55, 100 ,55, 10, 100, 10]); + expect(getCPath({ x: 100, y: 100 }, { x: 10, y: 10 })).toEqual(['C', 55, 100 ,55, 10, 10, 10]); + expect(getCPath({ x: 100, y: 10 }, { x: 10, y: 100 })).toEqual(['C', 55, 10 ,55, 100, 10, 100]); + }); +});