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.

makeNewCollisionTestResult: () => CollisionTestResult = makeNewCollisionTestResult

Type declaration

makeNewRaycastTestResult: () => RaycastTestResult = makeNewRaycastTestResult

Type declaration

vertices: FloatPoint[] = []

The vertices of the polygon

Methods

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

    You can read the result but do not keep a reference to it as it's a static object reused between function calls. If you need to keep the results, use copyCollisionTestResult.

    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

    A collision result. collision property is equal to true if polygons are overlapping. Do NOT keep a reference to this.

  • 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
  • Do a raycast test. Please note that the polygon must be convex!

    You can read the result but do not keep a reference to it as it's a static object reused between function calls. If you need to keep the results, use copyRaycastTestResult.

    For some theory, check Find the Intersection Point of Two Line Segments.

    Parameters

    • poly: Polygon

      The polygon to test

    • startX: number

      The raycast start point X

    • startY: number

      The raycast start point Y

    • endX: number

      The raycast end point X

    • endY: number

      The raycast end point Y

    Returns RaycastTestResult

    A raycast result with the contact points and distances. Do NOT keep a reference to this.

  • rotate(angle: number): void

Constructors

Generated using TypeDoc