Options
All
  • Public
  • Public/Protected
  • All
Menu

Polygon represents a polygon which can be used to create collisions masks for RuntimeObject.

Hierarchy

  • Polygon

Index

Properties

center: FloatPoint = ...

The center of the polygon. This property is only valid after calling computeCenter, and remains valid until vertices are modified.

edges: FloatPoint[] = []

The edges of the polygon. This property is only valid after calling computeEdges, and remains valid until vertices are modified.

vertices: FloatPoint[] = []

The vertices of the polygon

collisionTestStatics: { axis: FloatPoint; edge: FloatPoint; minMaxA: FloatPoint; minMaxB: FloatPoint; move_axis: FloatPoint; result: CollisionTestResult } = ...

Type declaration

  • axis: FloatPoint
  • edge: FloatPoint
  • minMaxA: FloatPoint
  • minMaxB: FloatPoint
  • move_axis: FloatPoint
  • result: CollisionTestResult
raycastTestStatics: { axis: FloatPoint; deltaQP: FloatPoint; p: FloatPoint; q: FloatPoint; r: FloatPoint; result: RaycastTestResult; s: FloatPoint } = ...

Type declaration

  • axis: FloatPoint
  • deltaQP: FloatPoint
  • p: FloatPoint
  • q: FloatPoint
  • r: FloatPoint
  • result: RaycastTestResult
  • s: FloatPoint

Methods

  • Do a collision test between two polygons. Please note that polygons must convexes!

    Uses Separating Axis Theorem .
    Based on this and this article.

    Parameters

    • p1: Polygon

      The first polygon

    • p2: Polygon

      The second polygon

    • ignoreTouchingEdges: boolean

      If true, then edges that are touching each other, without the polygons actually overlapping, won't be considered in collision.

    Returns CollisionTestResult

    returnValue.collision is equal to true if polygons are overlapping

  • computeCenter(): FloatPoint
  • computeEdges(): void
  • createRectangle(width: number, height: number): Polygon
  • crossProduct(a: FloatPoint, b: FloatPoint): number
  • distance(minA: number, maxA: number, minB: number, maxB: number): number
  • dotProduct(a: FloatPoint, b: FloatPoint): number
  • isConvex(): boolean
  • isPointInside(poly: Polygon, x: number, y: number): boolean
  • Check if a point is inside a polygon.

    Uses PNPOLY by W. Randolph Franklin.

    Parameters

    • poly: Polygon

      The polygon to test

    • x: number

      The point x coordinate

    • y: number

      The point y coordinate

    Returns boolean

    true if the point is inside the polygon

  • move(x: number, y: number): void
  • normalise(v: FloatPoint): void
  • project(axis: FloatPoint, p: Polygon, result: FloatPoint): void
  • rotate(angle: number): void

Constructors

Generated using TypeDoc