batgrl.geometry.basic#
Basic geometry functions and types.
Functions
|
If |
|
Linear interpolation of a to b with proportion p. |
|
Return n points on a circle. |
|
Return slices for indexing a rect in a numpy array. |
|
Like the built-in round, but always rounds down. |
Classes
- class batgrl.geometry.basic.Point(y: int, x: int)#
Bases:
NamedTuple
A 2-d point.
Note that y-coordinate is before x-coordinate. This convention is used so that the 2-d arrays that underly a gadget’s data can be directly indexed with the point.
Parameters or attributes type-hinted Point can often take tuple[int, int] for convenience.
- Parameters:
- yint
y-coordinate of point.
- xint
x-coordinate of point.
- Attributes:
- yint
y-coordinate of point.
- xint
x-coordinate of point.
- x: int#
x-coordinate of point.
- y: int#
y-coordinate of point.
- class batgrl.geometry.basic.Size(height: int, width: int)#
Bases:
NamedTuple
A rectangular area.
Parameters or attributes type-hinted Size can often take tuple[int, int] for convenience.
- Parameters:
- heightint
Height of area.
- widthint
Width of area.
- Attributes:
- property columns: int#
Alias for width.
- height: int#
Height of area.
- property rows: int#
Alias for height.
- width: int#
Width of area.
- batgrl.geometry.basic.clamp(value: Real, min: Real | None, max: Real | None) Real #
If
value
is less thanmin
, returnsmin
; else ifmax
is less thanvalue
, returnsmax
; else returnsvalue
. A one-sided clamp is possible by settingmin
ormax
toNone
.- Parameters:
- valueReal
Value to clamp.
- minReal | None
Minimum of clamped value.
- maxReal | None
Maximum of clamped value.
- Returns:
- Real
A value between min and max, inclusive.
- batgrl.geometry.basic.lerp(a: Real, b: Real, p: Real) Real #
Linear interpolation of a to b with proportion p.
- batgrl.geometry.basic.points_on_circle(n: int, radius: float = 1.0, center: tuple[float, float] = (0.0, 0.0), offset: float = 0.0) ndarray[Any, dtype[float32]] #
Return n points on a circle.
- Parameters:
- nint
Number of points on a circle.
- radiusfloat, default: 1.0
Radius of circle.
- centertuple[float, float], default: (0.0, 0.0)
Center of circle.
- offsetfloat, default: 0.0
Rotate output points by offset radians.
- Returns:
- NDArray[np.float32]
An (n, 2)-shaped NDArray of points on a circle.
- batgrl.geometry.basic.rect_slice(pos: Point, size: Size) tuple[slice, slice] #
Return slices for indexing a rect in a numpy array.
- Parameters:
- posPoint
Position of rect.
- sizeSize
Size of rect.
- Returns:
- tuple[slice, slice]
Slices that index a rect in a numpy array.
- batgrl.geometry.basic.round_down(n: float) int #
Like the built-in round, but always rounds down.
Used instead of round for smoother geometry.