Show / Hide Table of Contents

Class PolygonGrid2D

A class representing an immutable polygon where each of its vertices has integer coordinates.

Inheritance
System.Object
PolygonGrid2D
Namespace: Edgar.Geometry
Assembly: Edgar.dll
Syntax
public class PolygonGrid2D : Object
Remarks

Several invariants hold:

  • a polygon has at least 4 points
  • all lines must be parallel to one of the axis
  • no two adjacent line can be both horizontal or both vertical
  • points are in a clockwise order

Constructors

PolygonGrid2D(IEnumerable<Vector2Int>)

Create a polygon with given points.

Declaration
public PolygonGrid2D(IEnumerable<Vector2Int> points)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Vector2Int> points
Exceptions
Type Condition
System.ArgumentException

Thrown when invariants do not hold

Fields

PossibleRotations

Declaration
public static readonly int[] PossibleRotations
Field Value
Type Description
System.Int32[]

Properties

BoundingRectangle

Declaration
public RectangleGrid2D BoundingRectangle { get; }
Property Value
Type Description
RectangleGrid2D

Methods

Equals(Object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj
Returns
Type Description
System.Boolean

GetAllRotations()

Get all possible rotations of the polygon.

Declaration
public IEnumerable<PolygonGrid2D> GetAllRotations()
Returns
Type Description
System.Collections.Generic.IEnumerable<PolygonGrid2D>
Remarks

Possibly includes duplicates as e.g. all rotations of a square ale equal.

GetAllTransformations()

Get all possible transformations of the polygon.

Declaration
public IEnumerable<PolygonGrid2D> GetAllTransformations()
Returns
Type Description
System.Collections.Generic.IEnumerable<PolygonGrid2D>
Remarks

Possibly includes duplicates as e.g. all rotations of a square ale equal.

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

GetLines()

Gets all lines of the polygon ordered as they appear on the polygon.

Declaration
public List<OrthogonalLineGrid2D> GetLines()
Returns
Type Description
System.Collections.Generic.List<OrthogonalLineGrid2D>

GetPoints()

Gets point of the polygon.

Declaration
public ReadOnlyCollection<Vector2Int> GetPoints()
Returns
Type Description
System.Collections.ObjectModel.ReadOnlyCollection<Vector2Int>

GetRectangle(Int32, Int32)

Helper method to create a rectangle with given sides.

Declaration
public static PolygonGrid2D GetRectangle(int width, int height)
Parameters
Type Name Description
System.Int32 width
System.Int32 height
Returns
Type Description
PolygonGrid2D

GetSquare(Int32)

Helper method for creating a polygon with side a.

Declaration
public static PolygonGrid2D GetSquare(int a)
Parameters
Type Name Description
System.Int32 a

Length of the side.

Returns
Type Description
PolygonGrid2D

Rotate(Int32)

Rotates the polygon.

Declaration
public PolygonGrid2D Rotate(int degrees)
Parameters
Type Name Description
System.Int32 degrees

Degrees divisble by 90.

Returns
Type Description
PolygonGrid2D

Scale(Vector2Int)

Scales the polygon.

Declaration
public PolygonGrid2D Scale(Vector2Int factor)
Parameters
Type Name Description
Vector2Int factor
Returns
Type Description
PolygonGrid2D

ToString()

Declaration
public override string ToString()
Returns
Type Description
System.String

Transform(TransformationGrid2D)

Transforms a given polygon.

Declaration
public PolygonGrid2D Transform(TransformationGrid2D transformation)
Parameters
Type Name Description
TransformationGrid2D transformation
Returns
Type Description
PolygonGrid2D
Remarks

Returns a new polygon rather than modifying the original one.

Some transformations would result in a counter-clockwise order of points, which is currently not allowed. In that case, the order of points is reversed with the first point staying the same.

Operators

Addition(PolygonGrid2D, Vector2Int)

Computes a polygon that has all points moved by a given position.

Declaration
public static PolygonGrid2D operator +(PolygonGrid2D polygon, Vector2Int position)
Parameters
Type Name Description
PolygonGrid2D polygon
Vector2Int position
Returns
Type Description
PolygonGrid2D
Back to top Generated by DocFX