Class Rectangle
Represents a 2D rectangle. Provides numerous static functions that enable creation and common operations involving rectangles.
Implements
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class Rectangle : ValueType, IEquatable<Rectangle>, IEquatable<(int, int, int, int)>, IMatchable<Rectangle>, IMatchable<(int, int, int, int)>, IEquatable<(Point, Point)>, IMatchable<(Point, Point)>
Constructors
Rectangle(Point, Point)
Constructor.
Declaration
public Rectangle(Point minExtent, Point maxExtent)
Parameters
Type | Name | Description |
---|---|---|
Point | minExtent | Minimum x and y values that are considered inside the rectangle. |
Point | maxExtent | Maximum x and y values that are considered inside the rectangle. |
Rectangle(Point, Int32, Int32)
Constructor.
Declaration
public Rectangle(Point center, int horizontalRadius, int verticalRadius)
Parameters
Type | Name | Description |
---|---|---|
Point | center | The center point of the rectangle. |
Int32 | horizontalRadius | Number of units to the left and right of the center point that are included within the rectangle. |
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 |
---|---|---|
Int32 | x | Minimum x coordinate that is inside the rectangle. |
Int32 | y | Minimum y coordinate that is inside the rectangle. |
Int32 | width | Width of the rectangle. |
Int32 | height | Height of the rectangle. |
Fields
Empty
The empty rectangle. Has origin of (0, 0) with 0 width and height.
Declaration
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 |
---|---|
Int32 |
Width
The width of the rectangle.
Declaration
public readonly int Width
Field Value
Type | Description |
---|---|
Int32 |
X
X-coordinate of position of the rectangle.
Declaration
public readonly int X
Field Value
Type | Description |
---|---|
Int32 |
Y
Y-coordinate of position of the rectangle.
Declaration
public readonly int Y
Field Value
Type | Description |
---|---|
Int32 |
Properties
Area
Calculates the area of the rectangle.
Declaration
public int Area { get; }
Property Value
Type | Description |
---|---|
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 Point Center { get; }
Property Value
Type | Description |
---|---|
Point |
IsEmpty
Whether or not this rectangle contains no locations (eg. has width or height of 0).
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
Boolean |
MaxExtent
The maximum X and Y coordinates that are included in the rectangle.
Declaration
public Point MaxExtent { get; }
Property Value
Type | Description |
---|---|
Point |
MaxExtentX
The maximum X-coordinate that is included in the rectangle.
Declaration
public int MaxExtentX { get; }
Property Value
Type | Description |
---|---|
Int32 |
MaxExtentY
The maximum Y-coordinate that is included in the rectangle.
Declaration
public int MaxExtentY { get; }
Property Value
Type | Description |
---|---|
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 Point MinExtent { get; }
Property Value
Type | Description |
---|---|
Point |
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 |
---|---|
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 |
---|---|
Int32 |
Position
Coord representing the position (min x- and y-values) of the rectangle.
Declaration
public Point Position { get; }
Property Value
Type | Description |
---|---|
Point |
Size
Returns a coordinate (Width, Height), which represents the size of the rectangle.
Declaration
public Point Size { get; }
Property Value
Type | Description |
---|---|
Point |
Methods
Bisect()
Bisects the rectangle into two halves along its longest axis.
Declaration
public BisectionResult Bisect()
Returns
Type | Description |
---|---|
BisectionResult | A BisectionResult of either Top and Bottom halves, or Left and Right halves. |
Remarks
Cuts the rectangle by reducing it's longest dimension by half. For example, a rectangle that extends from (3, 3) to (18, 7) that calls DivideInHalf will return an IEnumerable with two rectangles. The rectangle at index 0 starts at (3, 3) and extends to (9, 7), and the rectangle at index 1 extends from (10, 3) to (18, 7)
BisectHorizontally()
Bisects the rectangle into top and bottom halves.
Declaration
public BisectionResult BisectHorizontally()
Returns
Type | Description |
---|---|
BisectionResult | A BisectionResult with Top and Bottom Rectangles. |
BisectRecursive(Int32)
Recursively divides this rectangle in half until the small rectangles are between minimumDimension and 2 * minimumDimension.
Declaration
public IEnumerable<Rectangle> BisectRecursive(int minimumDimension)
Parameters
Type | Name | Description |
---|---|---|
Int32 | minimumDimension | The smallest allowable dimension for a rectangle to be. |
Returns
Type | Description |
---|---|
IEnumerable<Rectangle> | A list of all rectangles that add up to the original rectangle |
BisectVertically()
Divides the rectangle into a left and right half.
Declaration
public BisectionResult BisectVertically()
Returns
Type | Description |
---|---|
BisectionResult | A BisectionResult with the Left and Right rectangles. |
ChangeHeight(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 |
---|---|---|
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. |
ChangePosition(Direction)
Creates and returns a new rectangle that has its position moved in the given direction.
Declaration
public Rectangle ChangePosition(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. |
ChangePosition(Point)
Creates and returns a new rectangle whose position has been moved by the given delta-change values.
Declaration
public Rectangle ChangePosition(Point deltaChange)
Parameters
Type | Name | Description |
---|---|---|
Point | 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. |
ChangeSize(Point)
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(Point deltaChange)
Parameters
Type | Name | Description |
---|---|---|
Point | 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. |
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 |
---|---|---|
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. |
ChangeX(Int32)
Creates and returns a new rectangle whose x-position has been moved by the given delta value.
Declaration
public Rectangle ChangeX(int dx)
Parameters
Type | Name | Description |
---|---|---|
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. |
ChangeY(Int32)
Creates and returns a new rectangle whose y-position has been moved by the given delta value.
Declaration
public Rectangle ChangeY(int dy)
Parameters
Type | Name | Description |
---|---|---|
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. |
Contains(Point)
Returns whether or not the specified point is considered within the rectangle.
Declaration
public bool Contains(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to check. |
Returns
Type | Description |
---|---|
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 |
---|---|
Boolean | True if the given rectangle is completely contained within the current one, false otherwise. |
Deconstruct(out Point, out Point)
Adds support for C# Deconstruction syntax.
Declaration
public void Deconstruct(out Point minExtent, out Point maxExtent)
Parameters
Type | Name | Description |
---|---|---|
Point | minExtent | |
Point | maxExtent |
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 |
---|---|---|
Int32 | x | |
Int32 | y | |
Int32 | width | |
Int32 | height |
Divide(Rectangle)
Divides this rectangle by another, and returns an IEnumerable of divisor-sized rectangles that fit within the dividend.
Declaration
public IEnumerable<Rectangle> Divide(Rectangle divisor)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | divisor | The rectangle by which to divide |
Returns
Type | Description |
---|---|
IEnumerable<Rectangle> | IEnumerable of Rectangles the size of divisor, that fit within this rectangle. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the width or height of the divisor is 0 or less |
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 |
---|---|
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 |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Boolean | true if the object specified is a rectangle instance and encompasses the same area, false otherwise. |
Equals((Point, Point))
True if the given position has equal x and y values to the current one.
Declaration
public bool Equals((Point, Point) other)
Parameters
Type | Name | Description |
---|---|---|
(, )<Point, Point> | other | Point to compare. |
Returns
Type | Description |
---|---|
Boolean | True if the two positions are equal, false if not. |
Equals((Int32, Int32, Int32, Int32))
True if the given position has equal x and y values to the current one.
Declaration
public bool Equals((int, int, int, int) other)
Parameters
Type | Name | Description |
---|---|---|
(, , , )<Int32, Int32, Int32, Int32> | other | Point to compare. |
Returns
Type | Description |
---|---|
Boolean | True if the two positions are equal, false if not. |
Expand(Int32, Int32)
Returns a new rectangle, expanded on each side by the given amounts. Negative change values can be used to shrink the rectangle on each side.
Declaration
public Rectangle Expand(int horizontalChange, int verticalChange)
Parameters
Type | Name | Description |
---|---|---|
Int32 | horizontalChange | Number of additional columns to include on the left and right of the rectangle. |
Int32 | verticalChange | Number of additional rows to include on the top and bottom of the rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle, expanded appropriately. |
GetDifference(Rectangle, Rectangle)
Gets an Area representing every location in rect1
that
is NOT in rect2
.
Declaration
public static Area GetDifference(Rectangle rect1, Rectangle rect2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect1 | |
Rectangle | rect2 |
Returns
Type | Description |
---|---|
Area | A Area representing every location in |
GetExactUnion(Rectangle, Rectangle)
Gets a Area representing the exact union of the specified rectangles, eg. an area containing all locations from either rectangle.
Declaration
public static Area GetExactUnion(Rectangle r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
Area | A Area containing every position in either rectangle. |
GetHashCode()
Simple hashing.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | Hash code for rectangle. |
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 |
---|---|
Boolean | True if the given rectangle intersects with the current one, false otherwise. |
IsOnSide(Point, Direction)
Returns whether or not the given position lines on the given edge of the rectangle.
Declaration
public bool IsOnSide(Point point, Direction side)
Parameters
Type | Name | Description |
---|---|---|
Point | point | |
Direction | side |
Returns
Type | Description |
---|---|
Boolean | True if the given position lies along the given edge of the rectangle, false otherwise. |
Matches(Rectangle)
Compares based upon whether or not the areas contained within the rectangle are identical in both position and extents.
Declaration
public bool Matches(Rectangle other)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | other |
Returns
Type | Description |
---|---|
Boolean | true if the area of the two rectangles encompass the exact same area, false otherwise. |
Matches((Point, Point))
True if the given position has equal x and y values to the current one.
Declaration
public bool Matches((Point, Point) other)
Parameters
Type | Name | Description |
---|---|---|
(, )<Point, Point> | other | Point to compare. |
Returns
Type | Description |
---|---|
Boolean | True if the two positions are equal, false if not. |
Matches((Int32, Int32, Int32, Int32))
True if the given position has equal x and y values to the current one.
Declaration
public bool Matches((int, int, int, int) other)
Parameters
Type | Name | Description |
---|---|---|
(, , , )<Int32, Int32, Int32, Int32> | other | Point to compare. |
Returns
Type | Description |
---|---|
Boolean | True if the two positions are equal, false if not. |
MaxXPositions()
Gets all positions that reside on the max-x line of the rectangle.
Declaration
public IEnumerable<Point> MaxXPositions()
Returns
Type | Description |
---|---|
IEnumerable<Point> | 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<Point> MaxYPositions()
Returns
Type | Description |
---|---|
IEnumerable<Point> | 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<Point> MinXPositions()
Returns
Type | Description |
---|---|
IEnumerable<Point> | 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<Point> MinYPositions()
Returns
Type | Description |
---|---|
IEnumerable<Point> | 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 RectanglePerimeterPositionsEnumerator PerimeterPositions()
Returns
Type | Description |
---|---|
RectanglePerimeterPositionsEnumerator | IEnumerable of all positions that reside on the inner perimeter of the rectangle. |
Positions()
Returns all positions in the rectangle.
Declaration
public RectanglePositionsEnumerator Positions()
Returns
Type | Description |
---|---|
RectanglePositionsEnumerator | All positions in the rectangle. |
PositionsOnSide(Direction)
Gets an IEnumerable of all positions that line on the inner perimeter of the rectangle, on the given side of the rectangle.
Declaration
public IEnumerable<Point> PositionsOnSide(Direction side)
Parameters
Type | Name | Description |
---|---|---|
Direction | side | Side to get positions for. |
Returns
Type | Description |
---|---|
IEnumerable<Point> | IEnumerable of all positions that line on the inner perimeter of the rectangle on the given side. |
ToString()
Returns a string representing the rectangle, formatted as (X, Y) -> (MaxExtentX, MaxExtentY)
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | String formatted as above. |
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(Point)
Creates and returns a new rectangle whose position has been moved by the given delta-change values.
Declaration
public Rectangle Translate(Point deltaChange)
Parameters
Type | Name | Description |
---|---|---|
Point | 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. |
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 |
---|---|---|
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 |
---|---|---|
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(Point)
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(Point center)
Parameters
Type | Name | Description |
---|---|---|
Point | 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. |
WithExtents(Point, Point)
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(Point minExtent, Point maxExtent)
Parameters
Type | Name | Description |
---|---|---|
Point | minExtent | Minimum (x, y) coordinates that are inside the rectangle. |
Point | maxExtent | Maximum (x, y) coordinates that are 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 |
---|---|---|
Int32 | height | The height for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with its height changed to the given value. |
WithMaxExtent(Point)
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(Point maxExtent)
Parameters
Type | Name | Description |
---|---|---|
Point | 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. |
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 |
---|---|---|
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 |
---|---|---|
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(Point)
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(Point minExtent)
Parameters
Type | Name | Description |
---|---|---|
Point | 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. |
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 |
---|---|---|
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 |
---|---|---|
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(Point)
Creates and returns a new rectangle that has its Position moved to the given position.
Declaration
public Rectangle WithPosition(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle that has its position changed to the given value. |
WithPositionAndSize(Point, Point)
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(Point position, Point size)
Parameters
Type | Name | Description |
---|---|---|
Point | position | Minimum (x, y) values that are inside the resulting rectangle. |
Point | 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. |
WithPositionAndSize(Point, 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(Point position, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
Point | position | Minimum x/y coordinate that is inside the rectangle. |
Int32 | width | Width of the rectangle. |
Int32 | height | Height of the rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle at the given position with the given width and height. |
WithRadius(Point, 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(Point center, int horizontalRadius, int verticalRadius)
Parameters
Type | Name | Description |
---|---|---|
Point | center | Center of the rectangle. |
Int32 | horizontalRadius | Number of units to the left and right of the center point that are included within the rectangle. |
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(Point)
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(Point size)
Parameters
Type | Name | Description |
---|---|---|
Point | 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 |
---|---|---|
Int32 | width | The width for the new rectangle. |
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 |
---|---|---|
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 |
---|---|---|
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 |
---|---|---|
Int32 | y | The Y value for the new rectangle. |
Returns
Type | Description |
---|---|
Rectangle | A new rectangle with Y changed to the given value. |
Operators
Equality(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 |
---|---|
Boolean | true if the area of the two rectangles encompass the exact same area, false otherwise. |
Equality(Rectangle, (Point, Point))
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(Rectangle r1, (Point, Point) r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
(, )<Point, Point> | r2 |
Returns
Type | Description |
---|---|
Boolean | True if the two rectangles are equal, false if not. |
Equality(Rectangle, (Int32, Int32, Int32, Int32))
True if the two rectangles represent the same area.
Declaration
public static bool operator ==(Rectangle r1, (int, int, int, int) r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
(, , , )<Int32, Int32, Int32, Int32> | r2 |
Returns
Type | Description |
---|---|
Boolean | True if the two rectangles are equal, false if not. |
Equality((Point, Point), Rectangle)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==((Point, Point) r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
(, )<Point, Point> | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
Boolean | True if the two rectangles are equal, false if not. |
Equality((Int32, Int32, Int32, Int32), Rectangle)
True if the two rectangles represent the same area.
Declaration
public static bool operator ==((int, int, int, int) r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
(, , , )<Int32, Int32, Int32, Int32> | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
Boolean | True if the two rectangles are equal, false if not. |
Implicit(Rectangle to (Point, Point))
Implicitly converts a GoRogue Rectangle to an equivalent tuple of 2 Points (minExtent, maxExtent).
Declaration
public static implicit operator (Point, Point)(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect |
Returns
Type | Description |
---|---|
(, )<Point, Point> |
Implicit(Rectangle to (Int32, Int32, Int32, Int32))
Implicitly converts a GoRogue Rectangle to an equivalent tuple of 4 integers (x, y, width, height).
Declaration
public static implicit operator (int, int, int, int)(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect |
Returns
Type | Description |
---|---|
(, , , )<Int32, Int32, Int32, Int32> |
Implicit((Point, Point) to Rectangle)
Implicitly converts a tuple of 2 Points (minExtent, maxExtent) to an equivalent GoRogue Rectangle.
Declaration
public static implicit operator Rectangle((Point, Point) tuple)
Parameters
Type | Name | Description |
---|---|---|
(, )<Point, Point> | tuple |
Returns
Type | Description |
---|---|
Rectangle |
Implicit((Int32, Int32, Int32, Int32) 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, int, int, int) tuple)
Parameters
Type | Name | Description |
---|---|---|
(, , , )<Int32, Int32, Int32, 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 |
---|---|
Boolean | true if the rectangles do NOT encompass the same area, false otherwise. |
Inequality(Rectangle, (Point, Point))
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(Rectangle r1, (Point, Point) r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
(, )<Point, Point> | r2 |
Returns
Type | Description |
---|---|
Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality(Rectangle, (Int32, Int32, Int32, Int32))
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=(Rectangle r1, (int, int, int, int) r2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | r1 | |
(, , , )<Int32, Int32, Int32, Int32> | r2 |
Returns
Type | Description |
---|---|
Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality((Point, Point), Rectangle)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=((Point, Point) r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
(, )<Point, Point> | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |
Inequality((Int32, Int32, Int32, Int32), Rectangle)
True if any of the rectangles' x/y/width/height values are not equal.
Declaration
public static bool operator !=((int, int, int, int) r1, Rectangle r2)
Parameters
Type | Name | Description |
---|---|---|
(, , , )<Int32, Int32, Int32, Int32> | r1 | |
Rectangle | r2 |
Returns
Type | Description |
---|---|
Boolean | True if any of the x/y/width/height values are not equal, false if they are all equal. |