Struct Rectangle
Represents a rectangle in terms of grid squares. Provides numerous static functions that enable creation and common operations involving rectangles, as well as implicit conversion operators that enable interoperability with rectangle representations from other libraries.
Implements
Inherited Members
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
[Serializable]
public struct Rectangle : IEquatable<Rectangle>, IEquatable<(int x, int y, int width, int height)>
Remarks
Rectangle is designed to be extremely efficient and interoperable with equivalent representations in other libraries, so in general, in an environment where you have multiple rectangle representations defined, it is best to prefer Rectangle where possible, as something that accepts or works with Rectangle will generally work with other supported types as well.
Constructors
| Improve this Doc View SourceRectangle(Coord, Coord)
Constructor.
Declaration
public Rectangle(Coord minExtent, Coord maxExtent)
Parameters
Type | Name | Description |
---|---|---|
Coord | minExtent | Minimum x and y values that are considered inside the rectangle. |
Coord | maxExtent | Maximum x and y values that are considered inside the rectangle. |
Rectangle(Coord, Int32, Int32)
Constructor.
Declaration
public Rectangle(Coord center, int horizontalRadius, int verticalRadius)
Parameters
Type | Name | Description |
---|---|---|
Coord | center | The center point of the rectangle. |
System.Int32 | horizontalRadius | Number of units to the left and right of the center point that are included within the rectangle. |
System.Int32 | verticalRadius | Number of units to the top and bottom of the center point that are included within the rectangle. |
Rectangle(Int32, Int32, Int32, Int32)
Constructor.
Declaration
public Rectangle(int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | Minimum x coordinate that is inside the rectangle. |
System.Int32 | y | Minimum y coordinate that is inside the rectangle. |
System.Int32 | width | Width of the rectangle. |
System.Int32 | height | Height of the rectangle. |
Fields
| Improve this Doc View SourceEMPTY
The empty rectangle. Has origin of (0, 0) with 0 width and height.
Declaration
[NonSerialized]
public static readonly Rectangle EMPTY
Field Value
Type | Description |
---|---|
Rectangle |
Height
The height of the rectangle.
Declaration
public readonly int Height
Field Value
Type | Description |
---|---|
System.Int32 |
Width
The width of the rectangle.
Declaration
public readonly int Width
Field Value
Type | Description |
---|---|
System.Int32 |
X
X-coordinate of position of the rectangle.
Declaration
public readonly int X
Field Value
Type | Description |
---|---|
System.Int32 |
Y
Y-coordinate of position of the rectangle.
Declaration
public readonly int Y
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
| Improve this Doc View SourceArea
Calculates the area of the rectangle.
Declaration
public int Area { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Center
The center coordinate of the rectangle, rounded up if the exact center is between two positions. The center of a rectangle with width/height 1 is its Position.
Declaration
public Coord Center { get; }
Property Value
Type | Description |
---|---|
Coord |
IsEmpty
Whether or not this rectangle is empty (has width and height of 0).
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
MaxExtent
The maximum X and Y coordinates that are included in the rectangle.
Declaration
public Coord MaxExtent { get; }
Property Value
Type | Description |
---|---|
Coord |
MaxExtentX
The maximum X-coordinate that is included in the rectangle.
Declaration
public int MaxExtentX { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
MaxExtentY
The maximum Y-coordinate that is included in the rectangle.
Declaration
public int MaxExtentY { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
MinExtent
Minimum extent of the rectangle (minimum x and y values that are included within it). Identical to Position because we define the rectangle's position by its minimum extent.
Declaration
public Coord MinExtent { get; }
Property Value
Type | Description |
---|---|
Coord |
MinExtentX
X-value of the minimum extent of the rectangle (minimum x value that is included within it). Identical to the X value because we define the rectangle's position by its minimum extent.
Declaration
public int MinExtentX { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
MinExtentY
Y-value of the minimum extent of the rectangle (minimum y value that is included within it). Identical to the Y value because we define the rectangle's position by its minimum extent.
Declaration
public int MinExtentY { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Perimeter
Calculates the perimeter length of the rectangle. This is equal to the mathematical perimeter, NOT the number of grid squares around the perimiter.
Declaration
public int Perimeter { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Position
Coord representing the position (min x- and y-values) of the rectangle.
Declaration
public Coord Position { get; }
Property Value
Type | Description |
---|---|
Coord |
Size
Returns a coordinate (Width, Height), which represents the size of the rectangle.
Declaration
public Coord Size { get; }
Property Value
Type | Description |
---|---|
Coord |
Methods
| Improve this Doc View SourceChangeHeight(Int32)
Creates and returns a new rectangle whose position is the same as the current one, but has its height changed by the given delta-change value.
Declaration
public Rectangle ChangeHeight(int deltaHeight)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | deltaHeight | Delta-change for the height of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle whose height is modified by the given delta-change value. |
ChangeSize(Coord)
Creates and returns a new rectangle whose position is the same as the current one, but has its width and height changed by the given delta-change values.
Declaration
public Rectangle ChangeSize(Coord deltaChange)
Parameters
Type | Name | Description |
---|---|---|
Coord | deltaChange | Vector (deltaWidth, deltaHeight) specifying the delta-change values for the width/height of the new Rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle whose width/height are modified by the given delta-change values. |
ChangeSize(Int32, Int32)
Creates and returns a new rectangle whose position is the same as the current one, but has its width and height changed by the given delta-change values.
Declaration
public Rectangle ChangeSize(int deltaWidth, int deltaHeight)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | deltaWidth | Delta-change for the width of the new rectangle. |
System.Int32 | deltaHeight | Delta-change for the height of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle whose width/height are modified by the given delta-change values. |
ChangeWidth(Int32)
Creates and returns a new rectangle whose position is the same as the current one, but has its width changed by the given delta-change value.
Declaration
public Rectangle ChangeWidth(int deltaWidth)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | deltaWidth | Delta-change for the width of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle whose width is modified by the given delta-change value. |
Contains(Coord)
Returns whether or not the specified point is considered within the rectangle.
Declaration
public bool Contains(Coord position)
Parameters
Type | Name | Description |
---|---|---|
Coord | position | The position to check. |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not the specified point is considered within the rectangle. |
Contains(Rectangle)
Returns whether or not the specified rectangle is considered completely contained within the current one.
Declaration
public bool Contains(Rectangle other)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | other | The rectangle to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the given rectangle is completely contained within the current one, false otherwise. |
Contains(Int32, Int32)
Returns whether or not the specified point is considered within the rectangle.
Declaration
public bool Contains(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The x-value position to check. |
System.Int32 | y | The y-value position to check. |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not the specified point is considered within the rectangle. |
Deconstruct(out Int32, out Int32, out Int32, out Int32)
Adds support for C# Deconstruction syntax.
Declaration
public void Deconstruct(out int x, out int y, out int width, out int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | |
System.Int32 | y | |
System.Int32 | width | |
System.Int32 | height |
Equals(Rectangle)
Compares based upon whether or not the areas contained within the rectangle are identical in both position and extents.
Declaration
public bool Equals(Rectangle other)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | other |
Returns
Type | Description |
---|---|
System.Boolean | true if the area of the two rectangles encompass the exact same area, false otherwise. |
Equals(Object)
Compares to an arbitrary object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj |
Returns
Type | Description |
---|---|
System.Boolean | true if the object specified is a rectangle instance and encompasses the same area, false otherwise. |
Overrides
Equals((Int32 x, Int32 y, Int32 width, Int32 height))
True if the given position has equal x and y values to the current one.
Declaration
public bool Equals((int x, int y, int width, int height) other)
Parameters
Type | Name | Description |
---|---|---|
System.ValueTuple<System.Int32, System.Int32, System.Int32, System.Int32> | other | Point to compare. |
Returns
Type | Description |
---|---|
System.Boolean | True if the two positions are equal, false if not. |
Expand(Int32, Int32)
Returns a new rectangle, expanded to include the additional specified number of tiles on the left/right and top/bottom.
Declaration
public Rectangle Expand(int horizontalChange, int verticalChange)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | horizontalChange | Number of additional tiles to include on the left/right of the rectangle. |
System.Int32 | verticalChange | Number of additional tiles to include on the top/bottom of the rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, expanded appropriately. |
GetDifference(Rectangle, Rectangle)
Gets a MapArea representing every location in rect1
that
is NOT in rect2
.
Declaration
public static MapArea GetDifference(Rectangle rect1, Rectangle rect2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect1 | |
Rectangle | rect2 |
Returns
Type | Description |
---|---|
MapArea | A MapArea representing every location in |
GetExactUnion(Rectangle, Rectangle)
Gets a MapArea representing the exact union of the specified rectangles, eg. a MapArea containing all locations from either rectangle.
Declaration
public static MapArea GetExactUnion(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
MapArea | A MapArea containing every position in either rectangle. |
GetHashCode()
Simple hashing.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | Hash code for rectangle. |
Overrides
GetIntersection(Rectangle, Rectangle)
Returns the rectangle that represents the intersection of the two rectangles specified, or the empty rectangle if the specified rectangles do not intersect.
Declaration
public static Rectangle GetIntersection(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
Rectangle | Rectangle representing the intersection of |
GetUnion(Rectangle, Rectangle)
Gets the smallest possible rectangle that includes the entire area of both r1
and
r2
.
Declaration
public static Rectangle GetUnion(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
Rectangle | The smallest possible rectangle that includes the entire area of both |
Intersects(Rectangle)
Returns whether or not the given rectangle intersects the current one.
Declaration
public bool Intersects(Rectangle other)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | other | The rectangle to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the given rectangle intersects with the current one, false otherwise. |
MaxXPositions()
Gets all positions that reside on the max-x line of the rectangle.
Declaration
public IEnumerable<Coord> MaxXPositions()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> | IEnumerable of all positions that lie on the max-x line of the rectangle. |
MaxYPositions()
Gets all positions that reside on the max-y line of the rectangle.
Declaration
public IEnumerable<Coord> MaxYPositions()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> | IEnumerable of all positions that lie on the max-y line of the rectangle. |
MinXPositions()
Gets all positions that reside on the min-x line of the rectangle.
Declaration
public IEnumerable<Coord> MinXPositions()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> | IEnumerable of all positions that lie on the min-x line of the rectangle. |
MinYPositions()
Gets all positions that reside on the min-y line of the rectangle.
Declaration
public IEnumerable<Coord> MinYPositions()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> | IEnumerable of all positions that lie on the min-y line of the rectangle. |
PerimeterPositions()
Gets all positions that reside on the inner perimeter of the rectangle.
Declaration
public IEnumerable<Coord> PerimeterPositions()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> | IEnumerable of all positions that reside on the inner perimeter of the rectangle. |
Positions()
Returns all positions in the rectangle.
Declaration
public IEnumerable<Coord> Positions()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> | All positions in the rectangle. |
PositionsOnSide(Direction)
Gets an IEnumerable of all positions that line on the inner perimiter of the rectangle, on the given side of the rectangle.
Declaration
public IEnumerable<Coord> PositionsOnSide(Direction side)
Parameters
Type | Name | Description |
---|---|---|
Direction | side | Side to get positions for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> | IEnumerable of all positions that line on the inner perimieter of the rectangle on the given side. |
RandomPosition(Func<Coord, Boolean>, IGenerator)
Returns a random position from within this rectangle, for which the selector function specified returns true. Random positions will continuously be generated until one that qualifies is found.
Declaration
public Coord RandomPosition(Func<Coord, bool> selector, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<Coord, System.Boolean> | selector | Selector function that takes a position, and returns true if it is an acceptable selection, and false otherwise. |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
Coord | A random position from within the rectangle, for which the given selector function returned true. |
RandomPosition(Func<Rectangle, Coord, Boolean>, IGenerator)
Returns a random position from within this rectangle, for which the selector function specified returns true. Random positions will continuously be generated until one that qualifies is found.
Declaration
public Coord RandomPosition(Func<Rectangle, Coord, bool> selector, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<Rectangle, Coord, System.Boolean> | selector | Selector function that takes a position and a rectangle, and returns true if it is an acceptable selection, and false otherwise. |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
Coord | A random position from within the rectangle, for which the given selector function returned true. |
RandomPosition(IGenerator)
Returns a random position from within this rectangle.
Declaration
public Coord RandomPosition(IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
Coord | A random position from within the rectangle. |
ToString()
Returns a string representing the rectangle, formatted as (X, Y) -> (MaxExtentX, MaxExtentY)
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | String formatted as above. |
Overrides
Translate(Coord)
Creates and returns a new rectangle whose position has been moved by the given delta-change values.
Declaration
public Rectangle Translate(Coord deltaChange)
Parameters
Type | Name | Description |
---|---|---|
Coord | deltaChange | Delta-x and delta-y values by which to move the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, whose position has been moved by the given delta-change values. |
Translate(Direction)
Creates and returns a new rectangle that has its position moved in the given direction.
Declaration
public Rectangle Translate(Direction direction)
Parameters
Type | Name | Description |
---|---|---|
Direction | direction | The direction to move the new rectangle in. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that has its position moved in the given direction. |
Translate(Int32, Int32)
Creates and returns a new rectangle whose position has been moved by the given delta-change values.
Declaration
public Rectangle Translate(int dx, int dy)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dx | Delta-x value by which to move the new rectangle. |
System.Int32 | dy | Delta-y value by which to move the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, whose position has been moved by the given delta-change values. |
TranslateX(Int32)
Creates and returns a new rectangle whose x-position has been moved by the given delta value.
Declaration
public Rectangle TranslateX(int dx)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dx | Value by which to move the new rectangle's x-position. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, whose x-position has been moved by the given delta-x value. |
TranslateY(Int32)
Creates and returns a new rectangle whose y-position has been moved by the given delta value.
Declaration
public Rectangle TranslateY(int dy)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dy | Value by which to move the new rectangle's y-position. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, whose y-position has been moved by the given delta-y value. |
WithCenter(Coord)
Creates and returns a new rectangle that is the same size as the current one, but with the center moved to the given position.
Declaration
public Rectangle WithCenter(Coord center)
Parameters
Type | Name | Description |
---|---|---|
Coord | center | The center-point for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that is the same size as the current one, but with the center moved to the given location. |
WithCenter(Int32, Int32)
Creates and returns a new rectangle that is the same size as the current one, but with the center moved to the given position.
Declaration
public Rectangle WithCenter(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X-value for the center-point of the new rectangle. |
System.Int32 | y | Y-value for the center-point of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that is the same size as the current one, but with the center moved to the given location. |
WithExtents(Coord, Coord)
Creates a rectangle with the given minimum and maximum extents. Effectively a constructor, but with extra overloads not possible to provide in constructors alone.
Declaration
public static Rectangle WithExtents(Coord minExtent, Coord maxExtent)
Parameters
Type | Name | Description |
---|---|---|
Coord | minExtent | Minimum (x, y) coordinates that are inside the rectangle. |
Coord | maxExtent | Maximum (x, y) coordinates that are inside the rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new Rectangle with the given minimum and maximum extents. |
WithExtents(Int32, Int32, Int32, Int32)
Creates a rectangle with the given minimum and maximum extents. Effectively a constructor, but with extra overloads not possible to provide in constructors alone.
Declaration
public static Rectangle WithExtents(int minX, int minY, int maxX, int maxY)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | minX | Minimum x coordinate that is inside the rectangle. |
System.Int32 | minY | Minimum y coordinate that is inside the rectangle. |
System.Int32 | maxX | Maximum x coordinate that is inside the rectangle. |
System.Int32 | maxY | Maximum y coordinate that is inside the rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new Rectangle with the given minimum and maximum extents. |
WithHeight(Int32)
Creates and returns a new rectangle that has the same position and width as the current one, but with the height changed to the given value.
Declaration
public Rectangle WithHeight(int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | height | The height for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with its height changed to the given value. |
WithMaxExtent(Coord)
Creates and returns a new rectangle that has been shrunk/expanded as necessary, such that the maximum extent is the specified value.
Declaration
public Rectangle WithMaxExtent(Coord maxExtent)
Parameters
Type | Name | Description |
---|---|---|
Coord | maxExtent | The maximum extent of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that has its maximum extent adjusted to the specified value. |
WithMaxExtent(Int32, Int32)
Creates and returns a new rectangle that has been shrunk/expanded as necessary, such that the maximum extent is the specified value.
Declaration
public Rectangle WithMaxExtent(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The x-value for the minimum extent of the new rectangle. |
System.Int32 | y | The y-value for the minimum extent of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that has its maximum extent adjusted to the specified value. |
WithMaxExtentX(Int32)
Creates and returns a new rectangle that has been shrunk/expanded as necessary, such that the x-value of maximum extent is changed to the specified value.
Declaration
public Rectangle WithMaxExtentX(int x)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The x-coordinate for the maximum extent of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, with its MaxExtentX adjusted to the specified value. |
WithMaxExtentY(Int32)
Creates and returns a new rectangle that has been shrunk/expanded as necessary, such that the y-value of maximum extent is changed to the specified value.
Declaration
public Rectangle WithMaxExtentY(int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | y | The y-coordinate for the maximum extent of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, with its MaxExtentY adjusted to the specified value. |
WithMinExtent(Coord)
Creates and returns a new rectangle that has been shrunk/expanded as necessary, such that the minimum extent is the specified value.
Declaration
public Rectangle WithMinExtent(Coord minExtent)
Parameters
Type | Name | Description |
---|---|---|
Coord | minExtent | The minimum extent of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that has its minimum extent adjusted to the specified value. |
WithMinExtent(Int32, Int32)
Creates and returns a new rectangle that has been shrunk/expanded as necessary, such that the minimum extent is the specified value.
Declaration
public Rectangle WithMinExtent(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The x-value for the minimum extent of the new rectangle. |
System.Int32 | y | The y-value for the minimum extent of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that has its minimum extent adjusted to the specified value. |
WithMinExtentX(Int32)
Creates and returns a new rectangle that has been shrunk/expanded as necessary, such that the x-value of minimum extent is changed to the specified value.
Declaration
public Rectangle WithMinExtentX(int x)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The x-coordinate for the minimum extent of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, with its MinExtentX adjusted to the specified value. |
WithMinExtentY(Int32)
Creates and returns a new rectangle that has been shrunk/expanded as necessary, such that the y-value of minimum extent is changed to the specified value.
Declaration
public Rectangle WithMinExtentY(int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | y | The y-coordinate for the minimum extent of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, with its MinExtentY adjusted to the specified value. |
WithPosition(Coord)
Creates and returns a new rectangle that has its Position moved to the given position.
Declaration
public Rectangle WithPosition(Coord position)
Parameters
Type | Name | Description |
---|---|---|
Coord | position | The position for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that has its position changed to the given value. |
WithPosition(Int32, Int32)
Creates and returns a new rectangle that has its position moved to the given position.
Declaration
public Rectangle WithPosition(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X-value for the position of the new rectangle. |
System.Int32 | y | Y-value for the position of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with the position changed to the given value. |
WithPositionAndSize(Int32, Int32, Int32, Int32)
Creates a rectangle with the given position and size. Effectively a constructor, but with extra overloads not possible to provide in constructors alone.
Declaration
public static Rectangle WithPositionAndSize(int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | Minimum x coordinate that is inside the rectangle. |
System.Int32 | y | Minimum y coordinate that is inside the rectangle. |
System.Int32 | width | Width of the rectangle. |
System.Int32 | height | Height of the rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle at the given position with the given width and height. |
WithPostionAndSize(Coord, Coord)
Creates a rectangle with the given position and size. Effectively a constructor, but with extra overloads not possible to provide in constructors alone.
Declaration
public static Rectangle WithPostionAndSize(Coord position, Coord size)
Parameters
Type | Name | Description |
---|---|---|
Coord | position | Minimum (x, y) values that are inside the resulting rectangle. |
Coord | size | The size of the rectangle, in form (width, height). |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle at the given position with the given size. |
WithRadius(Coord, Int32, Int32)
Creates a rectangle centered on the given position, with the given horizontal and vertical radius values. Effectively a constructor, but with extra overloads not possible to provide in constructors alone.
Declaration
public static Rectangle WithRadius(Coord center, int horizontalRadius, int verticalRadius)
Parameters
Type | Name | Description |
---|---|---|
Coord | center | Center of the rectangle. |
System.Int32 | horizontalRadius | Number of units to the left and right of the center point that are included within the rectangle. |
System.Int32 | verticalRadius | Number of units to the top and bottom of the center point that are included within the rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with the given center point and radius values. |
WithRadius(Int32, Int32, Int32, Int32)
Creates a rectangle centered on the given position, with the given horizontal and vertical radius values. Effectively a constructor, but with extra overloads not possible to provide in constructors alone.
Declaration
public static Rectangle WithRadius(int centerX, int centerY, int horizontalRadius, int verticalRadius)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | centerX | X-value of the center of the rectangle. |
System.Int32 | centerY | Y-value of the center of the rectangle. |
System.Int32 | horizontalRadius | Number of units to the left and right of the center point that are included within the rectangle. |
System.Int32 | verticalRadius | Number of units to the top and bottom of the center point that are included within the rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with the given center point and radius values. |
WithSize(Coord)
Creates and returns a new rectangle whose position is the same as the current one, but has the specified width and height.
Declaration
public Rectangle WithSize(Coord size)
Parameters
Type | Name | Description |
---|---|---|
Coord | size | Vector (width, height) specifying the width/height of the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with the given width and height. |
WithSize(Int32, Int32)
Creates and returns a new rectangle whose position is the same as the current one, but has the specified width and height.
Declaration
public Rectangle WithSize(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width for the new rectangle. |
System.Int32 | height | The height for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with the given width and height. |
WithWidth(Int32)
Creates and returns a new rectangle that is exactly the same as the current one, but with the width changed to the given value.
Declaration
public Rectangle WithWidth(int width)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with its Width changed to the given value. |
WithX(Int32)
Creates and returns a new rectangle that has its X value moved to the given x-coordinate.
Declaration
public Rectangle WithX(int x)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The X value for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with X changed to the given value. |
WithY(Int32)
Creates and returns a new rectangle that has its Y value moved to the given y-coordinate.
Declaration
public Rectangle WithY(int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | y | The Y value for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with Y changed to the given value. |
Operators
| Improve this Doc View SourceEquality(Rectangle, Rectangle)
Returns whether or not the rectangles have the same position and extents.
Declaration
public static bool operator ==(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | true if the area of the two rectangles encompass the exact same area, false otherwise. |
Equality(Rectangle, Rectangle)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
Microsoft.Xna.Framework.Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two rectangles are equal, false if not. |
Equality(Rectangle, Rectangle)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
System.Drawing.Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two rectangles are equal, false if not. |
Equality(Rectangle, RectangleF)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(Rectangle r1, RectangleF r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
System.Drawing.RectangleF | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two rectangles are equal, false if not. |
Equality(Rectangle, (Int32 x, Int32 y, Int32 width, Int32 height))
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(Rectangle r1, (int x, int y, int width, int height) r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
System.ValueTuple<System.Int32, System.Int32, System.Int32, System.Int32> | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two rectangles are equal, false if not. |
Equality(Rectangle, Rectangle)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Xna.Framework.Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two rectangles are equal, false if not. |
Equality(Rectangle, Rectangle)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two rectangles are equal, false if not. |
Equality(RectangleF, Rectangle)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(RectangleF r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.RectangleF | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two rectangles are equal, false if not. |
Equality((Int32 x, Int32 y, Int32 width, Int32 height), Rectangle)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==((int x, int y, int width, int height) r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
System.ValueTuple<System.Int32, System.Int32, System.Int32, System.Int32> | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if the two rectangles are equal, false if not. |
Implicit(Rectangle to Rectangle)
Implicitly converts a GoRogue Rectangle to an equivalent MonoGame Rectangle.
Declaration
public static implicit operator Rectangle(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect |
Returns
Type | Description |
---|---|
Microsoft.Xna.Framework.Rectangle |
Implicit(Rectangle to Rectangle)
Implicitly converts a GoRogue Rectangle to an equivalent System.Drawing.Rectangle.
Declaration
public static implicit operator Rectangle(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect |
Returns
Type | Description |
---|---|
System.Drawing.Rectangle |
Implicit(Rectangle to RectangleF)
Implicitly converts a GoRogue Rectangle to an equivalent System.Drawing.RectangleF.
Declaration
public static implicit operator RectangleF(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect |
Returns
Type | Description |
---|---|
System.Drawing.RectangleF |
Implicit(Rectangle to (Int32 x, Int32 y, Int32 width, Int32 height))
Implicitly converts a GoRogue Rectangle to an equivalent tuple of 4 integers (x, y, width, height).
Declaration
public static implicit operator (int x, int y, int width, int height)(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Int32, System.Int32, System.Int32, System.Int32> |
Implicit(Rectangle to Rectangle)
Implicitly converts a MonoGame Rectangle to an equivalent GoRogue Rectangle.
Declaration
public static implicit operator Rectangle(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Xna.Framework.Rectangle | rect |
Returns
Type | Description |
---|---|
Rectangle |
Implicit(Rectangle to Rectangle)
Implicitly converts a System.Drawing.Rectangle to an equivalent GoRogue Rectangle.
Declaration
public static implicit operator Rectangle(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Rectangle | rect |
Returns
Type | Description |
---|---|
Rectangle |
Implicit((Int32 x, Int32 y, Int32 width, Int32 height) to Rectangle)
Implicitly converts a tuple of 4 integers (x, y, width, height) to an equivalent GoRogue Rectangle.
Declaration
public static implicit operator Rectangle((int x, int y, int width, int height) tuple)
Parameters
Type | Name | Description |
---|---|---|
System.ValueTuple<System.Int32, System.Int32, System.Int32, System.Int32> | tuple |
Returns
Type | Description |
---|---|
Rectangle |
Inequality(Rectangle, Rectangle)
Returns whether or not the rectangles differ in either their positions or extents.
Declaration
public static bool operator !=(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | true if the rectangles do NOT encompass the same area, false otherwise. |
Inequality(Rectangle, Rectangle)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
Microsoft.Xna.Framework.Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality(Rectangle, Rectangle)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
System.Drawing.Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality(Rectangle, RectangleF)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(Rectangle r1, RectangleF r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
System.Drawing.RectangleF | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality(Rectangle, (Int32 x, Int32 y, Int32 width, Int32 height))
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(Rectangle r1, (int x, int y, int width, int height) r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
System.ValueTuple<System.Int32, System.Int32, System.Int32, System.Int32> | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality(Rectangle, Rectangle)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Xna.Framework.Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality(Rectangle, Rectangle)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality(RectangleF, Rectangle)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(RectangleF r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.RectangleF | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality((Int32 x, Int32 y, Int32 width, Int32 height), Rectangle)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=((int x, int y, int width, int height) r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
System.ValueTuple<System.Int32, System.Int32, System.Int32, System.Int32> | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |