Class Quadrilateral
Represents a quadrilateral (four-corner polygon) defined by four points. Immutable: all operations return new instances. Suitable for rotated rectangles, skewed boxes, or arbitrary four-cornered regions such as OCR bounding boxes. Provides geometric operations, transformations, and access to an axis-aligned bounding box (AABB).
public sealed class Quadrilateral : IBounds, ISize, IEquatable<Quadrilateral>
- Inheritance
-
Quadrilateral
- Implements
- Inherited Members
Constructors
- Quadrilateral(Point, Point, Point, Point)
Initializes a new instance of the Quadrilateral class from four corner points. The inputs may be in any order; corners are normalized to (TopLeft, TopRight, BottomRight, BottomLeft), clockwise.
Fields
- Empty
An empty quadrilateral positioned at the origin (0,0) with zero width and height.
Properties
- Area
Gets the area of the quadrilateral, computed via the shoelace formula.
- AxisAlignedBounds
Gets a Rectangle representing the axis-aligned bounding box (AABB) of this quadrilateral.
- Bottom
Gets the largest Y-coordinate of the quadrilateral (bottom edge of the AABB). Computed lazily and cached.
- BottomLeft
Gets the bottom-left corner of the quadrilateral.
- BottomRight
Gets the bottom-right corner of the quadrilateral.
- Centroid
Gets the polygon centroid (geometric center) computed via the shoelace formula. If the area is approximately zero, falls back to the average of the four corners.
- Height
Gets the height of the axis-aligned bounding box (AABB) surrounding this quadrilateral. Computed lazily from Top and Bottom and cached.
- Left
Gets the smallest X-coordinate of the quadrilateral (left edge of the AABB). Computed lazily and cached.
- MidX
Gets the horizontal midpoint of the quadrilateral's axis-aligned bounds.
- MidY
Gets the vertical midpoint of the quadrilateral's axis-aligned bounds.
- Right
Gets the largest X-coordinate of the quadrilateral (right edge of the AABB). Computed lazily and cached.
- Top
Gets the smallest Y-coordinate of the quadrilateral (top edge of the AABB). Computed lazily and cached.
- TopLeft
Gets the top-left corner of the quadrilateral.
- TopRight
Gets the top-right corner of the quadrilateral.
- Width
Gets the width of the axis-aligned bounding box (AABB) surrounding this quadrilateral. Computed lazily from Left and Right and cached.
Methods
- Contains(double, double)
Determines whether the specified point lies inside (or on the edges of) the quadrilateral.
- Deconstruct(out Point, out Point, out Point, out Point)
Deconstructs the quadrilateral into corner points (TopLeft, TopRight, BottomRight, BottomLeft). Enables tuple-style deconstruction:
var (tl, tr, br, bl) = quad;
- Equals(Quadrilateral)
Determines whether another quadrilateral has identical corner coordinates.
- Equals(object)
Determines whether the specified object is equal to the current quadrilateral.
- FromBounds(IBounds)
Creates a quadrilateral from an axis-aligned IBounds.
- FromBounds(IBounds, double, Point)
Creates a quadrilateral by rotating axis-aligned bounds about a given pivot point.
- FromCenterSizeAngle(double, double, double, double, double)
Creates a quadrilateral by specifying its center, size, and rotation angle.
- FromRectangle(Rectangle)
Creates a quadrilateral from a Rectangle.
- FromRectangle(Rectangle, double, Point)
Creates a quadrilateral by rotating a Rectangle about a given pivot point.
- FromRectangle(double, double, double, double)
Creates a quadrilateral from rectangle parameters (left, top, width, height).
- FromRectangle(double, double, double, double, double, Point)
Creates a quadrilateral from rectangle parameters and rotates it around a specified pivot point.
- GetHashCode()
Returns a hash code for this quadrilateral based on its four corners.
- Normalize()
Returns a new quadrilateral with corners normalized to (TopLeft, TopRight, BottomRight, BottomLeft), clockwise.
- Rotate(double, Point)
Returns a new quadrilateral rotated around a specified pivot point.
- RotateAroundCenter(double)
Returns a new quadrilateral rotated around its polygon centroid.
- Scale(double, double)
Returns a new quadrilateral scaled by the specified factors relative to the origin (0,0).
- ToString()
Returns a string representation of the quadrilateral and its axis-aligned bounding box (AABB).
- Translate(Point)
Returns a new quadrilateral translated by a vector Point.
- Translate(double, double)
Returns a new quadrilateral translated (moved) by the specified offsets.
- Union(IBounds)
Returns the smallest axis-aligned quadrilateral that contains this quadrilateral and
other
. This is the union of their axis-aligned bounding boxes (AABB).
- Union(Quadrilateral)
Returns the AABB union of this quadrilateral and another quadrilateral, as a new axis-aligned quadrilateral.
- Union(Quadrilateral, Quadrilateral)
Returns the AABB union of two quadrilaterals as an axis-aligned quadrilateral.
Operators
- operator +(Point, Quadrilateral)
Translates a quadrilateral by a point offset.
- operator +(Quadrilateral, Point)
Translates a quadrilateral by a point offset.
- operator /(Quadrilateral, double)
Uniformly scales a quadrilateral relative to the origin by dividing by a scalar.
- operator ==(Quadrilateral, Quadrilateral)
Determines whether two quadrilaterals have identical corner coordinates (after normalization).
- operator !=(Quadrilateral, Quadrilateral)
Determines whether two quadrilaterals differ in any corner coordinate.
- operator *(Quadrilateral, double)
Uniformly scales a quadrilateral relative to the origin.
- operator *(double, Quadrilateral)
Uniformly scales a quadrilateral relative to the origin.
- operator -(Quadrilateral, Point)
Translates a quadrilateral by the negation of a point offset.