Class InscribedRectangle
The InscribedRectangle class defines the largest rectangle within an arbitrary shape.
Inherited Members
Namespace: Microsoft.MixedReality.Toolkit.Boundary
Assembly: cs.temp.dll.dll
Syntax
public class InscribedRectangle
Constructors
InscribedRectangle(Edge[], Int32)
Finds a large inscribed rectangle. Tries to be maximal but this is best effort. The algorithm used was inspired by the blog post https://d3plus.org/blog/behind-the-scenes/2014/07/08/largest-rect/ Random points within the polygon are chosen, and then 2 lines are drawn through those points. The midpoints of those lines are used as the center of various rectangles, using a binary search to vary the size, until the largest fit-able rectangle is found. This is then repeated for predefined angles (0-180 in steps of 15) and aspect ratios (1 to 15 in steps of 0.5).
Declaration
public InscribedRectangle(Edge[] geometryEdges, int randomSeed)
Parameters
Type | Name | Description |
---|---|---|
Edge[] | geometryEdges | The boundary geometry. |
Int32 | randomSeed | Random number generator seed. |
Remarks
For the most reproducible results, use the same randomSeed value each time this method is called.
Properties
Angle
The rotation angle, in degrees, of the inscribed rectangle.
Declaration
public float Angle { get; }
Property Value
Type | Description |
---|---|
Single |
Center
The center point of the inscribed rectangle.
Declaration
public Vector2 Center { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Height
The height of the inscribed rectangle.
Declaration
public float Height { get; }
Property Value
Type | Description |
---|---|
Single |
IsValid
Is the described rectangle valid?
Declaration
public bool IsValid { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
A rectangle is considered valid if its center point is valid.
Width
The width of the inscribed rectangle.
Declaration
public float Width { get; }
Property Value
Type | Description |
---|---|
Single |
Methods
IsInsideBoundary(Vector2)
Determine of the provided point lies within the defined rectangle.
Declaration
public bool IsInsideBoundary(Vector2 point)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | point | The point to check |
Returns
Type | Description |
---|---|
Boolean | True if the point is within the rectangle's bounds, false otherwise. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The rectangle is not valid. |