pchandler.geometry.spherical.angle

Unit-aware angle scalar and array wrappers (radians / degrees / gon).

Classes

Angle

Represent a scalar (or, via __new__ dispatch, array) angle in any supported unit.

AngleArray

Multi-dimensional array of angles, supporting indexing, iteration and unit conversion.

AngleBase

Base class providing storage, unit conversion, comparison and arithmetic for angles.

class pchandler.geometry.spherical.angle.AngleBase

Bases: object

Base class providing storage, unit conversion, comparison and arithmetic for angles.

Angles are always stored internally in radians; the display_unit controls the unit used for string formatting and display_value.

__init__(value, unit=AngleUnit.RAD)

Initialize an AngleBase.

Internally the angle is stored in radians; unit specifies the display unit (and the input unit of value).

Parameters:
  • value (float | ArrayT) – Numeric value(s) interpreted in unit.

  • unit (AngleUnit, default=AngleUnit.RAD) – Unit in which value is supplied and in which the angle will be displayed.

to(unit)

Convert the stored radians to unit and return the numeric value.

Parameters:

unit (AngleUnit) – Target unit.

Returns:

Numeric value(s) in unit.

Return type:

Array_Float_T | float

in_unit(unit)

Return a view of the angle with its display unit changed to unit.

Parameters:

unit (AngleUnit) – Target display unit.

Returns:

New instance sharing the underlying radian array.

Return type:

Angle | AngleArray

property display_unit: AngleUnit

Return the display unit currently set for the angle(s).

Returns:

The current display unit.

Return type:

AngleUnit

property internal_value: float | Array_Float_T

Return the underlying stored angle value(s), always in radians.

property display_value: GSEGUtils.base_types.Array_Float_T

Return the angle value(s) converted into the current display unit.

property degrees: float | Array_Float_T

Return a copy of the angle value(s) in degrees.

Returns:

Angle(s) in degrees.

Return type:

float | Array_Float_T

in_degrees()

Return a view of the angle(s) with display unit set to degrees.

Returns:

New instance sharing the underlying radian array.

Return type:

Angle | AngleArray

property radians: float | Array_Float_T

Return a copy of the angle value(s) in radians.

Returns:

Angle(s) in radians.

Return type:

float | Array_Float_T

in_radians()

Return a view of the angle(s) with display unit set to radians.

Returns:

New instance sharing the underlying radian array.

Return type:

Angle | AngleArray

property gon: float | Array_Float_T

Return a copy of the angle value(s) in gradians (gon).

Returns:

Angle(s) in gon.

Return type:

float | Array_Float_T

in_gon()

Return a view of the angle(s) with display unit set to gradians (gon).

Returns:

New instance sharing the underlying radian array.

Return type:

Angle | AngleArray

min()

Return the minimum value of the angle(s) in radians.

max()

Return the maximum value of the angle(s) in radians.

class pchandler.geometry.spherical.angle.Angle

Bases: AngleBase

Represent 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 to AngleArray.

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 Angle or AngleArray based on the input shape.

Parameters:
  • value (float, Array_Float_T, or str) – The angle value(s). If a string, it is parsed to create an instance.

  • unit (AngleUnit, default=AngleUnit.RAD) – The unit of the angle value(s).

Returns:

An instance of either Angle or AngleArray depending on the dimension of the input value.

Return type:

Angle or AngleArray

classmethod parse(value)

Build an Angle / AngleArray from 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:

Angle | AngleArray

Raises:

ValueError – If value cannot be parsed as an angle.

class pchandler.geometry.spherical.angle.AngleArray

Bases: AngleBase

Multi-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 arr is supplied (also the initial display unit).

static __new__(cls, arr, unit=AngleUnit.RAD)

Return a new AngleArray carrying arr (a copy as float64).

property shape: tuple[int, ...]

Return the shape of the underlying array.

Returns:

Shape tuple, matching numpy.ndarray.shape.

Return type:

tuple[int, …]