Skip to content

Commit

Permalink
fix: use 30 segment size for better precision #92
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Sep 1, 2022
1 parent e028c64 commit c596f7e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion __tests__/unit/path/get-point-at-length.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('get point at length', () => {
it('should get point in rounded rect correctly', () => {
const segments = parsePathString('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z') as PathArray;
const pt = getPointAtLength(segments, 25);
expect(pt).toEqual({ x: 8.723272341772404, y: 16 });
expect(pt).toEqual({ x: 8.717532406110443, y: 16 });
});

it('should get point in arc correctly', () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/unit/path/get-total-length.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ describe('get total length', () => {
it('should calc the length of circle correctly', () => {
const length = getTotalLength(getCirclePath(0, 0, 100, 100));

expect(length).toBeCloseTo(625.7378601609234); // 2 * Math.PI * 100
expect(length).toBeCloseTo(628.0314749153262); // 2 * Math.PI * 100
});

it('should calc the length of rounded rect correctly', () => {
const length = getTotalLength(
parsePathString('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z') as PathArray,
);
expect(length).toBeCloseTo(60.55345531645519);
expect(length).toBeCloseTo(60.56493518777911);
});

it('should calc the length of rounded rect correctly', () => {
const length = getTotalLength(
parsePathString('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z') as PathArray,
);

expect(length).toBeCloseTo(60.55345531645519);
expect(length).toBeCloseTo(60.56493518777911);
});

it('should calc the length of Q commands correctly', () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/util",
"version": "3.2.4",
"version": "3.2.5",
"license": "MIT",
"sideEffects": false,
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/path/util/segment-arc-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function segmentArcFactory(
distance: number,
options: Partial<PathLengthFactoryOptions>,
): LengthFactory {
const { bbox = true, length = true, sampleSize = 10 } = options;
const { bbox = true, length = true, sampleSize = 30 } = options;
const distanceIsNumber = typeof distance === 'number';
let x = X1;
let y = Y1;
Expand Down

0 comments on commit c596f7e

Please sign in to comment.