A polygon is defined by a number of line segments that enclose an area.

Constructors

Properties

boundsCache: undefined | Rectangle
lineSegments: LineSegment[]

Methods

  • Returns the closest point on the polygon's perimiter to the given point.

    Parameters

    • p: Point

      The point that we want to get the closest point to.

    Returns Point

  • Checks if this polygon contains any of the points of the other polygon.

    Parameters

    • other: Polygon

      Polygon whose points are or are not part of this polygon.

    Returns boolean

  • Verifies whether a point reside inside this polygon or not. If the point is positioned at the periphery, it should be considered as not contained.

    Parameters

    Returns boolean

  • Finds the shortest distance, if it exists, that would make the point p hit this polygons perimiter when going in the defined direction.

    Parameters

    Returns Optional<number>

  • Checks if this polygon and the other polygon contains the same points.

    Parameters

    • other: Polygon

      Polygon to compare with.

    Returns boolean

  • Merges this polygon and the other polygon into one shape. If no overlap is found between the polygons exception is thrown.

    Parameters

    • other: Polygon

      Polygon to merge this polygon with.

    Returns Polygon

  • Return the middle point of this polygon. This is given by finding the smallest possible rectangle that encompasses the polygon, and returning the middle of that.

    Returns Point

  • Identifies if this polygon somehow overlaps the other polygon.

    Parameters

    Returns boolean

  • Finds the smallest possible vector in the given direction that this polygon can be translated so that it no longer overlaps the other polygon. If they already don't overlap, a null vector is returned.

    Parameters

    • other: Polygon

      The other polygon that we should no longer overlap

    • direction: Vector

      The direction that this polygon should be moved until it no longer overlaps the other polygon

    Returns Vector

  • Returns a Polygon that is expanded by 'size' units compared to this one.

    Parameters

    • size: number

      number of units the polygon should expand.

    Returns Polygon

  • Gives a readable representation of this polygon.

    Returns string

  • Returns a new polygon that is like this polygon with all points moved.

    Parameters

    • x: number
    • y: number

    Returns Polygon

  • Creates a Polygon from the given points. The points should preferably be given clockwise for the polygon, but if they are not, the given line segments will be corrected to make sure that they are clockwise oriented. The points are also not allowed to define lines that intersect other lines in the polygon. Ie. giving [0,0], [1,1], [1,0], [0,1] would not be allowed since line segments would intersect in the point [0.5, 0.5].

    Parameters

    • points: Point[]

      The given points that define the polygon. Lines are defined between points next to each other in the array.

    Returns Polygon

Generated using TypeDoc