Table of Contents

Class RectanglePhysical

Namespace
VirtualLabAPI.Core.Numerics
Assembly
VirtualLabAPI.dll

Class which describes a rectangle of physical dimensions. The location is in the lower left corner, the x-axis directs to the right, the y-axis upwards.

[Serializable]
public class RectanglePhysical : ManualSerialization, IEquatable<IObjectBase>, ICloneable, ISerializable, IDeserializationCallback
Inheritance
ObjectBase
SerializableObjectBase
ManualSerialization
RectanglePhysical
Implements
IEquatable<IObjectBase>
Inherited Members

Constructors

RectanglePhysical()

Default constructor

public RectanglePhysical()

RectanglePhysical(double, double, double, double)

Constructor with location coordinates, width, and height.

public RectanglePhysical(double x, double y, double width, double height)

Parameters

x double

The x coordinate of the lower left corner.

y double

The y coordinate of the lower left corner.

width double

The width of the rectangle, measured to the right.

height double

The height of the rectangle, measured upwards.

RectanglePhysical(Rectangle, bool)

Constructor that takes a Rectangle object.

public RectanglePhysical(Rectangle rect, bool lowerLeftOrigin = false)

Parameters

rect Rectangle

Rectangle to be converted.

lowerLeftOrigin bool

If this optional parameter is set true, the point (left, bottom) will be copied as location. Otherwise the point (left, top) will be the location.

RectanglePhysical(RectangleF, bool)

Constructor that takes a RectangleF object.

public RectanglePhysical(RectangleF rect, bool lowerLeftOrigin = false)

Parameters

rect RectangleF

RectangleF to be converted.

lowerLeftOrigin bool

If this optional parameter is set true, the point (left, bottom) will be copied as location. Otherwise the point (left, top) will be the location.

RectanglePhysical(PhysicalValueRange, PhysicalValueRange)

Constructor which gets a physical value range for x and y respectively.

public RectanglePhysical(PhysicalValueRange rangeX, PhysicalValueRange rangeY)

Parameters

rangeX PhysicalValueRange
rangeY PhysicalValueRange

RectanglePhysical(RectanglePhysical)

Copy constructor

public RectanglePhysical(RectanglePhysical rectanglePhysical)

Parameters

rectanglePhysical RectanglePhysical

Rectangle to copy.

RectanglePhysical(VectorD, VectorD)

Constructor with location and size.

public RectanglePhysical(VectorD location, VectorD size)

Parameters

location VectorD

The location (lower left corner) of the rectangle.

size VectorD

The size of the rectangle, measured to the right and upwards.

RectanglePhysical(VectorD, VectorD, MeasuredQuantity, MeasuredQuantity)

Constructor with location, size, and physical properties.

public RectanglePhysical(VectorD location, VectorD size, MeasuredQuantity measuredQuantityX, MeasuredQuantity measuredQuantityY)

Parameters

location VectorD

The location (lower left corner) of the rectangle.

size VectorD

The size of the rectangle, measured to the right and upwards.

measuredQuantityX MeasuredQuantity

The measured quantity of the x-dimension.

measuredQuantityY MeasuredQuantity

The measured quantity of the y-dimension.

Fields

FormatString

The string describing how a rectangle is formatted when the ToString method is used.

public const string FormatString = "(LB, RT) = ({0}, {1}); ({2}, {3})"

Field Value

string

Properties

Bottom

Gets the lower side of the rectangle.

public double Bottom { get; }

Property Value

double

Center

Gets the center point of the rectangle.

public VectorD Center { get; }

Property Value

VectorD

Height

The height (measured upwards) of the rectangle.

public double Height { get; set; }

Property Value

double

IsEmpty

Checks whether width or height are zero.

public bool IsEmpty { get; }

Property Value

bool

Left

Gets the left side of the rectangle.

public double Left { get; }

Property Value

double

Location

The location (lower left corner = minimum values) of the rectangle.

public VectorD Location { get; set; }

Property Value

VectorD

MeasuredQuantityX

Gets and sets the measured quantity for the x-dimension.

public MeasuredQuantity MeasuredQuantityX { get; set; }

Property Value

MeasuredQuantity

MeasuredQuantityY

Gets and sets the measured quantity for the y-dimension.

public MeasuredQuantity MeasuredQuantityY { get; set; }

Property Value

MeasuredQuantity

PhysicalPropertyX

The physical property of the x dimension.

public PhysicalProperty PhysicalPropertyX { get; set; }

Property Value

PhysicalProperty

PhysicalPropertyY

The physical property of the y dimension.

public PhysicalProperty PhysicalPropertyY { get; set; }

Property Value

PhysicalProperty

Right

Gets the right side of the rectangle.

public double Right { get; }

Property Value

double

Size

The size of the rectangle, measured to the right and upwards.

