Skip to content

Commit

Permalink
fix(san-key): 贝塞尔曲线的方向不对 (#3023)
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc authored Nov 20, 2020
1 parent fcf024e commit 0210319
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/geometry/shape/edge/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/geometry/shape/util/c-path-spec.ts
Original file line number Diff line number Diff line change
@@ -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]);
});
});

0 comments on commit 0210319

Please sign in to comment.