Class PolygonArea
An area with an arbitrary number of sides and corners
Implements
Inherited Members
Namespace: GoRogue.MapGeneration
Assembly: GoRogue.dll
Syntax
public class PolygonArea : IReadOnlyArea, IMatchable<IReadOnlyArea>, IEnumerable<Point>, IEnumerable, IMatchable<PolygonArea>
Constructors
View SourcePolygonArea(Algorithm, params Point[])
Returns a new PolygonArea with corners at the provided points.
Declaration
public PolygonArea(Lines.Algorithm algorithm, params Point[] corners)
Parameters
| Type | Name | Description |
|---|---|---|
| Lines.Algorithm | algorithm | Which Line-drawing algorithm to use |
| Point[] | corners | The points which are corners for this polygon |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Must have 3 or more corners; Algorithm must produce ordered lines. |
PolygonArea(params Point[])
Returns a new polygon with corners at the provided points, using the algorithm DDA to produce lines
Declaration
public PolygonArea(params Point[] corners)
Parameters
| Type | Name | Description |
|---|---|---|
| Point[] | corners | The corners of the polygon |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Must have 3 or more corners; Algorithm must produce ordered lines. |
PolygonArea(IEnumerable<Point>, Algorithm)
Creates a new Polygon, with corners at the provided points
Declaration
public PolygonArea(IEnumerable<Point> corners, Lines.Algorithm algorithm = Algorithm.Bresenham)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Point> | corners | Each corner of the polygon, which is copied into a new list |
| Lines.Algorithm | algorithm | Which Line Algorithm to use |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Must have 3 or more corners; Algorithm must produce ordered lines. |
PolygonArea(ref List<Point>, Algorithm)
Creates a new Polygon, with corners at the provided points
Declaration
public PolygonArea(ref List<Point> corners, Lines.Algorithm algorithm = Algorithm.Bresenham)
Parameters
| Type | Name | Description |
|---|---|---|
| List<Point> | corners | The corners of this polygon |
| Lines.Algorithm | algorithm | Which Line Algorithm to use |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Must have 3 or more corners; Algorithm must produce ordered lines. |
Fields
View SourceLineAlgorithm
Which Line-Drawing algorithm to use
Declaration
public readonly Lines.Algorithm LineAlgorithm
Field Value
| Type | Description |
|---|---|
| Lines.Algorithm |
Properties
View SourceBottom
The bottom-most Y-value of the Polygon
Declaration
public int Bottom { get; }
Property Value
| Type | Description |
|---|---|
| int |
Bounds
Smallest possible rectangle that encompasses every position in the area.
Declaration
public Rectangle Bounds { get; }
Property Value
| Type | Description |
|---|---|
| Rectangle |
Center
The Center point of this Polygon
Declaration
public Point Center { get; }
Property Value
| Type | Description |
|---|---|
| Point |
Remarks
There is no guarantee that the center point lies within the polygon
Corners
The corners of this polygon
Declaration
public IReadOnlyList<Point> Corners { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<Point> |
Count
Number of (unique) positions in the current area.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
Height
how tall this Polygon is
Declaration
public int Height { get; }
Property Value
| Type | Description |
|---|---|
| int |
InnerPoints
The interior points of the polygon
Declaration
public IReadOnlyArea InnerPoints { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyArea |
this[int]
Returns positions from the area in the same fashion you would via a list.
Declaration
public Point this[int index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Index of list to retrieve. |
Property Value
| Type | Description |
|---|---|
| Point |
Left
The left-most X-value of the Polygon
Declaration
public int Left { get; }
Property Value
| Type | Description |
|---|---|
| int |
OuterPoints
The exterior points of the polygon
Declaration
public IReadOnlyMultiArea OuterPoints { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyMultiArea |
Right
The right-most X-value of the Polygon
Declaration
public int Right { get; }
Property Value
| Type | Description |
|---|---|
| int |
Top
The top-most Y-value of the Polygon
Declaration
public int Top { get; }
Property Value
| Type | Description |
|---|---|
| int |
UseIndexEnumeration
Whether or not it is more efficient for this implementation to use enumeration by index, rather than generic IEnumerable, when iterating over positions using ReadOnlyAreaPositionsEnumerator.
Declaration
public bool UseIndexEnumeration { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Set this to true if your indexer implementation scales well (constant time), and is relatively fast. Implementations with more complex indexers should set this to false.
The default interface implementation returns false, in order to preserve backwards compatibility with previous versions.
If you set this to false, your IEnumerable.GetEnumerator() implementations must NOT call return a ReadOnlyAreaPositionsEnumerator, as this will create an infinite loop.
Width
How Wide this Polygon is
Declaration
public int Width { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
View SourceContains(IReadOnlyArea)
Returns whether or not the given area is completely contained within the current one.
Declaration
public bool Contains(IReadOnlyArea area)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyArea | area | Area to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the given area is completely contained within the current one, false otherwise. |
Contains(Point)
Determines whether or not the given position is considered within the area or not.
Declaration
public bool Contains(Point position)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | position | The position to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the specified position is within the area, false otherwise. |
Contains(int, int)
Determines whether or not the given position is considered within the area or not.
Declaration
public bool Contains(int positionX, int positionY)
Parameters
| Type | Name | Description |
|---|---|---|
| int | positionX | X-value of the position to check. |
| int | positionY | X-value of the position to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the specified position is within the area, false otherwise. |
FlipHorizontal(int)
Flip horizontally around an X-axis
Declaration
public PolygonArea FlipHorizontal(int x)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The value around which to flip. |
Returns
| Type | Description |
|---|---|
| PolygonArea | A new, flipped PolygonArea |
FlipVertical(int)
Flip vertically around a Y-axis
Declaration
public PolygonArea FlipVertical(int y)
Parameters
| Type | Name | Description |
|---|---|---|
| int | y | The value around which to flip. |
Returns
| Type | Description |
|---|---|
| PolygonArea |
GetEnumerator()
Declaration
public IEnumerator<Point> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<Point> |
Intersects(IReadOnlyArea)
Returns whether or not the given map area intersects the current one. If you intend to determine/use the exact intersection based on this return value, it is best to instead call GetIntersection(IReadOnlyArea, IReadOnlyArea, IEqualityComparer<Point>), and check the number of positions in the result (0 if no intersection).
Declaration
public bool Intersects(IReadOnlyArea area)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyArea | area | The area to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the given area intersects the current one, false otherwise. |
IsCorner(Point)
Returns true if the position provided is a corner of this polygon
Declaration
public bool IsCorner(Point position)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | position |
Returns
| Type | Description |
|---|---|
| bool |
Matches(PolygonArea?)
Compares the polygons to ensure that they are defined by the same corners, and thus represent the same area.
Declaration
public bool Matches(PolygonArea? other)
Parameters
| Type | Name | Description |
|---|---|---|
| PolygonArea | other |
Returns
| Type | Description |
|---|---|
| bool | True if the polygons represent the same area; false otherwise. |
Matches(IReadOnlyArea?)
Returns true if the given object is considered "equal" to the current one, based on the definition of equality for the object.
Declaration
public bool Matches(IReadOnlyArea? other)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyArea | other | Object to compare to. |
Returns
| Type | Description |
|---|---|
| bool | True if the objects are considered equal, false, otherwise. |
Parallelogram(Point, int, int, bool, Algorithm)
Creates a new Polygon in the shape of a parallelogram.
Declaration
public static PolygonArea Parallelogram(Point origin, int width, int height, bool fromTop = false, Lines.Algorithm algorithm = Algorithm.Bresenham)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | origin | Origin of the parallelogram. |
| int | width | Width of the parallelogram. |
| int | height | Height of the parallelogram. |
| bool | fromTop | Whether the parallelogram extends downward-right or upwards-right from the start |
| Lines.Algorithm | algorithm | Line-drawing algorithm to use for finding boundaries. |
Returns
| Type | Description |
|---|---|
| PolygonArea | A new Polygon in the shape of a parallelogram |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Must have 3 or more corners; Algorithm must produce ordered lines. |
Rectangle(Rectangle, Algorithm)
Creates a new Polygon from a GoRogue.Rectangle.
Declaration
public static PolygonArea Rectangle(Rectangle rectangle, Lines.Algorithm algorithm = Algorithm.Bresenham)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The rectangle |
| Lines.Algorithm | algorithm | Line-drawing algorithm to use for finding boundaries. |
Returns
| Type | Description |
|---|---|
| PolygonArea | A new Polygon in the shape of a rectangle |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Must have 3 or more corners; Algorithm must produce ordered lines. |
RegularPolygon(Point, int, double, Algorithm)
Creates a polygon whose sides are even-length
Declaration
public static PolygonArea RegularPolygon(Point center, int numberOfSides, double radius, Lines.Algorithm algorithm = Algorithm.Bresenham)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | center | The center point of this polygon |
| int | numberOfSides | Number of sides and corners on this polygon |
| double | radius | The desired distance between the center and each corner |
| Lines.Algorithm | algorithm | Which line-drawing algorithm to use |
Returns
| Type | Description |
|---|---|
| PolygonArea |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Must have 3 or more corners; Algorithm must produce ordered lines. |
RegularStar(Point, int, double, double, Algorithm)
Creates a new star-shaped polygon
Declaration
public static PolygonArea RegularStar(Point center, int points, double outerRadius, double innerRadius, Lines.Algorithm algorithm = Algorithm.Bresenham)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | center | The center point of the star |
| int | points | How many points this star has |
| double | outerRadius | The distance between the center and a tip of the star |
| double | innerRadius | The distance between the center and an armpit of the star |
| Lines.Algorithm | algorithm | Which line-drawing algorithm to use |
Returns
| Type | Description |
|---|---|
| PolygonArea |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Stars must have 3 or more points; algorithm must be ordered; inner and outer radius must be positive |
Rotate(double)
Rotates the Polygon around it's center.
Declaration
public PolygonArea Rotate(double degrees)
Parameters
| Type | Name | Description |
|---|---|---|
| double | degrees | The amount of degrees to rotate |
Returns
| Type | Description |
|---|---|
| PolygonArea | A new, rotated PolygonArea |
Rotate(double, Point)
Rotates the Polygon around a point of origin
Declaration
public PolygonArea Rotate(double degrees, Point origin)
Parameters
| Type | Name | Description |
|---|---|---|
| double | degrees | The amount of degrees to rotate |
| Point | origin | The Point around which to rotate |
Returns
| Type | Description |
|---|---|
| PolygonArea | A new, rotated PolygonArea |
ToString()
Returns a string detailing the region's corner locations.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
View SourceTranslate(Point)
Moves the Polygon in the indicated direction.
Declaration
public PolygonArea Translate(Point delta)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | delta | The amount (X and Y) to translate by. |
Returns
| Type | Description |
|---|---|
| PolygonArea | A new, translated PolygonArea |
Translate(int, int)
Moves the Polygon in the indicated direction.
Declaration
public PolygonArea Translate(int dx, int dy)
Parameters
| Type | Name | Description |
|---|---|---|
| int | dx | The X-value by which to shift |
| int | dy | The Y-value by which to shift |
Returns
| Type | Description |
|---|---|
| PolygonArea |
Transpose(Point)
Invert the X and Y values of a Polygon, respective to a diagonal line
Declaration
public PolygonArea Transpose(Point xy)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | xy | Any point which intersects the line around which to transpose |
Returns
| Type | Description |
|---|---|
| PolygonArea | A new PolygonArea |
Transpose(int, int)
Invert the X and Y values of a Polygon, respective to a diagonal line
Declaration
public PolygonArea Transpose(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | Any X-value of a point which intersects the line around which to transpose |
| int | y | Any Y-value of a Point which intersects the line around which to transpose |
Returns
| Type | Description |
|---|---|
| PolygonArea | A new PolygonArea |