public VectorD Size { get; set; }

Property Value

VectorD

Top

Gets the upper side of the rectangle.

public double Top { get; }

Property Value

double

Width

The width (measured to the right) of the rectangle.

public double Width { get; set; }

Property Value

double

X

The x coordinate of the lower left corner, i.e. the minimum x-value.

public double X { get; set; }

Property Value

double

Y

The y-coordinate of the lower left corner, i.e. the minimum y-value.

public double Y { get; set; }

Property Value

double

Methods

Clone()

Creates a new object that is a copy of the current instance.

public override object Clone()

Returns

object

A new object that is a copy of this instance.

CompleteCuttingLineByRectangle(NamedPolygonVertex, NamedPolygonVertex, RectanglePhysical)

Cuts a RectanglePhysical in a special way. One point on the boundary has to be given. From this point the rectangle's boundary is traced in clockwise direction until the second point on the boundary (which has to be given too) is reached. All rectangle corners on the way are collected. Finally a polygon is created: [starting point]-[intermediate corner 1]-[intermediate corner 2]-...-[end point].

public static SimplePolygon CompleteCuttingLineByRectangle(NamedPolygonVertex startPointOnBoundary, NamedPolygonVertex endPointOnBoundary, RectanglePhysical rectangleToCut)

Parameters

startPointOnBoundary NamedPolygonVertex

Starting point where the corner search starts in clockwise direction.

endPointOnBoundary NamedPolygonVertex

End point where the corner search ends in clockwise direction.

rectangleToCut RectanglePhysical

The rectangle to be cut.

Returns

SimplePolygon

That piece of the rectangle which is created by the (clockwise) sequence [starting point]-[intermediate corner 1]-[intermediate corner 2]-...-[end point].

Contains(double, double, bool)

Checks whether or not this rectangle contains a given point.

public bool Contains(double pointToCheckX, double pointToCheckY, bool permissive = false)

Parameters

pointToCheckX double

x-Coordinate or the point to check for being contained.

pointToCheckY double

y-Coordinate or the point to check for being contained.

permissive bool

If true, NumericalChecks will be used for comparison.

Returns

bool

true if the point lies within the rectangle or on its boundaries, false otherwise.

Contains(VectorD, bool)

Checks whether or not this rectangle contains a given point.

public bool Contains(VectorD pointToCheck, bool permissive = false)

Parameters

pointToCheck VectorD

Point to check for being contained.

permissive bool

If true, NumericalChecks will be used for comparison.

Returns

bool

true if the point lies within the rectangle or on its boundaries, false otherwise.

ContainsCompletely(RectanglePhysical)

Method to check whether or not a given rectangle lies completely inside this

public bool ContainsCompletely(RectanglePhysical rectToCheck)

Parameters

rectToCheck RectanglePhysical

The rectangle to be checked.

Returns

bool

true if the rectangle to be checked lies completely inside this, otherwise false.

CutByLine(VectorD, VectorD, RectanglePhysical)

Method which cuts a rectangle by a given line into pieces (two at most).

public static List<SimplePolygon> CutByLine(VectorD basePointOfLine, VectorD directionOfLine, RectanglePhysical rectangleToCut)

Parameters

basePointOfLine VectorD

Any point on the cutting line.

directionOfLine VectorD

The direction of the cutting line.

rectangleToCut RectanglePhysical

The rectangle to be cut.

Returns

List<SimplePolygon>

Up to two pieces the rectangle is split to by the line.

Equals(object, EqualityIntent)

Determines whether the specified object is equal to this instance.

public override bool Equals(object obj, EqualityIntent equalityIntent)

Parameters

obj object
equalityIntent EqualityIntent

Defines what kind of equality you want to check when comparing two objects, for example all values or physical equality.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

FromLTRB(double, double, double, double, MeasuredQuantity, MeasuredQuantity)

Creates a RectanglePhysical with the specified borders.

public static RectanglePhysical FromLTRB(double left, double top, double right, double bottom, MeasuredQuantity measuredQuantityX = null, MeasuredQuantity measuredQuantityY = null)

Parameters

left double

The x-coordinate of the left border.

top double

The y-coordinate of the top border.

right double

The x-coordinate of the right border.

bottom double

The y-coordinate of the bottom border.

measuredQuantityX MeasuredQuantity

Optional measured quantity for the x-dimension. "No Unit" by default.

measuredQuantityY MeasuredQuantity

Optional measured quantity for the y-dimension. "No Unit" by default.

Returns

RectanglePhysical

A new rectangle as specified.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

HeightAsPhysicalValueRange(bool, bool)

Gives the height as PhysicalValueRange.

public PhysicalValueRange HeightAsPhysicalValueRange(bool bottomIsElementOfRange, bool topIsElementOfRange)

