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
-
ObjectBaseSerializableObjectBaseManualSerializationRectanglePhysical
- 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
xdoubleThe x coordinate of the lower left corner.
ydoubleThe y coordinate of the lower left corner.
widthdoubleThe width of the rectangle, measured to the right.
heightdoubleThe height of the rectangle, measured upwards.
RectanglePhysical(Rectangle, bool)
Constructor that takes a Rectangle object.
public RectanglePhysical(Rectangle rect, bool lowerLeftOrigin = false)
Parameters
rectRectangleRectangle to be converted.
lowerLeftOriginboolIf 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
rectRectangleFRectangleF to be converted.
lowerLeftOriginboolIf 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
rangeXPhysicalValueRangerangeYPhysicalValueRange
RectanglePhysical(RectanglePhysical)
Copy constructor
public RectanglePhysical(RectanglePhysical rectanglePhysical)
Parameters
rectanglePhysicalRectanglePhysicalRectangle to copy.
RectanglePhysical(VectorD, VectorD)
Constructor with location and size.
public RectanglePhysical(VectorD location, VectorD size)
Parameters
locationVectorDThe location (lower left corner) of the rectangle.
sizeVectorDThe 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
locationVectorDThe location (lower left corner) of the rectangle.
sizeVectorDThe size of the rectangle, measured to the right and upwards.
measuredQuantityXMeasuredQuantityThe measured quantity of the x-dimension.
measuredQuantityYMeasuredQuantityThe 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
Properties
Bottom
Gets the lower side of the rectangle.
public double Bottom { get; }
Property Value
Center
Gets the center point of the rectangle.
public VectorD Center { get; }
Property Value
Height
The height (measured upwards) of the rectangle.
public double Height { get; set; }
Property Value
IsEmpty
Checks whether width or height are zero.
public bool IsEmpty { get; }
Property Value
Left
Gets the left side of the rectangle.
public double Left { get; }
Property Value
Location
The location (lower left corner = minimum values) of the rectangle.
public VectorD Location { get; set; }
Property Value
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
PhysicalPropertyY
The physical property of the y dimension.
public PhysicalProperty PhysicalPropertyY { get; set; }
Property Value
Right
Gets the right side of the rectangle.
public double Right { get; }
Property Value
Size
The size of the rectangle, measured to the right and upwards.
public VectorD Size { get; set; }
Property Value
Top
Gets the upper side of the rectangle.
public double Top { get; }
Property Value
Width
The width (measured to the right) of the rectangle.
public double Width { get; set; }
Property Value
X
The x coordinate of the lower left corner, i.e. the minimum x-value.
public double X { get; set; }
Property Value
Y
The y-coordinate of the lower left corner, i.e. the minimum y-value.
public double Y { get; set; }
Property Value
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
startPointOnBoundaryNamedPolygonVertexStarting point where the corner search starts in clockwise direction.
endPointOnBoundaryNamedPolygonVertexEnd point where the corner search ends in clockwise direction.
rectangleToCutRectanglePhysicalThe 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
pointToCheckXdoublex-Coordinate or the point to check for being contained.
pointToCheckYdoubley-Coordinate or the point to check for being contained.
permissiveboolIf
true, NumericalChecks will be used for comparison.
Returns
- bool
trueif the point lies within the rectangle or on its boundaries,falseotherwise.
Contains(VectorD, bool)
Checks whether or not this rectangle contains a given point.
public bool Contains(VectorD pointToCheck, bool permissive = false)
Parameters
pointToCheckVectorDPoint to check for being contained.
permissiveboolIf
true, NumericalChecks will be used for comparison.
Returns
- bool
trueif the point lies within the rectangle or on its boundaries,falseotherwise.
ContainsCompletely(RectanglePhysical)
Method to check whether or not a given rectangle lies completely inside this
public bool ContainsCompletely(RectanglePhysical rectToCheck)
Parameters
rectToCheckRectanglePhysicalThe rectangle to be checked.
Returns
- bool
trueif 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
basePointOfLineVectorDAny point on the cutting line.
directionOfLineVectorDThe direction of the cutting line.
rectangleToCutRectanglePhysicalThe 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
objobjectequalityIntentEqualityIntentDefines what kind of equality you want to check when comparing two objects, for example all values or physical equality.
Returns
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
leftdoubleThe x-coordinate of the left border.
topdoubleThe y-coordinate of the top border.
rightdoubleThe x-coordinate of the right border.
bottomdoubleThe y-coordinate of the bottom border.
measuredQuantityXMeasuredQuantityOptional measured quantity for the x-dimension. "No Unit" by default.
measuredQuantityYMeasuredQuantityOptional 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
bottomIsElementOfRangeboolShall the bottom of the rectangle belong to the interval?
topIsElementOfRangeboolShall the top of the rectangle belong to the interval?
Returns
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
xSummanddoubleValue to be added at the left and the right.
ySummanddoubleValue 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
rectToIntersectRectanglePhysicalRectangle to intersect.
lineToIntersectLine_forGUI_physicalUnitsLine 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
rectToIntersectRectanglePhysical
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
keepSizeUnchangedbool
Scale(VectorD, bool)
Method that scales the rectangle by the given factors.
public void Scale(VectorD factors, bool keepCenter)
Parameters
factorsVectorDThe scaling factors for both x- and y-direction.
keepCenterboolWhether 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
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
formatStringstringThe format string with for parameters for left, bottom, right, and top, respectively, e.g. "(LB, RT) = ({0}, {1}); ({2}, {3})".
numberOfSignificantDigitsint?
Returns
WidthAsPhysicalValueRange(bool, bool)
Gives the width as PhysicalValueRange.
public PhysicalValueRange WidthAsPhysicalValueRange(bool leftIsElementOfRange, bool rightIsElementOfRange)
Parameters
leftIsElementOfRangeboolShall the left side of the rectangle belong to the interval?
rightIsElementOfRangeboolShall the right side of the rectangle belong to the interval?
Returns
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
r1RectanglePhysicalFirst RectanglePhysical to compare with second one.
r2RectanglePhysicalSecond 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
rectangleRectanglePhysicalThe 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
rectangleRectanglePhysicalThe 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
r1RectanglePhysicalFirst RectanglePhysical to compare with second one.
r2RectanglePhysicalSecond RectanglePhysical to compare with first one.
Returns
- bool
true, if the two RectanglePhysical objects are equal.