Copyright © 2021 by K4.org
  (v.0.48.124)

Polygon is a pure geometry object. It is used for geometric computations within rules. A Polygon can have a boundary and any number of holes, each described by a chain of Points. The polygon cannot contain internal islands. The points are stored both as Point objects as well as 2D GeoJSON x-y locations if demanded. A Polygon also stores its plane and "flattener" transform. A Polygon stores its boundary in CCW order relative to its normal, and holes are stored CW. Collinear points will NOT be removed from the boundary or holes. This is so that the author can rely on such points being kept if needed.

Hierarchy

Implements

  • IKnown

Index

Constructors

constructor

Properties

boundary

boundary: Point[]

The outer loop; by definition CCW about normal

holes

holes: Point[][]

Discrete inner loops, CW about normal

Readonly plane

plane: Plane

The plane of this polygon

Readonly xform

xform: Frame

3D to 2D "flattener" to this.plane

Accessors

areaTotal

areaTotal:

The total area of this polygon. So named because the area() method, which is not cached, already existed.

boundaryEdges

boundaryEdges:

The set of Lines built from the boundary points. Use boundaryEdges2 to ensure the Lines are co-planar.

boundaryEdges2

boundaryEdges2:

This is the edges quashed to the xform plane.

frame2d

frame2d:

geoJson

geoJson:

holeEdges

holeEdges:

The set of Lines built from the hole points.

normal

normal:

The returned value is normalized.

polygon

polygon:

Convenience function to allow mixed use with objects like Profile.

Methods

area

  • area(): number
  • Computes the area of this Polygon by triangulating and then summing the area of the triangles.

    Returns number

    Area of this polygon.

clone

  • Returns a copy of this.

    Returns Polygon

containsPoint

  • containsPoint(pt: Point): boolean
  • Returns true if pt is inside or on the boundary of this polygon. If a point is inside a hole, it is considered outside. If the point is not exactly in the plane of the polygon, it is dropped onto it before testing.

    Parameters

    • pt: Point

      The test point.

    Returns boolean

    Boolean indicating inside.

describe

  • describe(): string
  • Returns string

    A string of the form polygon[b:n, h:m]

flatten

  • Returns a new Polygon which has been flattened to the XY plane of xform. This is used to ensure that all polygons in boolean operations are in the same plane.

    Parameters

    Returns Polygon

    New Polygon

Protected getGeoJson

  • Returns the GeoJSON for this polygon relative to xform.

    Parameters

    Returns GeoJsonPolygon

makePie

  • Creates a "pie slice" shaped polygon.

    Parameters

    • cen: Point

      Pie center

    • nor: Vector

      Pie normal

    • rad: number

      Pie radius

    • dir1: Vector

      Direction from center to starting point

    • dir2: Vector

      Direction from center to finishing point

    • Optional deviation: number

      Optional. Maximum allowed deviation from a true arc. Default is system global.

    Returns Point[]

nearestPoint

  • Finds the nearest point to pt on this polygon.

    Parameters

    • pt: Point

      The given point

    Returns Point

offset

  • offset(dist: number, arcsegs?: number): Polygon[]
  • Creates an offset of this polygon. This does not handle holes.

    deprecated

    Use offset2 instead.

    Parameters

    • dist: number

      Distance to offset (negative offsets inward/left)

    • Optional arcsegs: number

      Number of segments to use for outside corners (default 5)

    Returns Polygon[]

    An array of polygons.

offset2

  • offset2(distances: number[], fillType?: string, deviation?: number): Polygon[]
  • Creates an offset of the boundary of this polygon. NOTE: This currently ignores holes in this polygon, but can produce holes in the output polygon(s).

    Parameters

    • distances: number[]

      Distances to offset (negative offsets inward/left)

    • Default value fillType: string = "circular"

      One of "circular" (the default), "miter", or "bevel". Only the first letter is actually used.

    • Default value deviation: number = maxDeviation

      Max deviation for arc approximation. Default is system global.

    Returns Polygon[]

    An array of polygons.

polygonBoolean

  • Performs a polygon boolean operation on another Polygon. This is the GeoJSON/Martinez version. This is obsolete.

    Parameters

    • polyB: Polygon

      The polygon to combine with this one

    • operation: string

      The boolean operation. One of 'union', 'intersection', or 'difference'. Actually only looks at the first letter.

    Returns Polygon[]

polygonSetBoolean

  • Combines this with a set of tools. This is the Martinez/GeoJSON version and is obsolete.

    Parameters

    • polys: Polygon[]

      The tools for the operation

    • operation: string

      The boolean operation. One of 'union', 'intersection', or 'difference'. Actually only looks at the first letter.

    Returns Polygon[]

polygonSetBoolean2

  • Combines this with a set of tools.

    Parameters

    • polys: Polygon[]

      The tools for the operation

    • operation: string

      The boolean operation. One of 'union', 'intersection', or 'difference'. Actually only looks at the first letter.

    Returns Polygon[]

same

  • Returns true if the this and poly can be considered the "same". They must have the same points, in the same order, but the first point does not need to be the same.

    Parameters

    • poly: Polygon

      The poly to compare against.

    Returns boolean

triangulate

  • triangulate(): MeshData
  • Returns the triangulation of this as a MeshData object.

    Returns MeshData

unflatten

  • Returns a new Polygon which has been 'unflattened' by the inverse of xform. This is used to restore flattened results to their original geometric space.

    Parameters

    Returns Polygon

    New Polygon

Static samePointLoop

  • samePointLoop(loop1: Point[], loop2: Point[]): boolean
  • Compares two point loops for equivalence.

    Parameters

    • loop1: Point[]

      List of points

    • loop2: Point[]

      List of points

    Returns boolean