Table of Contents

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

r BoundingRect

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

Center GeoPoint2D

Center of the BoundingRect

HalfWidth double

Half width

HalfHeight double

Half height

BoundingRect(params GeoPoint2D[])

Creates a new BoundingRect which contains the provided points

public BoundingRect(params GeoPoint2D[] p)

Parameters

p GeoPoint2D[]

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

Left double

Left limit

Bottom double

Bottom limit

Right double
Top double

BoundingRect(Rectangle)

Creates a new BoundingRect from the provided System.Drawing.rectangle

public BoundingRect(Rectangle r)

Parameters

r Rectangle

das gegebene Rechteck

Fields

Bottom

The lower limit (minimum y). It is MaxValue for the EmptyBoundingRect.

public double Bottom

Field Value

double

EmptyBoundingRect

Returns an empty BoundingRect which is convenient as a start for the MinMax(GeoPoint2D) method.

public static BoundingRect EmptyBoundingRect

Field Value

BoundingRect

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

BoundingRect

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

BoundingRect

Left

The left limit (minimum x). It is MaxValue for the EmptyBoundingRect.

public double Left

Field Value

double

Right

The right limit (maximum x). It is MinValue for the EmptyBoundingRect.

public double Right

Field Value

double

Top

The upper limit (maximum y). It is MinValue for the EmptyBoundingRect.

public double Top

Field Value

double

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

bool

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

double

UnitBoundingRect

Returns an BoundingRect form 0 to 1 in both directions

public static BoundingRect UnitBoundingRect { get; }

Property Value

BoundingRect

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

location GeoPoint2D

a point on the line

direction GeoVector2D

the direction of the line, must not be a null vector

startPoint GeoPoint2D

the point where the line enters this rectangle

endPoint GeoPoint2D

the 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

location GeoPoint2D

a point on the line

direction GeoVector2D

the direction of the line, must not be a null vector

startParameter double

parameter where the line enters this rectangle

endParameter double

parameter 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

uv GeoPoint2D

the point to test

eps double

tolerance: 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

p GeoPoint2D

the 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

b1 BoundingRect

First rectangle

b2 BoundingRect

Second 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

other BoundingRect

the rectangle to compare with

Returns

bool

true, if equal

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetCenter()

Returns the center of the rectangle

public GeoPoint2D GetCenter()

Returns

GeoPoint2D

GetHashCode()

public override int GetHashCode()

Returns

int

GetLowerLeft()

Returns the lower left point of the rectangle

public GeoPoint2D GetLowerLeft()

Returns

GeoPoint2D

GetLowerMiddle()

Returns the center of the bottom line of the rectangle

public GeoPoint2D GetLowerMiddle()

Returns

GeoPoint2D

GetLowerRight()

Returns the lower right point of the rectangle

public GeoPoint2D GetLowerRight()

Returns

GeoPoint2D

GetMiddleLeft()

Returns the center of the left line of the rectangle

public GeoPoint2D GetMiddleLeft()

Returns

GeoPoint2D

GetMiddleRight()

Returns the center of the right line of the rectangle

public GeoPoint2D GetMiddleRight()

Returns

GeoPoint2D

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

data IJsonWriteData

receives 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

info SerializationInfo

receives the data

context StreamingContext

the 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

p GeoPoint2D

The point to test

frameWidth double

The 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

GeoPoint2D

GetUpperMiddle()

Returns the center of the upper line of the rectangle

public GeoPoint2D GetUpperMiddle()

Returns

GeoPoint2D

GetUpperRight()

Returns the upper right point of the rectangle

public GeoPoint2D GetUpperRight()

Returns

GeoPoint2D

Inflate(double)

Inflates the rectangle by the provided value which may also be negative (for shrinking)

public void Inflate(double d)

Parameters

d double

Value for infaltion

Inflate(double, double)

Inflates the rectangle with different values in width an height

public void Inflate(double width, double height)

Parameters

width double

Inflation of the width

height double

Inflation of the height

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

factor double

the 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

factor double

the 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

factor double

the 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

rect BoundingRect

Returns

bool

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

r BoundingRect

Rectangle to be included

MinMax(GeoPoint2D)

Adapts the size of this bounding rectangle to include the provided point.

public void MinMax(GeoPoint2D p)

Parameters

p GeoPoint2D

Point 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

p GeoPoint2D[]

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

y double

y 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

x double

x 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

m ModOp2D

Modification to use

Move(GeoVector2D)

Moves the rectangle by the provided offset

public void Move(GeoVector2D offset)

Parameters

offset GeoVector2D

Offset 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

data IJsonReadData

not 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

r1 BoundingRect

first rectangle

r2 BoundingRect

second rectangle

Returns

BoundingRect

the enclosing rectangle

operator +(BoundingRect, double)

Returns an inflated or deflated rectangle

public static BoundingRect operator +(BoundingRect rect, double offset)

Parameters

rect BoundingRect

The initial rectangle

offset double

The 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

r1 BoundingRect

first rectangle

r2 BoundingRect

second rectangle

Returns

bool

true, if equal

explicit operator Rectangle(BoundingRect)

Typecast to a System.Drawing.Rectangle

public static explicit operator Rectangle(BoundingRect r)

Parameters

r BoundingRect

The 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

r1 BoundingRect

Left operand

r2 BoundingRect

Right 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

p GeoPoint2D

The point to test

r BoundingRect

The 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

r1 BoundingRect

Left operand

r2 BoundingRect

Right 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

p GeoPoint2D

The point to test

r BoundingRect

The 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

r1 BoundingRect

first rectangle

r2 BoundingRect

second 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

r1 BoundingRect

Left operand

r2 BoundingRect

Right 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

p GeoPoint2D

The point to test

r BoundingRect

The 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

r1 BoundingRect

Left operand

r2 BoundingRect

Right 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

p GeoPoint2D

The point to test

r BoundingRect

The 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

rect BoundingRect

The initial rectangle

Factor double

The 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

m ModOp2D

the modification

rect BoundingRect

the rectangle to transform

Returns

BoundingRect

the transformed rectangle