Show / Hide Table of Contents

Class PolygonArea

An area with an arbitrary number of sides and corners

Inheritance
object
PolygonArea
Implements
IReadOnlyArea
IMatchable<IReadOnlyArea>
IEnumerable<Point>
IEnumerable
IMatchable<PolygonArea>
Inherited Members
object.GetType()
object.MemberwiseClone()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: GoRogue.MapGeneration
Assembly: GoRogue.dll
Syntax
public class PolygonArea : IReadOnlyArea, IMatchable<IReadOnlyArea>, IEnumerable<Point>, IEnumerable, IMatchable<PolygonArea>

Constructors

View Source

PolygonArea(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.

View Source

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.

View Source

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.

View Source

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 Source

LineAlgorithm

Which Line-Drawing algorithm to use

Declaration
public readonly Lines.Algorithm LineAlgorithm
Field Value
Type Description
Lines.Algorithm

Properties

View Source

Bottom

The bottom-most Y-value of the Polygon

Declaration
public int Bottom { get; }
Property Value
Type Description
int
View Source

Bounds

Smallest possible rectangle that encompasses every position in the area.

Declaration
public Rectangle Bounds { get; }
Property Value
Type Description
Rectangle
View Source

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

View Source

Corners

The corners of this polygon

Declaration
public IReadOnlyList<Point> Corners { get; }
Property Value
Type Description
IReadOnlyList<Point>
View Source

Count

Number of (unique) positions in the current area.

Declaration
public int Count { get; }
Property Value
Type Description
int
View Source

Height

how tall this Polygon is

Declaration
public int Height { get; }
Property Value
Type Description
int
View Source

InnerPoints

The interior points of the polygon

Declaration
public IReadOnlyArea InnerPoints { get; }
Property Value
Type Description
IReadOnlyArea
View Source

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
View Source

Left

The left-most X-value of the Polygon

Declaration
public int Left { get; }
Property Value
Type Description
int
View Source

OuterPoints

The exterior points of the polygon

Declaration
public IReadOnlyMultiArea OuterPoints { get; }
Property Value
Type Description
IReadOnlyMultiArea
View Source

Right

The right-most X-value of the Polygon

Declaration
public int Right { get; }
Property Value
Type Description
int
View Source

Top

The top-most Y-value of the Polygon

Declaration
public int Top { get; }
Property Value
Type Description
int
View Source

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.

View Source

Width

How Wide this Polygon is

Declaration
public int Width { get; }
Property Value
Type Description
int

Methods

View Source

Contains(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.

View Source

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.

View Source

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.

View Source

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

View Source

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
View Source

GetEnumerator()

Declaration
public IEnumerator<Point> GetEnumerator()
Returns
Type Description
IEnumerator<Point>
View Source

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.

View Source

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
View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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

View Source

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

View Source

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

View Source

ToString()

Returns a string detailing the region's corner locations.

Declaration
public override string ToString()
Returns
Type Description
string
Overrides
object.ToString()
View Source

Translate(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

View Source

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
View Source

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

View Source

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

Implements

IReadOnlyArea
IMatchable<T>
IEnumerable<T>
IEnumerable
IMatchable<T>

Extension Methods

Utility.Yield<T>(T)
LineHelpers.BottomAt(IEnumerable<Point>, int)
LineHelpers.LeftAt(IEnumerable<Point>, int)
LineHelpers.RightAt(IEnumerable<Point>, int)
LineHelpers.TopAt(IEnumerable<Point>, int)
Utility.ExtendToString<T>(IEnumerable<T>, string, Func<T, string>?, string, string)
  • View Source
In This Article
Back to top Generated by DocFX