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
StaticWALL_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
OptionalintersectionOptions: 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_constrainProtectedConstrain polygon points by applying boundary shapes.
Protected_defineProtectedCompute 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_determineProtectedDetermine the edge types and their manner of inclusion for this polygon instance.
Optionalconfig: object = {}Optional polygon config which may include deprecated properties
Protected_determineProtectedDetermine 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_executeProtectedExecute the sweep over wall vertices
Protected_identifyProtectedRetrieves 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_identifyProtectedAdd additional vertices for intersections between edges.
Protected_identifyProtectedConsolidate all vertices from identified edges and register them as part of the vertex mapping.
Protected_initializeProtectedDetermine the initial set of active edges as those which intersect with the initial ray
A set of initially active edges
Protected_isProtectedTest 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_sortProtectedSort vertices clockwise from the initial ray (due west).
The array of sorted vertices
Protected_switchProtectedSwitch 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_testProtectedTest 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_visualizeProtectedVisualize the polygon, displaying its computed area, rays, and collision points
StaticapplyAugment a PointSourcePolygon by adding additional coverage for shapes permitted by threshold walls.
The computed polygon
The augmented polygon
StaticbenchmarkBenchmark 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
StaticcreateCompute 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.
Optionalconfig: any = {}Configuration options which customize the polygon computation
The computed polygon instance
StatictestTest 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