Skip to content

ShapeUtils.triangulateShape should accept Vector2Like instead of relying on Vector2.equals #32340

@atox996

Description

@atox996

Description

Currently, ShapeUtils.triangulateShape internally calls removeDupEndPts, which relies on Vector2.equals. This introduces a strong coupling to Vector2 instances, forcing users to instantiate potentially large numbers of Vector2 objects just to perform triangulation.

Ideally, triangulateShape should accept inputs adhering to the Vector2Like type ({ readonly x: number; readonly y: number; }) and avoid depending on Vector2.equals. This would allow users to pass plain objects without creating Vector2 instances, improving performance and reducing memory overhead in high-vertex-count scenarios.

Proposed solution

  • Allow triangulateShape to accept Vector2Like objects.
  • Replace Vector2.equals checks in removeDupEndPts with a simple value comparison (v1.x === v2.x && v1.y === v2.y).

Reproduction steps

none

Code

const contour: Vector2Like[] = [];
const holes: Vector2Like[][] = [];
ShapeUtils.triangulateShape(contour, holes)

Live example

none

Screenshots

No response

Version

r181

Device

No response

Browser

No response

OS

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions