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

    Class PolygonTree

    A polygon tree.

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    • get area(): number

      The area of this node.

      Returns number

    • get bounds(): Rectangle

      The bounds of the polygon, or the combined bounds of all children in case of the root node.

      The value of this property must not be mutated.

      Returns Rectangle

    • get children(): readonly PolygonTreeNode[]

      The children of this node.

      The value of this property must not be mutated.

      Returns readonly PolygonTreeNode[]

    • get depth(): number

      The depth of this node. The depth of the root node is 0.

      Returns number

    • get isEmpty(): boolean

      Is the (sub)tree empty?

      Returns boolean

    • get isHole(): boolean

      Is this a hole? The root node is a hole.

      Returns boolean

    • get parent(): PolygonTreeNode | null

      The parent of this node or null if this is the root node.

      Returns PolygonTreeNode | null

    • get path(): readonly Point[] | null

      The path of the polygon ([{x: x0, y: y0}, {x: x1, y: y1}, ...]). They are null in case of the root node.

      The value of this property must not be mutated.

      Returns readonly Point[] | null

    • get points(): readonly number[] | null

      The points of the polygon ([x0, y0, x1, y1, ...]). They are null in case of the root node.

      The value of this property must not be mutated.

      Returns readonly number[] | null

    • get polygon(): Polygon | null

      The polygon of this node. It is null in case of the root node.

      The value of this property must not be mutated.

      Returns Polygon | null

    • get polygons(): readonly Polygon[]

      The polygons of this polygon tree.

      The value of this property must not be mutated.

      Returns readonly Polygon[]

    • get triangulation(): Readonly<
          { indices: Uint16Array
          | Uint32Array; vertices: Float32Array },
      >

      The triangulation of this polygon tree.

      The value of this property must not be mutated.

      Returns Readonly<{ indices: Uint16Array | Uint32Array; vertices: Float32Array }>

    Methods

    • Draw the polygon tree into the Graphics element.

      Parameters

      • graphics: Graphics

        The Graphics element.

      Returns void

    • Find a point inside this polygon tree that is closest to the given reference point.

      Parameters

      • point: Point

        The reference point.

      Returns Point

      The closest point to the reference point in the polygon tree.

    • Compute the intersection of the polygon tree with the given Clipper path.

      Parameters

      • path: types.ClipperPoint[]

        The Clipper path to intersect the polygon tree with (the scaling factor must be CONST.CLIPPER_SCALING_FACTOR).

      • Optionaloptions: { clipType?: number; fillType?: number } = {}

        Additional options.

        • OptionalclipType?: number

          The Clipper clip type. Default: ClipperLib.ClipType.ctIntersection.

        • OptionalfillType?: number

          The Clipper fill type used for the Clipper path. Default: ClipperLib.PolyFillType.pftEvenOdd.

      Returns PolygonTree

      The result of the intersection.

    • Compute the intersection of the polygon tree with the given polygon.

      Parameters

      • polygon: Polygon

        The polygon to intersect the polygon tree with.

      • Optionaloptions: { clipType?: number; fillType?: number }

        Additional options.

        • OptionalclipType?: number

          The Clipper clip type. Default: ClipperLib.ClipType.ctIntersection.

        • OptionalfillType?: number

          The Clipper fill type used for the polygon. Default: ClipperLib.PolyFillType.pftEvenOdd.

      Returns PolygonTree

      The result of the intersection.

    • Test circle containment/intersection with this (sub)tree.

      Parameters

      • center: Point

        The center point of the circle.

      • radius: number

        The radius of the circle.

      Returns -1 | 0 | 1

      • -1: the circle is in the exterior and does not intersect the boundary. - 0: the circle is intersects the boundary. - 1: the circle is in the interior and does not intersect the boundary.
    • Test whether given point is contained within this (sub)tree. If distance is is nonzero, true is returned if and only if the signed distance from the point to the boundary of the (sub)tree is less than or equal to distance. The signed distance is positive for points in the exterior of the (sub)tree and negative for points within the interior of the (sub)tree.

      Parameters

      • point: Point

        The point.

      • Optionaldistance: number = 0

        The tolerance of the containment test.

      Returns boolean

      polygonTree.testPoint({x, y}, r);
      
      polygonTree.testPoint({x, y}, r);
      
      polygonTree.testPoint({x, y}, -r);
      
    • Create the tree from a Clipper polygon tree.

      Parameters

      • clipperPolyTree: PolyTree

      Returns PolygonTree