Parameters

bottomIsElementOfRange bool

Shall the bottom of the rectangle belong to the interval?

topIsElementOfRange bool

Shall the top of the rectangle belong to the interval?

Returns

PhysicalValueRange

Inflate(double, double)

Method that inflates the rectangle by adding the same value left and right, and at the top and bottom, respectively.

public void Inflate(double xSummand, double ySummand)

Parameters

xSummand double

Value to be added at the left and the right.

ySummand double

Value to be added at the top and the bottom.

IntersectWithLine(RectanglePhysical, Line_forGUI_physicalUnits)

Method for calculating the intersection(s) of a rectangle and a line.

public static List<(VectorD intersectionPoint, string nameOfPoint)> IntersectWithLine(RectanglePhysical rectToIntersect, Line_forGUI_physicalUnits lineToIntersect)

Parameters

rectToIntersect RectanglePhysical

Rectangle to intersect.

lineToIntersect Line_forGUI_physicalUnits

Line to intersect.

Returns

List<(VectorD intersectionPoint, string nameOfPoint)>

List of intersection points (position and name).

Intersection(RectanglePhysical)

Method that calculates the intersection of two rectangles.

public RectanglePhysical Intersection(RectanglePhysical rectToIntersect)

Parameters

rectToIntersect RectanglePhysical

Returns

RectanglePhysical

The intersection of this and rectToIntersect if it is not empty, otherwise null.

OnRectangleChanged(bool)

Method which throws event if necessary.

public void OnRectangleChanged(bool keepSizeUnchanged)

Parameters

keepSizeUnchanged bool

Scale(VectorD, bool)

Method that scales the rectangle by the given factors.

public void Scale(VectorD factors, bool keepCenter)

Parameters

factors VectorD

The scaling factors for both x- and y-direction.

keepCenter bool

Whether the center of the region remains unchanged (true) or is scaled by the same factors (false).

SetLocationAndSize(VectorD, VectorD)

Method for setting location and size at once. This throws one change event only.

public void SetLocationAndSize(VectorD location, VectorD size)

Parameters

location VectorD

New location to be set.

size VectorD

New size to be set.

ToString()

Overridden ToString() gives the rectangle in the format "(LB, RT) = (left, bottom); (right, top)".

public override string ToString()

Returns

string

The formatted string.

ToString(string, int?)

Converts to string.

public string ToString(string formatString, int? numberOfSignificantDigits = null)

Parameters

formatString string

The format string with for parameters for left, bottom, right, and top, respectively, e.g. "(LB, RT) = ({0}, {1}); ({2}, {3})".

numberOfSignificantDigits int?

Returns

string

A string that represents this instance.

WidthAsPhysicalValueRange(bool, bool)

Gives the width as PhysicalValueRange.

public PhysicalValueRange WidthAsPhysicalValueRange(bool leftIsElementOfRange, bool rightIsElementOfRange)

Parameters

leftIsElementOfRange bool

Shall the left side of the rectangle belong to the interval?

rightIsElementOfRange bool

Shall the right side of the rectangle belong to the interval?

Returns

PhysicalValueRange

Events

RectangleChanged

Event, thrown if the coordinates of the line have changed.

public event RectangleChangedDelegate RectangleChanged

Event Type

RectangleChangedDelegate

Operators

operator ==(RectanglePhysical, RectanglePhysical)

Operator for comparing two RectanglePhysical objects.

public static bool operator ==(RectanglePhysical r1, RectanglePhysical r2)

Parameters

r1 RectanglePhysical

First RectanglePhysical to compare with second one.

r2 RectanglePhysical

Second RectanglePhysical to compare with first one.

Returns

bool

true, if the two RectanglePhysical objects are equal.

explicit operator RectangleF(RectanglePhysical)

Explicit conversion operator from a RectanglePhysical to a RectangleF.

public static explicit operator RectangleF(RectanglePhysical rectangle)

Parameters

rectangle RectanglePhysical

The RectanglePhysical to convert.

Returns

RectangleF

The resulting RectangleF object.

explicit operator RectangleD(RectanglePhysical)

Explicit conversion operator from a RectanglePhysical to a RectangleD.

public static explicit operator RectangleD(RectanglePhysical rectangle)

Parameters

rectangle RectanglePhysical

The RectanglePhysical to convert.

Returns

RectangleD

The resulting RectangleD object.

operator !=(RectanglePhysical, RectanglePhysical)

Inequality operator for two RectanglePhysical objects.

public static bool operator !=(RectanglePhysical r1, RectanglePhysical r2)

Parameters

r1 RectanglePhysical

First RectanglePhysical to compare with second one.

r2 RectanglePhysical

Second RectanglePhysical to compare with first one.

Returns

bool

true, if the two RectanglePhysical objects are equal.