The rectangular bounds of this polygon
The configuration of this polygon.
The set of edges which define potential boundaries of the polygon
The origin point of the source polygon.
A collection of rays which are fired at vertices
A mapping of vertices which define potential collision points
Static
WALL_Customize how wall direction of one-way walls is applied
An indicator for whether this polygon is constrained by some boundary shape?
Is this polygon using inner bounds?
Perform the implementation-specific computation
This function has been adapted from Clipper's CleanPolygon function. When adding a new point to the polygon, check for collinearity with prior points to cull unnecessary points. This also removes spikes where we traverse points (a, b, a). We also enforce a minimum distance between two points, or a minimum perpendicular distance between three almost collinear points.
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.
The constraining boundary shape
Optional
intersectionOptions: object = {}Options passed to the shape intersection method
A new constrained polygon
Create a clone of this polygon. This overrides the default PIXI.Polygon#clone behavior.
A cloned instance
Compute the polygon using the origin and configuration options.
The computed polygon
Customize the provided configuration object for this polygon type.
The provided polygon origin. The elevation defaults to the elevation of config.source if passed and otherwise 0.
The provided configuration object
Determine if the shape is a complete circle. The config object must have an angle and a radius properties.
Protected
_constrainProtected
Constrain polygon points by applying boundary shapes.
Protected
_defineProtected
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.
Protected
_determineProtected
Determine the edge types and their manner of inclusion for this polygon instance.
Optional
config: object = {}Optional polygon config which may include deprecated properties
Protected
_determineProtected
Determine the result for the sweep at a given vertex
The target vertex
The set of active edges
Are there collinear vertices behind the target vertex?
Protected
_executeProtected
Execute the sweep over wall vertices
Protected
_identifyProtected
Retrieves the super-set of walls that could potentially apply to this polygon. Utilizes a custom collision test and the Quadtree to obtain candidate edges efficiently.
Protected
_identifyProtected
Add additional vertices for intersections between edges.
Protected
_identifyProtected
Consolidate all vertices from identified edges and register them as part of the vertex mapping.
Protected
_initializeProtected
Determine the initial set of active edges as those which intersect with the initial ray
A set of initially active edges
Protected
_isProtected
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.
The target vertex
The set of active edges
Is the target vertex behind some closer edge?
Protected
_sortProtected
Sort vertices clockwise from the initial ray (due west).
The array of sorted vertices
Protected
_switchProtected
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.
The pending collision result
The set of currently active edges
Protected
_testProtected
Test whether a wall should be included in the computed polygon for a given origin and type
The Edge being considered
Which types of edges are being used? 0=no, 1=maybe, 2=always
Should the edge be included?
Protected
_visualizeProtected
Visualize the polygon, displaying its computed area, rays, and collision points
Static
applyAugment a PointSourcePolygon by adding additional coverage for shapes permitted by threshold walls.
The computed polygon
The augmented polygon
Static
benchmarkBenchmark the performance of polygon computation for this source
The number of test iterations to perform
The origin point to benchmark
The polygon configuration to benchmark
Static
createCompute the polygon given a point origin and radius
The origin source point. The elevation defaults to the elevation of config.source if passed and otherwise 0.
Optional
config: any = {}Configuration options which customize the polygon computation
The computed polygon instance
Static
testTest 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.
An origin point. The elevation defaults to the elevation of config.source if passed and otherwise 0.
A destination point. The elevation defaults to the elevation of the origin.
The configuration that defines a certain Polygon type
The collision mode to test: "any", "all", or "closest"
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
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