Options
All
  • Public
  • Public/Protected
  • All
Menu

A PointSourcePolygon implementation that uses CCW (counter-clockwise) geometry orientation. Sweep around the origin, accumulating collision points based on the set of active walls. This algorithm was created with valuable contributions from https://github.com/caewok

Hierarchy

Index

Constructors

Properties

The configuration of this polygon.

vertices: VertexMap = ...

A mapping of vertices which define potential collision points

edges: EdgeSet = ...

The set of edges which define potential boundaries of the polygon

rays: Ray[] = []

A collection of rays which are fired at vertices

points: any
bounds: Rectangle

The rectangular bounds of this polygon

origin: Point

The origin point of the source polygon.

isClosed: boolean

Methods

  • initialize(origin: any, config: any): void
  • Customize the provided configuration object for this polygon type.

    Parameters

    • origin: any

      The provided polygon origin

    • config: any

      The provided configuration object

    Returns void

  • _compute(): void
  • _testCollision(ray: any, mode: any): any
  • visualize(): void
  • contains(x: any, y: any): any
  • Apply a constraining boundary shape to an existing PointSourcePolygon. Return a new instance of the polygon with the constraint applied. The new instance is only a "shallow clone", as it shares references to component properties with the original.

    Parameters

    Returns PointSourcePolygon

    A new constrained polygon

  • toClipperPoints([options]?: { scalingFactor: number }): { X: number; Y: number }[]
  • Convert a PIXI.Polygon into an array of clipper points [{X,Y}, ...]. Note that clipper points must be rounded to integers. In order to preserve some amount of floating point precision, an optional scaling factor may be provided.

    Parameters

    • [options]: { scalingFactor: number } = {}

      Options which affect how clipper points are generated

      • scalingFactor: number

    Returns { X: number; Y: number }[]

    } An array of points to be used by clipper

  • intersectPolygon(other: Polygon, [options]?: { clipType: number; scalingFactor: number }): Polygon
  • Intersect this PIXI.Polygon with another PIXI.Polygon using the clipper library.

    Parameters

    • other: Polygon

      Another PIXI.Polygon

    • [options]: { clipType: number; scalingFactor: number } = {}

      Options which configure how the intersection is computed

      • clipType: number
      • scalingFactor: number

    Returns Polygon

    The intersected polygon or null if no solution was present

  • intersectCircle(circle: Circle, options: { density: number }): Polygon
  • Intersect this PIXI.Polygon with a PIXI.Circle. For now, convert the circle to a Polygon approximation and use intersectPolygon. In the future we may replace this with more specialized logic which uses the line-circle intersection formula.

    Parameters

    • circle: Circle

      A PIXI.Circle

    • options: { density: number }
      • density: number

    Returns Polygon

    The intersected polygon

  • Intersect this PIXI.Polygon with a PIXI.Rectangle. For now, convert the rectangle to a Polygon and use intersectPolygon. In the future we may replace this with more specialized logic which uses the line-line intersection formula.

    Parameters

    • rect: Rectangle

      A PIXI.Rectangle

    • options: any

    Returns Polygon

    The intersected polygon

  • _getWalls(): Set<Wall>
  • Get the super-set of walls which could potentially apply to this polygon. Define a custom collision test used by the Quadtree to obtain candidate Walls.

    Returns Set<Wall>

  • Compute the aggregate bounding box which is the intersection of all boundary shapes. Round and pad the resulting rectangle by 1 pixel to ensure it always contains the origin.

    Returns Rectangle

  • Test whether a wall should be included in the computed polygon for a given origin and type

    Parameters

    • wall: Wall

      The Wall being considered

    • bounds: Rectangle

      The overall bounding box

    Returns boolean

    Should the wall be included?

  • #configureLimitedAngle(): void
  • Configure a limited angle and rotation into a triangular polygon boundary shape.

    Returns void

  • #configureLimitedRadius(): void
  • Configure a provided limited radius as a circular polygon boundary shape.

    Returns void

  • _identifyEdges(): void
  • Translate walls and other obstacles into edges which limit visibility

    Returns void

  • _identifyVertices(): void
  • Consolidate all vertices from identified edges and register them as part of the vertex mapping.

    Returns void

  • _identifyIntersections(wallEdgeMap: Map<string, PolygonEdge>): void
  • Add additional vertices for intersections between edges.

    Parameters

    • wallEdgeMap: Map<string, PolygonEdge>

      A mapping of wall IDs to PolygonEdge instances

    Returns void

  • _truncateBoundaryEdge(edge: PolygonEdge, v: PolygonVertex): void
  • Truncate an edge which intersects with a boundary by replacing one of its vertices with the intersection point.

    Parameters

    • edge: PolygonEdge

      The edge which intersects with the boundary

    • v: PolygonVertex

      The vertex of the intersection point

    Returns void

  • _executeSweep(): void
  • Execute the sweep over wall vertices

    Returns void

  • #includeCollinearVertices(vertex: PolygonVertex, collinearVertices: PolygonVertexSet): void
  • Include collinear vertices until they have all been added. Do not include the original vertex in the set.

    Parameters

    • vertex: PolygonVertex

      The current vertex

    • collinearVertices: PolygonVertexSet

    Returns void

  • _updateActiveEdges(vertex: PolygonVertex, activeEdges: EdgeSet): void
  • Update active edges at a given vertex Must delete first, in case the edge is in both sets.

    Parameters

    • vertex: PolygonVertex

      The current vertex

    • activeEdges: EdgeSet

      A set of currently active edges

    Returns void

  • Determine the initial set of active edges as those which intersect with the initial ray

    Returns EdgeSet

    A set of initially active edges

  • _sortVertices(): PolygonVertex[]
  • Sort vertices clockwise from the initial ray (due west).

    Returns PolygonVertex[]

    The array of sorted vertices

  • _isVertexBehindActiveEdges(vertex: PolygonVertex, activeEdges: EdgeSet): { isBehind: boolean; wasLimited: boolean }
  • Test whether a target vertex is behind some closer active edge. If the vertex is to the left of the edge, is must be behind the edge relative to origin. If the vertex is collinear with the edge, it should be considered "behind" and ignored. We know edge.A is ccw to edge.B because of the logic in _identifyVertices.

    Parameters

    • vertex: PolygonVertex

      The target vertex

    • activeEdges: EdgeSet

      The set of active edges

    Returns { isBehind: boolean; wasLimited: boolean }

    Is the target vertex behind some closer edge?

    • isBehind: boolean
    • wasLimited: boolean
  • _determineSweepResult(vertex: PolygonVertex, activeEdges: EdgeSet, hasCollinear?: boolean): void
  • Determine the result for the sweep at a given vertex

    Parameters

    • vertex: PolygonVertex

      The target vertex

    • activeEdges: EdgeSet

      The set of active edges

    • hasCollinear: boolean = false

      Are there collinear vertices behind the target vertex?

    Returns void

  • _switchEdge(result: CollisionResult, activeEdges: EdgeSet): void
  • Switch to a new active edge. Moving from the origin, a collision that first blocks a side must be stored as a polygon point. Subsequent collisions blocking that side are ignored. Once both sides are blocked, we are done.

    Collisions that limit a side will block if that side was previously limited.

    If neither side is blocked and the ray internally collides with a non-limited edge, n skip without adding polygon endpoints. Sight is unaffected before this edge, and the internal collision can be ignored.

    Parameters

    • result: CollisionResult

      The pending collision result

    • activeEdges: EdgeSet

      The set of currently active edges

    Returns void

  • _getInternalEdgeCollisions(ray: Ray, internalEdges: EdgeSet): PolygonVertex[]
  • Identify the collision points between an emitted Ray and a set of active edges.

    Parameters

    • ray: Ray

      The candidate ray to test

    • internalEdges: EdgeSet

      The set of edges to check for collisions against the ray

    Returns PolygonVertex[]

    A sorted array of collision points

  • _constrainBoundaryShapes(): void
  • Constrain polygon points by applying boundary shapes.

    Returns void

  • _visualizeCollision(ray: Ray, collisions: PolygonVertex[]): void
  • Visualize the polygon, displaying its computed area, rays, and collision points

    Parameters

    • ray: Ray
    • collisions: PolygonVertex[]

    Returns void

  • Benchmark the performance of polygon computation for this source

    Parameters

    • iterations: number

      The number of test iterations to perform

    • origin: Point

      The origin point to benchmark

    • config: PointSourcePolygonConfig

      The polygon configuration to benchmark

    Returns Promise<void>

  • testCollision(origin: Point, destination: Point, config?: PointSourcePolygonConfig): boolean | PolygonVertex | PolygonVertex[]
  • Test whether a Ray between the origin and destination points would collide with a boundary of this Polygon. A valid wall restriction type is compulsory and must be passed into the config options.

    Parameters

    • origin: Point

      An origin point

    • destination: Point

      A destination point

    • config: PointSourcePolygonConfig = {}

      The configuration that defines a certain Polygon type

    Returns boolean | PolygonVertex | PolygonVertex[]

    The collision result depends on the mode of the test: * any: returns a boolean for whether any collision occurred * all: returns a sorted array of PolygonVertex instances * closest: returns a PolygonVertex instance or null

  • fromClipperPoints(points: { X: number; Y: number }[], [options]?: { scalingFactor: number }): Polygon
  • Construct a PIXI.Polygon instance from an array of clipper points [{X,Y}, ...].

    Parameters

    • points: { X: number; Y: number }[]
    • [options]: { scalingFactor: number } = {}

      Options which affect how canvas points are generated

      • scalingFactor: number

    Returns Polygon

    The resulting PIXI.Polygon

Accessors

  • get isConstrained(): boolean
  • An indicator for whether this polygon is constrained by some boundary shape?

    Returns boolean

isClosed