From c596f7e8651262594d12a40ae59500e11e11b279 Mon Sep 17 00:00:00 2001 From: "yuqi.pyq" Date: Thu, 1 Sep 2022 14:04:06 +0800 Subject: [PATCH] fix: use 30 segment size for better precision #92 --- __tests__/unit/path/get-point-at-length.spec.ts | 2 +- __tests__/unit/path/get-total-length.spec.ts | 6 +++--- package.json | 2 +- src/path/util/segment-arc-factory.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/__tests__/unit/path/get-point-at-length.spec.ts b/__tests__/unit/path/get-point-at-length.spec.ts index 2c0e439..c6b844d 100644 --- a/__tests__/unit/path/get-point-at-length.spec.ts +++ b/__tests__/unit/path/get-point-at-length.spec.ts @@ -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', () => { diff --git a/__tests__/unit/path/get-total-length.spec.ts b/__tests__/unit/path/get-total-length.spec.ts index e8a1972..9d2f659 100644 --- a/__tests__/unit/path/get-total-length.spec.ts +++ b/__tests__/unit/path/get-total-length.spec.ts @@ -25,14 +25,14 @@ 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', () => { @@ -40,7 +40,7 @@ describe('get total length', () => { 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', () => { diff --git a/package.json b/package.json index 38b1514..1c41fa7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antv/util", - "version": "3.2.4", + "version": "3.2.5", "license": "MIT", "sideEffects": false, "main": "lib/index.js", diff --git a/src/path/util/segment-arc-factory.ts b/src/path/util/segment-arc-factory.ts index aca246d..50cfc9e 100644 --- a/src/path/util/segment-arc-factory.ts +++ b/src/path/util/segment-arc-factory.ts @@ -136,7 +136,7 @@ export function segmentArcFactory( distance: number, options: Partial, ): 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;