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:
- 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:
- 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: T, min: T | None, max: T | None) T #
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:
- valueT
Value to clamp.
- minT | None
Minimum of clamped value.
- maxT | None
Maximum of clamped value.
- Returns:
- T
A value between min and max, inclusive.
- batgrl.geometry.basic.lerp(a: float, b: float, p: float) float #
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[tuple[int, Literal[2]], dtype[float64]] #
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:
- Coords
An (n, 2)-shaped array of evenly-spaced points on a circle.
- batgrl.geometry.basic.rect_slice(pos: Pointlike, size: Sizelike) tuple[slice, slice] #
Return slices for indexing a rect in a numpy array.
- Parameters:
- posPointlike
Position of rect.
- sizeSizelike
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.