Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    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 Summary)

    Index

    Properties

    bounds: Rectangle = ...

    The rectangular bounds of this polygon

    The configuration of this polygon.

    edges: EdgeSet = ...

    The set of edges which define potential boundaries of the polygon

    The origin point of the source polygon.

    rays: Ray[] = []

    A collection of rays which are fired at vertices

    surfaceExposure: any

    The area of surfaces that is visible to this polygon, if any.

    vertices: VertexMap = ...

    A mapping of vertices which define potential collision points

    Accessors

    • get isConstrained(): boolean

      An indicator for whether this polygon is constrained by some boundary shape?

      Returns boolean

    • get useInnerBounds(): boolean

      Is this polygon using inner bounds?

      Returns boolean

    Methods

    • Parameters

      • ray: any
      • mode: any
      • destination: any
      • tMin: any
      • tMax: any

      Returns any

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

      Parameters

      • __namedParameters: { x: any; y: any }

      Returns ClockwiseSweepPolygon

    • 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

      • OptionalintersectionOptions: object = {}

        Options passed to the shape intersection method

      Returns PointSourcePolygon<PointSourcePolygonConfig>

      A new constrained polygon

    • Customize the provided configuration object for this polygon type.

      Parameters

      • origin: any

        The provided polygon origin. The elevation defaults to the elevation of config.source if passed and otherwise 0.

      • config: any

        The provided configuration object

      Returns void

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

      Returns boolean

    • 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

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

      Parameters

      • type: string
      • priority: number
      • Optionalconfig: object = {}

        Optional polygon config which may include deprecated properties

      Returns Record<EdgeType, ClockwiseSweepEdgeConfig>

    • Protected

      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

    • Protected

      Execute the sweep over wall vertices

      Returns void

    • Protected

      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.

      Returns void

    • Protected

      Add additional vertices for intersections between edges.

      Parameters

      • edgeMap: Map<string, Edge>

      Returns void

    • Protected

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

      Returns void

    • Protected

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

      Returns EdgeSet

      A set of initially active edges

    • Protected

      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

      Returns { isBehind: boolean; wasLimited: boolean }

      Is the target vertex behind some closer edge?

    • Protected

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

      Returns PolygonVertex[]

      The array of sorted vertices

    • Protected

      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

      Returns void

    • Protected

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

      Parameters

      Returns boolean

      Should the edge be included?

    • Protected

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

      Parameters

      Returns void

    • Benchmark the performance of polygon computation for this source

      Parameters

      • iterations: number

        The number of test iterations to perform

      • origin: Point | ElevatedPoint

        The origin point to benchmark

      • config: PolygonConfig

        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 | ElevatedPoint

        An origin point. The elevation defaults to the elevation of config.source if passed and otherwise 0.

      • destination: Point | ElevatedPoint

        A destination point. The elevation defaults to the elevation of the origin.

      • config: PolygonConfig = {}

        The configuration that defines a certain Polygon type

        • mode

          The collision mode to test: "any", "all", or "closest"

        • tMin

          Intersections of the ray and an edge with t-value at most tMin are not considered collisions. Default: 0.

        • tMax

          Intersections of the ray and an edge with t-value greater than tMax are not considered collisions. Default: 1.

      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