Rect2D Type
An immutable 2D Rectangle with any rotation in 2D space. Described by an Origin and two Edge vectors. This implementation guarantees the 2D Rectangle to be always valid. That means the X and Y axes are always perpendicular to each other. However the length of one of these axes might still be zero. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
Record fields
Record Field |
Description
|
The Origin Corner of the 2D Rectangle.
|
|
The Edge vector representing the X-axis of the 2D Rectangle.
|
|
The Edge vector representing the Y-axis of the 2D Rectangle.
|
Instance members
Instance member |
Description
|
Full Usage:
this.Area
Returns: float
Modifiers: inline |
Calculates the area of the 2D Rectangle.
|
Full Usage:
this.AreaSq
Returns: float
Modifiers: inline |
Calculates the squared area of the 2D Rectangle. by using the squared lengths of the X and Y axis. This is a bit faster than calculating the area and good enough for relative comparisons or sorting by size.
|
Full Usage:
this.AsString
Returns: string
|
Format the 2D Rectangle into string with nice floating point number formatting of X, Y and Z size only. But without type name as in v.ToString()
|
|
Get the axis aligned 2D Bounding Rectangle of the 2D Rectangle.
|
|
Returns the center of the 2D Rectangle.
|
|
Check for point containment in the 2D Rectangle. By doing 4 dot products with the sides of the rectangle. A point exactly on the edge of the Box is considered inside.
|
|
Returns the diagonal vector of the 2D Rectangle. From Origin to FarCorner.
|
|
Returns the diagonal 2D line from point 0 to 2 of the 2D rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns a 2D line from point 0 to 1 of the 2D rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns a 2D line from point 1 to 2 of the 2D rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns a 2D line from point 2 to 3 of the 2D rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns a 2D line from point 3 to 0 of the 2D rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns the local X side as the 2D line from point 0 to 1 of the 2D rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns the local Y side as 2D line from point 0 to 3 of the 2D rectangle. This is the reverse of Edge30. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns the 4 Edges of the 2D Rectangle in Counter-Clockwise order, starting at Origin. Returns an array of 4 Lines: from point 0 to 1, 1 to 2 to 3 and 3 to 0. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
Full Usage:
this.EvaluateAt
Parameters:
float
yParameter : float
Returns: Pt
Modifiers: inline |
Evaluate a X and Y parameter of the 2D Rectangle. 0.0, 0.0 returns the Origin. 1.0, 1.0 returns the FarCorner.
|
Full Usage:
this.EvaluateDist
Parameters:
float
yDistance : float
Returns: Pt
Modifiers: inline |
Evaluate a point at X and Y distance on the respective axes of the 2D Rectangle.
|
|
Returns the corner diagonally opposite of corner from Origin (point 2). local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns one of the 4 Edges as 2D Line: Edge 0: from point 0 to 1 Edge 1: from point 1 to 2 Edge 2: from point 2 to 3 Edge 3: from point 3 to 0 local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns the 4 corners of the 2D Rectangle in Counter-Clockwise order, starting at Origin. Returns an array of 4 Points: point 0 then 1, 2 and 3. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns the 4 corners of the 2D Rectangle als closed loop in Counter-Clockwise order, starting at Origin. First and last point are the same. Returns an array of 5 Points: point 0 then 1, 2, 3 and again 0. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
Returns point 0 of the 2D rectangle. Same as member rect.Origin. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns point 1 of the 2D rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns point 2 of the 2D rectangle. Same as rect.FarCorner. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns point 3 of the 2D rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
|
Returns the Rectangle rotated 180 degrees around its center. Returns the same rectangle with a new orientation rotated by 180 degrees around its center. This only changes the internal representation of the rectangle, the appearance is not changed. Origin will be at point 2, X-axis to to point 3, Y-axis to point 1. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns the same rectangle with a new orientation rotated by 90 degrees counter clockwise around its center. This only changes the internal representation of the rectangle, the appearance is not changed. Origin will be at point 1, X-axis to to point 2, Y-axis to point 0. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Returns the same rectangle with a new orientation rotated by 90 degrees clockwise around its center. This only changes the internal representation of the rectangle, the appearance is not changed. Origin will be at point 3, X-axis to to point 0, Y-axis to point 2. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
Full Usage:
this.SizeX
Returns: float
Modifiers: inline |
The size in X direction
|
Full Usage:
this.SizeXSq
Returns: float
Modifiers: inline |
The squared size in X direction
|
Full Usage:
this.SizeY
Returns: float
Modifiers: inline |
The size in Y direction
|
Full Usage:
this.SizeYSq
Returns: float
Modifiers: inline |
The squared size in Y direction
|
|
Returns the corner at end of X-axis (point 1). local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Creates a unitized version of the local X-Axis.
|
|
Returns the corner at end of Y-axis (point 3). local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
Creates a unitized version of the local Y-Axis.
|
Static members
Static member |
Description
|
|
|
|
Creates a 2D rectangle from three points. Fails if points are too close to each other or all colinear. The Origin, a point in X-axis direction and length, and a point for the length in Y-axis direction. Origin and x-point define the X-axis orientation of the Rectangle. The y-point only defines the length and side of the Y axis. If the y-point is on the left side of the X-axis the origin will be at point 0, X at point 1. If the y-point is on the right side of the X-axis, the X-axis will be reversed. the origin will be at point x, and the end of the x-Axis at the origin. E.G if called with points (origin=3,x=2,y=0) the origin will be at 2, X at 3, and y at 1. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Divides a 2D Rectangle into a grid of points. The points are returned as an array of arrays. A xCount and yCount of 2 will only return just the 4 corners of the rectangle. A xCount and yCount of 3 will return 9 points, including the 4 corners, the 4 mid points on the edges and the center.
|
|
Divides a a 2D Rectangle into a grid of points. It will create as few as points as possible respecting the maximum segment length. The input maxSegmentLength is multiplied by factor 1.0001 of to avoid numerical errors. That means in an edge case there are fewer segments returned, not more. The returned array is divided along the x-axis. The sub-array is divided along the y-axis.
|
|
Divides a a 2D Rectangle into a grid of points. It will create as many points as possible respecting the minimum side length for x and y. The input minSegmentLength is multiplied by factor 0.9999 of to avoid numerical errors. That means in an edge case there are more segments returned, not fewer. The returned array is divided along the x-axis. The sub-array is divided along the y-axis.
|
|
|
|
|
|
|
Full Usage:
Rect2D.offsetCorner (rect, corner, xOffset, yOffset, xWidth, yHeight)
Parameters:
Rect2D
-
The 2D Rectangle
corner : int
-
The Index of the corner to offset
local
Y-Axis
^
|
| 2
3 +------------+
| |
| |
| |
| |
| | local
+------------+-----> X-Axis
0-Origin 1
xOffset : float
-
The local offset distances in x direction. (Applies to the y side.) Positive values offset to the inside of the rectangle, negative values will offset outwards.
yOffset : float
-
The local offset distances in y direction. (Applies to the x side.) Positive values offset to the inside of the rectangle, negative values will offset outwards.
xWidth : float
-
The the width (or size in x direction) that will be added to the current offset.
yHeight : float
-
The the height (or size in y direction) that will be added to the current offset.
Returns: Rect2D
A new 2D Rectangle. It will always have the same x and y axis orientation as the input rectangle. Independent of negative or positive offsets
|
Offsets a local Rect2D at one of the four corners.
|
Full Usage:
Rect2D.offsetEdge (rect, edgeIdx, offEdge, width, offStart, offEnd)
Parameters:
Rect2D
-
The 2D Rectangle
edgeIdx : int
-
The Index of the edge to offset
local
Y-Axis
^
|
| 2
+------------+
| |
| |
3| |1
| |
| | local
+------------+-----> X-Axis
0
offEdge : float
-
The local offset distances parallel to the edge.
width : float
-
The width of the new rectangle. This is like the second offset to be applied to the first offset of offEdge
offStart : float
-
The local offset distances perpendicular to the edge at the start.
offEnd : float
-
The local offset distances perpendicular to the edge at the end.
Returns: Rect2D
A new 2D Rectangle. It will always have the same x and y axis orientation as the input rectangle. Independent of negative or positive offsets
|
Offsets a local Rect2D at one of the four corners.
|
|
Offset a Rect2D inwards by four distances. Negative distances will offset outwards. The distance array is for Edge01, Edge12, Edge23 and Edge30 respectively. Fails if the distance is larger than half the size of the rectangle. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|
|
|
Full Usage:
Rect2D.rotateWithCenter cen rot rect
Parameters:
Pt
rot : Rotation2D
rect : Rect2D
Returns: Rect2D
|
Rotation of a Rect2D. around a given Center.
|
|
Divides a 2D Rectangle into a grid of sub-rectangles. The sub-rectangles are returned as an array of arrays. The gap between the sub-rectangles is given in x and y direction. It does not apply to the outer edges of the 2D Rectangle. The returned array has xCount elements, each element is an array of yCount sub-rectangles.
|
Divides a a 2D Rectangle into a grid of sub-rectangles. The gap between the sub-rectangles is given in x and y direction. It does not apply to the outer edges of the 2D Rectangle. It will create as few as segments as possible respecting the maximum segment length. The input maxSegmentLength is multiplied by factor 1.00001 of to avoid numerical errors. That means in an edge case there are fewer segments returned, not more. The returned array is divided along the x-axis. The sub-array is divided along the y-axis.
|
|
Divides a a 2D Rectangle into a grid of sub-rectangles. The gap between the sub-rectangles is given in x and y direction. It does not apply to the outer edges of the 2D Rectangle. It will create as many sub-rectangles as possible respecting the minimum side length for x and y. The input minSegmentLength is multiplied by factor 0.9999 of to avoid numerical errors. That means in an edge case there are more segments returned, not fewer. The returned array is divided along the x-axis. The sub-array is divided along the y-axis.
|
|
|
|
|
|
|
|
|
Tries to create a 2D rectangle from three points. Returns None if points are too close to each other or all colinear. The Origin, a point in X-axis direction and length, and a point for the length in Y-axis direction. Origin and x-point define the X-axis orientation of the Rectangle. The y-point only defines the length and side of the Y axis. If the y-point is on the left side of the X-axis the origin will be at point 0, X at point 1. If the y-point is on the right side of the X-axis, the X-axis will be reversed. the origin will be at point x, and the end of the x-Axis at the origin. E.G if called with points (origin=3,x=2,y=0) the origin will be at 2, X at 3, and y at 1. local Y-Axis ^ | | 2 3 +------------+ | | | | | | | | | | local +------------+-----> X-Axis 0-Origin 1
|