pchandler.geometry.spherical
Spherical-geometry classes and helpers (Angle units, field-of-view tiles).
- class pchandler.geometry.spherical.Angle
Bases:
AngleBaseRepresent a scalar (or, via
__new__dispatch, array) angle in any supported unit.Supports flexible construction from numbers, strings (
"45deg","0.5 rad","200.4gon"), and array-like inputs. Array inputs are upcast toAngleArray.- Parameters:
value (float) – The numerical representation of the angle.
unit (AngleUnit) – The unit of the angle, such as radians or degrees.
- static __new__(cls, value, unit=AngleUnit.RAD)
Return a new
AngleorAngleArraybased on the input shape.- Parameters:
- Returns:
An instance of either
AngleorAngleArraydepending on the dimension of the input value.- Return type:
Angle or AngleArray
- classmethod parse(value)
Build an
Angle/AngleArrayfrom a variety of input formats.Supported formats include:
Angle | AngleArray
(value, unit) tuple
single string
"45deg","0.5 rad","200.4gon", etc.numpy scalar
int | float
numpy array
list | tuple of numbers
- Parameters:
value (Any) – Input value to parse into an angle.
- Returns:
The parsed angle.
- Return type:
- Raises:
ValueError – If
valuecannot be parsed as an angle.
- class pchandler.geometry.spherical.AngleArray
Bases:
AngleBaseMulti-dimensional array of angles, supporting indexing, iteration and unit conversion.
- Parameters:
arr (ArrayT) – The array of angle values.
unit (AngleUnit, default=AngleUnit.RAD) – The unit in which
arris supplied (also the initial display unit).
- static __new__(cls, arr, unit=AngleUnit.RAD)
Return a new
AngleArraycarryingarr(a copy as float64).
- class pchandler.geometry.spherical.FoV
Bases:
BaseModelA rectangular angular region (Field of View) in spherical coordinates.
Defined by left/right horizontal bounds and top/bottom vertical bounds. Horizontal angles wrap on the
+/- pidiscontinuity (left > right indicates a wrapping FoV).- classmethod construct_without_bounds_check(*, left, right, top, bottom)
Construct a FoV without bounds check.
Enables construction of an
FoVwhose angular limits cross over the standard wraparound boundary (e.g., a horizontal FoV spanning350to10degrees).- Parameters:
left (AngleLikeT) – Left horizontal bound. May be greater than
rightto denote a wraparound region.right (AngleLikeT) – Right horizontal bound.
top (AngleLikeT) – Top vertical bound.
bottom (AngleLikeT) – Bottom vertical bound. May be less than
topfor wraparound.
- Returns:
A new
FoVconstructed viapydantic.BaseModel.model_construct(), bypassing the_check_elevationand_check_bottom_and_topmodel validators.- Return type:
Notes
This method bypasses the
_check_elevationand_check_bottom_and_topmodel validators viamodel_construct(). It exists for legitimate use cases – FoVs that cross the angular wraparound (e.g., a horizontal FoV spanning350to10degrees). The caller is responsible for ensuring the (left,right,top,bottom) quadruple represents a meaningful angular region; downstream FoV operations may produce surprising results if the invariant is violated.This is FRAG-06 documentation (Plan 02-06 / D-22): the
model_constructcall below is deliberate and the design is correct as-is. The method is not a security bypass –construct_without_bounds_checkis callable only by code that already has full control over the FoV construction, and the validators it skips are domain-shape checks (angular ordering), not security-shape checks.
- property crosses_pi: bool
Check whether the FoV horizontal range crosses the
+/- piboundary.- Returns:
Trueifleft > right(wrapping FoV).- Return type:
- property elevation_max: Angle
Elevation maximum angle value. Equivalent to the bottom attribute.
Warning
- DeprecationWarning
This property is deprecated. Use the ‘bottom’ property instead.
- Return type:
- property elevation_min: Angle
Elevation minimum angle value. Equivalent to the top attribute.
Warning
- DeprecationWarning
This property is deprecated. Use the ‘top’ property instead.
- Return type:
- encompasses(fov2)
Check whether
selffully surroundsfov2.
- equal_tiles(width, height)
Divides a region into equal tiles based on a specified width and height.
- extend_to_ratio(ratio)
Extend the FoV to match a specified width-to-height ratio.
- extent()
Return the angular extent
(width, height)of the FoV.
- find_points_inside(horizontal, vertical)
Return a boolean mask of the input points that fall inside the FoV.
- classmethod from_angles(horizontal, vertical)
Construct a FoV from horizontal and vertical angles.
- Parameters:
horizontal (VectorT | AngleArray)
vertical (VectorT | AngleArray)
- Return type:
- classmethod from_center_with_extent(centerpoint, extent)
Build an
FoVfrom a center point and angular extent.
- height()
Return the angular height (vertical extent) of the FoV.
- Returns:
The vertical extent.
- Return type:
- property horizontal_max: Angle
Horizontal maximum angle value. Equivalent to the right attribute.
Warning
- DeprecationWarning
This property is deprecated. Use the ‘right’ property instead.
- Return type:
- property horizontal_min: Angle
Horizontal minimum angle value. Equivalent to the left attribute.
Warning
- DeprecationWarning
This property is deprecated. Use the ‘left’ property instead.
- Return type:
- intersect(fov2)
Return the intersection of this FoV with another, or
Noneif disjoint.
- classmethod merge(fovs)
Merge multiple FoVs into one that encompasses the total area covered.
- quadrants()
Split the FoV into four equal quadrants.
- Returns:
The four quadrant FoVs (top-left, top-right, bottom-left, bottom-right).
- Return type:
tuple of Self
- ratio()
Return the width-to-height ratio of the FoV.
- Returns:
width() / height().- Return type:
NonNegativeFloat
- split(shape)
Split the FoV into smaller FoVs based on a grid shape.
- Parameters:
shape (tuple[int, int]) – The number of horizontal and vertical splits respectively.
- Return type:
Notes
split((1, 1))returns[self]– the original instance is reused by identity (not value-equality). Downstream code may rely onsplits[0] is fovfor this single-tile case (e.g., FoVTree’s no-op-split short-circuit).
- tile(target_extent, expand_to_integer_multiple=False)
Divides the current field of view (FOV) into smaller tiles based on the specified target extent/FoV.
If expand_to_integer_multiple is True, the method ensures that the field of view is expanded to the nearest integer multiple of the target_extent dimensions before tiling.
- union(fov2)
Return the union of this FoV with another (handles wrap at
+/- pi).
- width()
Return the angular width (horizontal extent) of the FoV.
- Returns:
The horizontal extent (accounting for wrap at
+/- pi).- Return type:
- class pchandler.geometry.spherical.FoVTree
Bases:
objectA hierarchical tree structure for spatial partitioning of FoVs.
- Parameters:
- __init__(identifier, node, children=<factory>)
- static add_identifier(fovs, shape)
Add unique identifier(s) to each field of view (FoV) in the list.
- classmethod build_from_tiles(tiles, min_children=4, identifier='')
Construct a tree from a 2D grid of FoVs by recursive quad-splitting.
- static calculate_optimal_shape(fov, target_ratio, max_denominator)
Calculate the optimal shape based on a given field of view (FoV), target ratio, and maximum denominator.
- depth()
Return the depth of the FoVTree from the current node.
Leaf nodes have a depth of 1.
- Return type:
- is_leaf()
Check whether this FoVTree node is a leaf (has no child nodes).
- Returns:
Trueif the node has no children,Falseotherwise.- Return type:
- to_list()
Convert tree structure into a flattened list.
Modules
Unit-aware angle scalar and array wrappers (radians / degrees / gon). |
|
Fields of View (FoVs) and hierarchical FoV trees for spherical-coordinate spatial partitioning. |