Struct BoundingBox
Oriented quadrilateral in image pixel space (Y down). Corner order matches OneOCR: P1→P2 along the top (reading direction), P3→P4 along the bottom back.
Implements
Inherited Members
Namespace: Zaya.Primitives
Assembly: Zaya.Primitives.dll
Syntax
public readonly struct BoundingBox : IEquatable<BoundingBox>
Remarks
P1 ----→ P2
↑ ↓
P4 ←---- P3
Direction and AngleDegrees are derived from the average of the top edge (P2−P1) and bottom edge (P3−P4).
Constructors
| Edit this page View SourceBoundingBox(Vector2, Vector2, Vector2, Vector2)
Creates a bounding box from four corners in OneOCR order.
Declaration
public BoundingBox(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | p1 | |
| Vector2 | p2 | |
| Vector2 | p3 | |
| Vector2 | p4 |
Properties
| Edit this page View SourceAngleDegrees
Tilt of Direction from +X, in degrees (image space, Y down).
Declaration
public float AngleDegrees { get; }
Property Value
| Type | Description |
|---|---|
| float |
Bottom
Integer bottom of the AABB (ceil of MaxY).
Declaration
public int Bottom { get; }
Property Value
| Type | Description |
|---|---|
| int |
Direction
Unit vector along reading direction: normalize((P2−P1)+(P3−P4)). Falls back to (1,0) when both edges are degenerate.
Declaration
public Vector2 Direction { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
Empty
Empty box (all corners at origin).
Declaration
public static BoundingBox Empty { get; }
Property Value
| Type | Description |
|---|---|
| BoundingBox |
Height
Integer AABB height.
Declaration
public int Height { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
True when all corners are at the origin and the box has no extent.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Left
Same as X.
Declaration
public int Left { get; }
Property Value
| Type | Description |
|---|---|
| int |
MaxX
Maximum X of the axis-aligned bounds.
Declaration
public float MaxX { get; }
Property Value
| Type | Description |
|---|---|
| float |
MaxY
Maximum Y of the axis-aligned bounds.
Declaration
public float MaxY { get; }
Property Value
| Type | Description |
|---|---|
| float |
MinX
Minimum X of the axis-aligned bounds.
Declaration
public float MinX { get; }
Property Value
| Type | Description |
|---|---|
| float |
MinY
Minimum Y of the axis-aligned bounds.
Declaration
public float MinY { get; }
Property Value
| Type | Description |
|---|---|
| float |
Normal
Unit normal rotated 90° from Direction (points toward the bottom of the glyph in image space for LTR horizontal text).
Declaration
public Vector2 Normal { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
P1
Start of the top edge (reading start).
Declaration
public Vector2 P1 { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
P2
End of the top edge (reading end).
Declaration
public Vector2 P2 { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
P3
End of the bottom edge.
Declaration
public Vector2 P3 { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
P4
Start of the bottom edge.
Declaration
public Vector2 P4 { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
P5
Midpoint of the leading edge (P1–P4): start of the word along reading direction.
Declaration
public Vector2 P5 { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
P6
Midpoint of the trailing edge (P2–P3): end of the word along reading direction.
Declaration
public Vector2 P6 { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
P7
Midpoint of the top edge (P1–P2).
Declaration
public Vector2 P7 { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
P8
Midpoint of the bottom edge (P4–P3).
Declaration
public Vector2 P8 { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
Right
Integer right of the AABB (ceil of MaxX).
Declaration
public int Right { get; }
Property Value
| Type | Description |
|---|---|
| int |
TextHeight
Glyph height along the normal (distance between top and bottom edge midpoints).
Declaration
public float TextHeight { get; }
Property Value
| Type | Description |
|---|---|
| float |
Top
Same as Y.
Declaration
public int Top { get; }
Property Value
| Type | Description |
|---|---|
| int |
Width
Integer AABB width.
Declaration
public int Width { get; }
Property Value
| Type | Description |
|---|---|
| int |
X
Integer left of the AABB (floor of MinX).
Declaration
public int X { get; }
Property Value
| Type | Description |
|---|---|
| int |
Y
Integer top of the AABB (floor of MinY).
Declaration
public int Y { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
| Edit this page View SourceEquals(object?)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current instance. |
Returns
| Type | Description |
|---|---|
| bool | true if |
Overrides
| Edit this page View SourceEquals(BoundingBox)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(BoundingBox other)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundingBox | other | An object to compare with this object. |
Returns
| Type | Description |
|---|---|
| bool | true if the current object is equal to the |
FromAxisAligned(int, int, int, int)
Creates an axis-aligned box from integer pixel coordinates.
Declaration
public static BoundingBox FromAxisAligned(int x, int y, int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | |
| int | y | |
| int | width | |
| int | height |
Returns
| Type | Description |
|---|---|
| BoundingBox |
FromAxisAligned(float, float, float, float)
Creates an axis-aligned box (P1 top-left → P2 top-right → P3 bottom-right → P4 bottom-left).
Declaration
public static BoundingBox FromAxisAligned(float x, float y, float width, float height)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | |
| float | y | |
| float | width | |
| float | height |
Returns
| Type | Description |
|---|---|
| BoundingBox |
FromLTRB(int, int, int, int)
Creates an axis-aligned box from left/top/right/bottom edges.
Declaration
public static BoundingBox FromLTRB(int left, int top, int right, int bottom)
Parameters
| Type | Name | Description |
|---|---|---|
| int | left | |
| int | top | |
| int | right | |
| int | bottom |
Returns
| Type | Description |
|---|---|
| BoundingBox |
GetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A 32-bit signed integer that is the hash code for this instance. |
Overrides
| Edit this page View SourceToRect()
Returns the integer axis-aligned rectangle (X, Y, Width, Height).
Declaration
public (int X, int Y, int Width, int Height) ToRect()
Returns
| Type | Description |
|---|---|
| (int X, int Y, int Width, int Height) |
ToString()
Returns the fully qualified type name of this instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | The fully qualified type name. |
Overrides
Operators
| Edit this page View Sourceoperator ==(BoundingBox, BoundingBox)
Equality operator.
Declaration
public static bool operator ==(BoundingBox left, BoundingBox right)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundingBox | left | |
| BoundingBox | right |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(BoundingBox, BoundingBox)
Inequality operator.
Declaration
public static bool operator !=(BoundingBox left, BoundingBox right)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundingBox | left | |
| BoundingBox | right |
Returns
| Type | Description |
|---|---|
| bool |