diff --git a/.changeset/five-rules-shop.md b/.changeset/five-rules-shop.md new file mode 100644 index 000000000..0bd7e435c --- /dev/null +++ b/.changeset/five-rules-shop.md @@ -0,0 +1,9 @@ +--- +'@antv/g-plugin-device-renderer': patch +'@antv/g-plugin-annotation': patch +'@antv/g-shader-components': patch +'@antv/g-plugin-box2d': patch +'@antv/g-lite': patch +--- + +Fix points type in Polyline & Polygon. diff --git a/packages/g-lite/src/css/properties/CSSPropertyPoints.ts b/packages/g-lite/src/css/properties/CSSPropertyPoints.ts index f7d60e1f8..33fe469c2 100644 --- a/packages/g-lite/src/css/properties/CSSPropertyPoints.ts +++ b/packages/g-lite/src/css/properties/CSSPropertyPoints.ts @@ -9,12 +9,12 @@ export class CSSPropertyPoints Partial< CSSProperty< { - points: [number, number, number?][]; + points: [number, number][]; totalLength: number; segments: [number, number][]; }, { - points: [number, number, number?][]; + points: [number, number][]; totalLength: number; segments: [number, number][]; } diff --git a/packages/g-lite/src/display-objects/Polygon.ts b/packages/g-lite/src/display-objects/Polygon.ts index 667b90f24..c5ed78681 100644 --- a/packages/g-lite/src/display-objects/Polygon.ts +++ b/packages/g-lite/src/display-objects/Polygon.ts @@ -5,7 +5,7 @@ import { Shape } from '../types'; import { DisplayObject, isDisplayObject } from './DisplayObject'; export interface PolygonStyleProps extends BaseStyleProps { - points: [number, number, number?][]; + points: ([number, number] | [number, number, number])[]; /** * marker will be positioned at the first point */ @@ -31,7 +31,7 @@ export interface PolygonStyleProps extends BaseStyleProps { } export interface ParsedPolygonStyleProps extends ParsedBaseStyleProps { points: { - points: [number, number, number?][]; + points: ([number, number] | [number, number, number])[]; segments: [number, number][]; totalLength: number; }; diff --git a/packages/g-lite/src/display-objects/Polyline.ts b/packages/g-lite/src/display-objects/Polyline.ts index 201c4e952..c5f559e9f 100644 --- a/packages/g-lite/src/display-objects/Polyline.ts +++ b/packages/g-lite/src/display-objects/Polyline.ts @@ -9,7 +9,7 @@ import type { DisplayObject } from './DisplayObject'; import { Polygon } from './Polygon'; export interface PolylineStyleProps extends BaseStyleProps { - points: [number, number, number?][]; + points: ([number, number] | [number, number, number])[]; /** * marker will be positioned at the first point */ @@ -34,7 +34,7 @@ export interface PolylineStyleProps extends BaseStyleProps { } export interface ParsedPolylineStyleProps extends ParsedBaseStyleProps { points: { - points: [number, number, number?][]; + points: ([number, number] | [number, number, number])[]; segments: [number, number][]; totalLength: number; }; diff --git a/packages/g-lite/src/utils/path.ts b/packages/g-lite/src/utils/path.ts index 86cca1e18..ca0ad1516 100644 --- a/packages/g-lite/src/utils/path.ts +++ b/packages/g-lite/src/utils/path.ts @@ -786,7 +786,7 @@ function ellipseToCommands( } function polygonToCommands( - points: [number, number, number?][], + points: ([number, number] | [number, number, number])[], closed: boolean, ): AbsoluteArray { const result = points.map((point, i) => { diff --git a/packages/g-plugin-annotation/src/selectable/SelectableRectPolygon.ts b/packages/g-plugin-annotation/src/selectable/SelectableRectPolygon.ts index 74199f29d..87b3849fc 100644 --- a/packages/g-plugin-annotation/src/selectable/SelectableRectPolygon.ts +++ b/packages/g-plugin-annotation/src/selectable/SelectableRectPolygon.ts @@ -176,7 +176,11 @@ export class SelectableRectPolygon extends AbstractSelectable { ]; const handleVec = vec2.normalize( vec2.create(), - vec2.sub(vec2.create(), points.points[0], points.points[3]), + vec2.sub( + vec2.create(), + points.points[0] as [number, number], + points.points[3] as [number, number], + ), ); this.rotateAnchor.setPosition( handleVec[0] * rotateAnchorDistance + midPoint[0], diff --git a/packages/g-plugin-box2d/src/utils.ts b/packages/g-plugin-box2d/src/utils.ts index 7fb0a2cdc..c32c191db 100644 --- a/packages/g-plugin-box2d/src/utils.ts +++ b/packages/g-plugin-box2d/src/utils.ts @@ -1,7 +1,9 @@ /** * @see https://stackoverflow.com/questions/45660743/sort-points-in-counter-clockwise-in-javascript */ -export function sortPointsInCCW(pts: [number, number][]): [number, number][] { +export function sortPointsInCCW( + pts: ([number, number] | [number, number, number])[], +): [number, number][] { const points = pts.map(([x, y]) => ({ x, y,