ClockwiseSweepPolygon

ClockwiseSweepPolygon

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

Constructor

new ClockwiseSweepPolygon()

Extends

Members

config :ClockwiseSweepPolygonConfig

Overrides:

The configuration of this polygon.

Type:

edges :EdgeSet

The set of edges which define potential boundaries of the polygon

Type:

origin :Point

Inherited From:

The origin point of the source polygon.

Type:

rays :Array.<Ray>

Overrides:

A collection of rays which are fired at vertices

Type:

vertices :VertexMap

A mapping of vertices which define potential collision points

Type:

Methods

(static) getRayCollisions(ray, optionsopt) → {boolean|Array.<object>|object}

Check whether a given ray intersects with walls.

Parameters:
Name Type Attributes Default Description
ray Ray

The Ray being tested

options object <optional>
{}

Options which customize how collision is tested

Properties
Name Type Attributes Default Description
type string <optional>
move

Which collision type to check, a value in CONST.WALL_RESTRICTION_TYPES

mode string <optional>
all

Which type of collisions are returned: any, closest, all

debug boolean <optional>
false

Visualize some debugging data to help understand the collision test

Returns:

Whether any collision occurred if mode is "any" An array of collisions, if mode is "all" The closest collision, if mode is "closest"

Type
boolean | Array.<object> | object

(static) pointBetweenRays(vertex, rMin, rMax, angle) → {boolean}

Test whether a vertex lies between two boundary rays

Parameters:
Name Type Description
vertex PolygonVertex

The target vertex

rMin Ray

The counter-clockwise bounding ray

rMax Ray

The clockwise bounding ray

angle number

The angle being tested, in degrees

Returns:

Is the vertex between the two rays?

Type
boolean

(static) testWallInclusion(wall, origin, type) → {boolean}

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

Parameters:
Name Type Description
wall Wall

The Wall being considered

origin Point

The origin point for the ray or polygon

type string

The type of perception or movement restriction being imposed

Returns:

Should the wall be included?

Type
boolean

(protected) _compute()

Overrides:

Perform the implementation-specific computation

(protected) _getBounds(points) → {Rectangle}

Inherited From:

Compute the rectangular bounds for the Polygon.

Parameters:
Name Type Description
points Array.<number>

The initially provided array of coordinates

Returns:

The computed Rectangular bounds

Type
Rectangle

compute() → {PointSourcePolygon}

Inherited From:

Compute the polygon using the origin and configuration options.

Returns:

The computed polygon

Type
PointSourcePolygon

initialize(origin, config)

Overrides:

Customize the provided configuration object for this polygon type.

Parameters:
Name Type Description
origin Point

The provided polygon origin

config ClockwiseSweepPolygonConfig

The provided configuration object

visualize()

Overrides:

Visualize the polygon, displaying its computed area, rays, and collision points