Struct BoundingRect
- Namespace
- CADability
- Assembly
- CADability.dll
BoundingRect is an axis oriented rectangle or a 2-dimensional bounding box. It is implemented as a "struct" (value type) so assignements always make a copy.
[JsonVersion(serializeAsStruct = true, version = 1)]
public struct BoundingRect : IQuadTreeInsertable, IComparable<BoundingRect>, ISerializable, IEquatable<BoundingRect>, IJsonSerialize
- Implements
- Inherited Members
Constructors
BoundingRect(BoundingRect)
Copy constructor
public BoundingRect(BoundingRect r)
Parameters
BoundingRect(GeoPoint2D, double, double)
Creates a new BoundingRect with the provided center, half width and half height
public BoundingRect(GeoPoint2D Center, double HalfWidth, double HalfHeight)
Parameters
CenterGeoPoint2DCenter of the BoundingRect
HalfWidthdoubleHalf width
HalfHeightdoubleHalf height
BoundingRect(params GeoPoint2D[])
Creates a new BoundingRect which contains the provided points
public BoundingRect(params GeoPoint2D[] p)
Parameters
pGeoPoint2D[]List of points to define the rectangle
BoundingRect(double, double, double, double)
Creates a new BoundingRect with the provided limits.
public BoundingRect(double Left, double Bottom, double Right, double Top)
Parameters
BoundingRect(Rectangle)
Creates a new BoundingRect from the provided System.Drawing.rectangle
public BoundingRect(Rectangle r)
Parameters
rRectangledas gegebene Rechteck
Fields
Bottom
The lower limit (minimum y). It is MaxValue for the EmptyBoundingRect.
public double Bottom
Field Value
EmptyBoundingRect
Returns an empty BoundingRect which is convenient as a start for the MinMax(GeoPoint2D) method.
public static BoundingRect EmptyBoundingRect
Field Value
HalfInfinitBoundingRect
A rectangle that practically contains everything but, unlike InfinitBoundingRect, has finite Width and Height: its limits are half of MinValue and MaxValue. Use it where an unrestricted domain takes part in computations.
public static BoundingRect HalfInfinitBoundingRect
Field Value
InfinitBoundingRect
A rectangle that contains everything: its limits are MinValue and MaxValue. Width and Height overflow to infinity, so use it only as a "no restriction" marker, not in computations (see HalfInfinitBoundingRect).
public static BoundingRect InfinitBoundingRect
Field Value
Left
The left limit (minimum x). It is MaxValue for the EmptyBoundingRect.
public double Left
Field Value
Right
The right limit (maximum x). It is MinValue for the EmptyBoundingRect.
public double Right
Field Value
Top
The upper limit (maximum y). It is MinValue for the EmptyBoundingRect.
public double Top
Field Value
Properties
Height
The height of the rectangle, i.e. Top minus Bottom. It is negative for the EmptyBoundingRect.
public double Height { get; }
Property Value
- double
The height of the rectangle
IsInfinite
Returns true if the BoundingRect is infinite. I.e. left and bottom equal Double.MinValue and right and top equal Double.MaxValue
public bool IsInfinite { get; }
Property Value
Size
A measure of the size of the rectangle: the sum of the absolute values of Width and Height. Mostly used to derive precision values relative to the size of the rectangle.
public double Size { get; }
Property Value
UnitBoundingRect
Returns an BoundingRect form 0 to 1 in both directions
public static BoundingRect UnitBoundingRect { get; }
Property Value
Width
The width of the rectangle, i.e. Right minus Left. It is negative for the EmptyBoundingRect.
public double Width { get; }
Property Value
- double
The width of the rectangle
Methods
ClipLine(GeoPoint2D, GeoVector2D, out GeoPoint2D, out GeoPoint2D)
Clips the infinite line, which is defined by location and
direction, to this rectangle and returns the two points where it enters and
leaves. If the line only touches a corner, both points are identical.
public bool ClipLine(GeoPoint2D location, GeoVector2D direction, out GeoPoint2D startPoint, out GeoPoint2D endPoint)
Parameters
locationGeoPoint2Da point on the line
directionGeoVector2Dthe direction of the line, must not be a null vector
startPointGeoPoint2Dthe point where the line enters this rectangle
endPointGeoPoint2Dthe point where the line leaves this rectangle
Returns
- bool
true, if the line intersects this rectangle
ClipLine(GeoPoint2D, GeoVector2D, out double, out double)
Clips the infinite line, which is defined by location and
direction, to this rectangle. The line is the set of points
location + t*direction, t being any real number. Returns the parameters t of the two points
where the line enters and leaves this rectangle.
public bool ClipLine(GeoPoint2D location, GeoVector2D direction, out double startParameter, out double endParameter)
Parameters
locationGeoPoint2Da point on the line
directionGeoVector2Dthe direction of the line, must not be a null vector
startParameterdoubleparameter where the line enters this rectangle
endParameterdoubleparameter where the line leaves this rectangle
Returns
- bool
true, if the line intersects this rectangle
ContainsEps(GeoPoint2D, double)
Checks whether the point is inside this rectangle enlarged by a tolerance. A positive eps is
an absolute distance by which all four limits are moved outward; a negative eps is taken as a
fraction of the width and height (e.g. -0.01 enlarges the rectangle by 1% of its width to the left and right
and by 1% of its height to the bottom and top).
public bool ContainsEps(GeoPoint2D uv, double eps)
Parameters
uvGeoPoint2Dthe point to test
epsdoubletolerance: absolute when positive, relative to the size of the rectangle when negative
Returns
- bool
true, if the point is inside the enlarged rectangle (limits included)
ContainsLb(GeoPoint2D)
Checks whether the point is inside this rectangle, where the left and bottom limits count as inside and the right and top limits as outside (half open intervals). With this convention a point in a grid of adjacent rectangles belongs to exactly one of them.
public bool ContainsLb(GeoPoint2D p)
Parameters
pGeoPoint2Dthe point to test
Returns
- bool
true, if Left <= p.x < Right and Bottom <= p.y < Top
Disjoint(BoundingRect, BoundingRect)
Returns true if the two rectangles are disjoint (do not overlap)
public static bool Disjoint(BoundingRect b1, BoundingRect b2)
Parameters
b1BoundingRectFirst rectangle
b2BoundingRectSecond rectangle
Returns
- bool
true if disjoint
Equals(BoundingRect)
Implements Equals(T): true, if both rectangles have exactly the same limits.
public bool Equals(BoundingRect other)
Parameters
otherBoundingRectthe rectangle to compare with
Returns
- bool
true, if equal
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
GetCenter()
Returns the center of the rectangle
public GeoPoint2D GetCenter()
Returns
GetHashCode()
public override int GetHashCode()
Returns
GetLowerLeft()
Returns the lower left point of the rectangle
public GeoPoint2D GetLowerLeft()
Returns
GetLowerMiddle()
Returns the center of the bottom line of the rectangle
public GeoPoint2D GetLowerMiddle()
Returns
GetLowerRight()
Returns the lower right point of the rectangle
public GeoPoint2D GetLowerRight()
Returns
GetMiddleLeft()
Returns the center of the left line of the rectangle
public GeoPoint2D GetMiddleLeft()
Returns
GetMiddleRight()
Returns the center of the right line of the rectangle
public GeoPoint2D GetMiddleRight()
Returns
GetObjectData(IJsonWriteData)
Implements GetObjectData(IJsonWriteData): writes the four limits as a list of values in the order left, bottom, right, top.
public void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDatareceives the values
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
GetPosition(GeoPoint2D, double)
Returns the position of the provided point with a given precision
public BoundingRect.Position GetPosition(GeoPoint2D p, double frameWidth)
Parameters
pGeoPoint2DThe point to test
frameWidthdoubleThe precision: if the distance to a bounding line is smaller than this value, the point is considered as onframe
Returns
- BoundingRect.Position
The position of the point
GetUpperLeft()
Returns the upper left point of the rectangle
public GeoPoint2D GetUpperLeft()
Returns
GetUpperMiddle()
Returns the center of the upper line of the rectangle
public GeoPoint2D GetUpperMiddle()
Returns
GetUpperRight()
Returns the upper right point of the rectangle
public GeoPoint2D GetUpperRight()
Returns
Inflate(double)
Inflates the rectangle by the provided value which may also be negative (for shrinking)
public void Inflate(double d)
Parameters
ddoubleValue for infaltion
Inflate(double, double)
Inflates the rectangle with different values in width an height
public void Inflate(double width, double height)
Parameters
InflateRelative(double)
Inflates the rectangle by a factor relative to its Size, which is the sum of width and height. All four sides are moved out by the same amount, so the shorter axis is enlarged much more than the longer one: a 1 x 0.001 rectangle inflated by 1.01 keeps its width but becomes twenty times as high.
[Obsolete("Ambiguous name. Use InflateRelativeToSize for exactly this behaviour, or InflateRelativeToWidthHeight to grow each axis in proportion to itself.")]
public void InflateRelative(double factor)
Parameters
factordoublethe relative amount to grow by, 1.0 leaves the rectangle unchanged
InflateRelativeToSize(double)
Inflates the rectangle by a factor relative to its Size, which is the sum of width and height. All four sides are moved out by the same amount.
NOTE: the amount is applied to BOTH sides of an axis, so the extent grows by twice it - a square inflated by 1.01 comes out 1.04 times as wide, not 1.01.
public void InflateRelativeToSize(double factor)
Parameters
factordoublethe relative amount to grow by, 1.0 leaves the rectangle unchanged
InflateRelativeToWidthHeight(double)
Inflates the rectangle by a factor, each axis in proportion to its own extent: the horizontal sides move out by a multiple of Width, the vertical ones by a multiple of Height. Unlike InflateRelativeToSize(double) the shape of the rectangle is preserved, which is what a rectangle in a parameter space usually needs - there width and height measure unrelated quantities and are routinely orders of magnitude apart.
NOTE: the amount is applied to BOTH sides of an axis, so the extent grows by twice it - a rectangle inflated by 1.01 comes out 1.02 times as wide, not 1.01. This matches InflateRelativeToSize(double) and the same method in the ShapeIt fork.
public void InflateRelativeToWidthHeight(double factor)
Parameters
factordoublethe relative amount to grow by, 1.0 leaves the rectangle unchanged
Interferes(ref BoundingRect)
Returns true, when this rectangle and the provided rect overlap
public bool Interferes(ref BoundingRect rect)
Parameters
rectBoundingRect
Returns
IsEmpty()
Returns true, if this BoundingRect is empty.
public bool IsEmpty()
Returns
- bool
true, if empty.
MakeEmpty()
Makes this BoundingRect an empty BoundingRect
public void MakeEmpty()
MinMax(BoundingRect)
Adapts the size of this bounding rectangle to include the provided rectangle.
public void MinMax(BoundingRect r)
Parameters
rBoundingRectRectangle to be included
MinMax(GeoPoint2D)
Adapts the size of this bounding rectangle to include the provided point.
public void MinMax(GeoPoint2D p)
Parameters
pGeoPoint2DPoint to be included
MinMax(params GeoPoint2D[])
Adapts the size of this bounding rectangle to include the provided points.
public void MinMax(params GeoPoint2D[] p)
Parameters
pGeoPoint2D[]Points to be included
MinMaxHeight(double)
Adapts the size of this bounding rectangle to include the provided y value, leaving the horizontal extent untouched. Also works fine with an empty rectangle.
public void MinMaxHeight(double y)
Parameters
ydoubley value to be included
MinMaxWidth(double)
Adapts the size of this bounding rectangle to include the provided x value, leaving the vertical extent untouched. Also works fine with an empty rectangle.
public void MinMaxWidth(double x)
Parameters
xdoublex value to be included
Modify(ModOp2D)
Modifies the rectangle by the provided ModOp2D. The resulting rectangle contains the modified vertices of this rectangle
public void Modify(ModOp2D m)
Parameters
mModOp2DModification to use
Move(GeoVector2D)
Moves the rectangle by the provided offset
public void Move(GeoVector2D offset)
Parameters
offsetGeoVector2DOffset to move
SetObjectData(IJsonReadData)
Implements SetObjectData(IJsonReadData). Does nothing, because a BoundingRect is serialized as a struct and read back by a constructor taking the stored values.
public void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDatanot used
ToBorder()
Returns a Border that consists of the four lines of this ractangle.
public Border ToBorder()
Returns
- Border
The border
ToRectangleF()
Converts this rectangle to a GDI+ RectangleF with (Left, Bottom) as its location and Width and Height as its size, in single precision.
public RectangleF ToRectangleF()
Returns
- RectangleF
the converted rectangle
Operators
operator +(BoundingRect, BoundingRect)
Returns the smallest rectangle that contains both rectangles (the union of their extents), like MinMax(BoundingRect) but without changing the operands.
public static BoundingRect operator +(BoundingRect r1, BoundingRect r2)
Parameters
r1BoundingRectfirst rectangle
r2BoundingRectsecond rectangle
Returns
- BoundingRect
the enclosing rectangle
operator +(BoundingRect, double)
Returns an inflated or deflated rectangle
public static BoundingRect operator +(BoundingRect rect, double offset)
Parameters
rectBoundingRectThe initial rectangle
offsetdoubleThe offset for the inflation (may be negaitve)
Returns
- BoundingRect
The inflated rectangle
operator ==(BoundingRect, BoundingRect)
True, if both rectangles have exactly the same limits.
public static bool operator ==(BoundingRect r1, BoundingRect r2)
Parameters
r1BoundingRectfirst rectangle
r2BoundingRectsecond rectangle
Returns
- bool
true, if equal
explicit operator Rectangle(BoundingRect)
Typecast to a System.Drawing.Rectangle
public static explicit operator Rectangle(BoundingRect r)
Parameters
rBoundingRectThe initial rectangle
Returns
- Rectangle
The casted rectangle
operator >(BoundingRect, BoundingRect)
Determins whether r2 is contained in r1.
public static bool operator >(BoundingRect r1, BoundingRect r2)
Parameters
r1BoundingRectLeft operand
r2BoundingRectRight operand
Returns
- bool
true, if r2 is contained in r1.
operator >(GeoPoint2D, BoundingRect)
Determins whether the provided point is outside of the provided ractangle
public static bool operator >(GeoPoint2D p, BoundingRect r)
Parameters
pGeoPoint2DThe point to test
rBoundingRectThe rectangle to test with
Returns
- bool
true if outside
operator >=(BoundingRect, BoundingRect)
Determins whether r2 is contained in r1. It may also contact one ore multiple sides of the rectangle.
public static bool operator >=(BoundingRect r1, BoundingRect r2)
Parameters
r1BoundingRectLeft operand
r2BoundingRectRight operand
Returns
- bool
true, if r2 is contained in r1.
operator >=(GeoPoint2D, BoundingRect)
Determins whether the provided point is outside of the provided ractangle. It may also reside on one of the bounding lines.
public static bool operator >=(GeoPoint2D p, BoundingRect r)
Parameters
pGeoPoint2DThe point to test
rBoundingRectThe rectangle to test with
Returns
- bool
true if outside
operator !=(BoundingRect, BoundingRect)
True, if the rectangles differ in at least one limit.
public static bool operator !=(BoundingRect r1, BoundingRect r2)
Parameters
r1BoundingRectfirst rectangle
r2BoundingRectsecond rectangle
Returns
- bool
true, if not equal
operator <(BoundingRect, BoundingRect)
Determins whether r1 is contained in r2.
public static bool operator <(BoundingRect r1, BoundingRect r2)
Parameters
r1BoundingRectLeft operand
r2BoundingRectRight operand
Returns
- bool
true, if r1 is contained in r2.
operator <(GeoPoint2D, BoundingRect)
Determins whether the provided point is contained in the provided rectangle
public static bool operator <(GeoPoint2D p, BoundingRect r)
Parameters
pGeoPoint2DThe point to test
rBoundingRectThe rectangle to test with
Returns
- bool
true if contained
operator <=(BoundingRect, BoundingRect)
Determins whether r1 is contained in r2. It may also contact one ore multiple sides of the rectangle.
public static bool operator <=(BoundingRect r1, BoundingRect r2)
Parameters
r1BoundingRectLeft operand
r2BoundingRectRight operand
Returns
- bool
true, if r1 is contained in r2.
operator <=(GeoPoint2D, BoundingRect)
Determins whether the provided point is contained in the provided rectangle. It may also reside on one of the bounding lines.
public static bool operator <=(GeoPoint2D p, BoundingRect r)
Parameters
pGeoPoint2DThe point to test
rBoundingRectThe rectangle to test with
Returns
- bool
true if contained
operator *(BoundingRect, double)
Returns a rectangle which is scaled by the provided factor. The center remaines fixed.
public static BoundingRect operator *(BoundingRect rect, double Factor)
Parameters
rectBoundingRectThe initial rectangle
FactordoubleThe scalingfactor
Returns
- BoundingRect
the scaled rectangle
operator *(ModOp2D, BoundingRect)
Returns the rectangle that encloses the four vertices of rect transformed by m
(see Modify(ModOp2D)). The operand is not changed.
public static BoundingRect operator *(ModOp2D m, BoundingRect rect)
Parameters
mModOp2Dthe modification
rectBoundingRectthe rectangle to transform
Returns
- BoundingRect
the transformed rectangle