nape-js API
    Preparing search index...

    Class Polygon

    A convex polygon physics shape.

    Hierarchy (View Summary)

    Index

    Constructors

    • Create a Polygon from a list of Vec2 vertices. Vertices must form a convex polygon in counter-clockwise order.

      The second parameter can be either a Vec2 local-COM offset or a Material. This allows both the legacy 2-arg form (verts, material) and the new 3-arg form (verts, localCOM, material, filter) — consistent with Circle and Capsule.

      Parameters

      • OptionallocalVerts: any

        Vertices as Array<Vec2>, Vec2List, or GeomPoly.

      • OptionallocalCOMOrMaterial: Vec2 | Material

        Local centre offset (Vec2) or Material for backward compat.

      • Optionalmaterial: Material | InteractionFilter

        Material to assign (uses default if omitted).

      • Optionalfilter: InteractionFilter

        InteractionFilter to assign (uses default if omitted).

      Returns Polygon

    Accessors

    Methods

    • Return true if the given world-space point lies inside this shape. Requires the shape to be attached to a Body.

      Parameters

      • point: Vec2

        The world-space point to test.

      Returns boolean

      True if the point is inside this shape.

    • Scale the shape's local geometry. Circles require uniform scaling.

      Parameters

      • scaleX: number

        Horizontal scale factor (must be non-zero).

      • scaleY: number

        Vertical scale factor (must be non-zero).

      Returns Shape

      this for chaining.

    • Apply a Mat23 affine transform to the shape's local geometry.

      Parameters

      • matrix: { _inner: any }

        The transformation matrix (must be non-singular; Circles require equiorthogonal).

      Returns Shape

      this for chaining.

    • Validate the polygon geometry and return a string describing any issues, or "valid" if the polygon is well-formed.

      Returns any

      A validation result string from the underlying ZPP_Polygon.

    • Create an axis-aligned rectangular polygon centred at the origin.

      Parameters

      • width: number

        Rectangle width.

      • height: number = width

        Rectangle height (defaults to width for a square).

      • weak: boolean = false

        If true, returned Vec2s are marked weak and will be auto-disposed.

      Returns Vec2[]

      Array of four Vec2 corner vertices.

    • Create an axis-aligned rectangle at the given position.

      Parameters

      • x: number

        Left edge x coordinate.

      • y: number

        Top edge y coordinate.

      • width: number

        Rectangle width.

      • height: number

        Rectangle height.

      • weak: boolean = false

        If true, returned Vec2s are marked weak and will be auto-disposed.

      Returns Vec2[]

      Array of four Vec2 corner vertices.

    • Create a regular polygon (or ellipse approximation) centred at the origin.

      Parameters

      • xRadius: number

        Horizontal radius of the circumscribed ellipse.

      • yRadius: number

        Vertical radius of the circumscribed ellipse.

      • edgeCount: number

        Number of sides (must be >= 3).

      • angleOffset: number = 0.0

        Rotation offset in radians applied to all vertices (default 0).

      • weak: boolean = false

        If true, returned Vec2s are marked weak and will be auto-disposed.

      Returns Vec2[]

      Array of edgeCount Vec2 vertices.