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 (view full)

Properties

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

bounds: Rectangle = ...

The rectangular bounds of this polygon

origin: Point

The origin point of the source polygon.

The configuration of this polygon.

#rayDistance2: number

The squared maximum distance of a ray that is needed for this Scene.

#rays: any[] = []

Deprecated

since v11

WALL_DIRECTION_MODES: Readonly<{
    NORMAL: 0;
    REVERSED: 1;
    BOTH: 2;
}> = ...

Customize how wall direction of one-way walls is applied

Type declaration

  • NORMAL: 0
  • REVERSED: 1
  • BOTH: 2

Accessors

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

    Returns boolean

Methods

  • Customize the provided configuration object for this polygon type.

    Parameters

    • origin: any

      The provided polygon origin

    • config: any

      The provided configuration object

    Returns void

  • 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

    • constraint: Rectangle | Polygon | Circle

      The constraining boundary shape

    • Optional intersectionOptions: object = {}

      Options passed to the shape intersection method

    Returns PointSourcePolygon

    A new constrained polygon

  • Determine if the shape is a complete circle. The config object must have an angle and a radius properties.

    Returns any

  • 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

    • Optional options: {
          scalingFactor: number;
      } = {}

      Options which affect how clipper points are generated

      • scalingFactor: number

        A scaling factor used to preserve floating point precision

    Returns ClipperPoint[]

    An array of points to be used by clipper

  • Intersect this PIXI.Polygon with another PIXI.Polygon using the clipper library.

    Parameters

    • other: Polygon

      Another PIXI.Polygon

    • Optional options: {
          clipType: number;
          scalingFactor: number;
      } = {}

      Options which configure how the intersection is computed

      • clipType: number

        The clipper clip type

      • scalingFactor: number

        A scaling factor passed to Polygon#toClipperPoints to preserve precision

    Returns Polygon

    The intersected polygon

  • Intersect this PIXI.Polygon with an array of ClipperPoints.

    Parameters

    • clipperPoints: ClipperPoint[]

      Array of clipper points generated by PIXI.Polygon.toClipperPoints()

    • Optional options: {
          clipType: number;
          scalingFactor: number;
      } = {}

      Options which configure how the intersection is computed

      • clipType: number

        The clipper clip type

      • scalingFactor: number

        A scaling factor passed to Polygon#toClipperPoints to preserve precision

    Returns ClipperPoint[]

    The resulting ClipperPaths

  • 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

    • Optional options: {
          density: number;
      }

      Options which configure how the intersection is computed

      • density: number

        The number of points which defines the density of approximation

    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

    • Optional options: object

      Options which configure how the intersection is computed

    Returns Polygon

    The intersected polygon

  • Protected

    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 void

  • Protected

    Determine the edge types and their manner of inclusion for this polygon instance.

    Returns Record<EdgeTypes, 0 | 1 | 2>

  • Protected

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

    Parameters

    • edge: Edge

      The Edge being considered

    • edgeTypes: Record<EdgeTypes, 0 | 1 | 2>

      Which types of edges are being used? 0=no, 1=maybe, 2=always

    • bounds: Rectangle

      The overall bounding box

    Returns boolean

    Should the edge be included?

  • Protected

    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

  • Protected

    Consolidate all vertices from identified edges and register them as part of the vertex mapping.

    Returns void

  • Protected

    Add additional vertices for intersections between edges.

    Parameters

    • edgeMap: Map<string, Edge>

    Returns void

  • Private

    Execute the sweep over wall vertices

    Returns 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

  • Update active edges at a given vertex Remove counter-clockwise edges which have now concluded. Add clockwise edges which are ongoing or beginning.

    Parameters

    • vertex: PolygonVertex

      The current vertex

    • activeEdges: EdgeSet

      A set of currently active edges

    Returns void

  • Private

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

    Returns EdgeSet

    A set of initially active edges

  • Private

    Sort vertices clockwise from the initial ray (due west).

    Returns PolygonVertex[]

    The array of sorted vertices

  • Private

    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.vertexA is ccw to edge.vertexB 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
  • Private

    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

  • Private

    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

  • Identify the collision points between an emitted Ray and a set of active edges.

    Parameters

    • vertices: PolygonVertex[]

      Active vertices

    • keys: Set<number>

      Active vertex keys

    • ray: Ray

      The candidate ray to test

    • activeEdges: EdgeSet

      The set of edges to check for collisions against the ray

    Returns void

  • Private

    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>

  • 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 any

    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

  • Construct a PIXI.Polygon instance from an array of clipper points [{X,Y}, ...].

    Parameters

    • points: ClipperPoint[]

      An array of points returned by clipper

    • Optional options: {
          scalingFactor: number;
      } = {}

      Options which affect how canvas points are generated

      • scalingFactor: number

        A scaling factor used to preserve floating point precision

    Returns Polygon

    The resulting PIXI.Polygon