Points¶
Lightweight 2‑D / 3‑D point and vector type shared across the pybosl2 geometry layer
Lightweight 2‑D / 3‑D point and vector type shared across the pybosl2 geometry layer.
Provides Point (mutable, x/y/optional z) with
elementwise arithmetic and numpy integration. Vector is a
backward-compatible alias for Point.
-
class pybosl2.points.Point(x=
0.0, y=None, z=None)[source]¶ Bases:
Sequence[float]A mutable 2‑D or 3‑D point and vector.
Inherits from
Sequencefor compatibility with functions that acceptSequence[float].If z is
Nonethe point is 2‑D (is_2dreturnsTrue); a concrete z makes it a 3‑D point. Supports iteration, indexing,len(), elementwise arithmetic (returningPoint), andnp.asarray().Examples
from pybosl2 import Point p2 = Point(10.0, 20.0) assert p2.is_2d assert len(p2) == 2 p3 = Point(10.0, 20.0, 5.0) assert not p3.is_2d assert len(p3) == 3- x : float¶
- y : float¶
-
z : float | None =
None¶
- property is_2d : bool¶
Truewhen z isNone(a 2‑D point).
- astuple()[source]¶
Return the point as a
(x, y)or(x, y, z)tuple.- Return type:¶
tuple[float, float] | tuple[float, float, float]
- property norm : float¶
Euclidean length of the vector from origin to this point.
-
to_3d(z=
0.0)[source]¶ Return a 3‑D copy with the given z.
For a 2‑D point this adds the Z coordinate. For a 3‑D point this returns a copy with z replaced (unless z equals
self.z).
-
normalized(error=
None)[source]¶ Normalize this vector to unit length, returning a new Point.
If it has (near) zero length, returns error if given, else raises ValueError.
- angle(other)[source]¶
Angle between this vector and other in radians.
The result is always in the range [0, pi].
- axis(other)[source]¶
Return the axis vector (cross product) and angle between this vector and other.
Requires 3-D vectors.
- bisect(other)[source]¶
Return a unit vector that bisects the minor angle between this vector and other.
Returns None if they are directly opposite.
-
pybosl2.points.PointLike : TypeAlias =
pybosl2.points.Point | collections.abc.Sequence[float] | NDArray[numpy.float64]¶ What a parameter meaning “one point” accepts (PLAN T-4, the point-shaped twin of
PathLike): aPoint, the plain list or tuple a caller writes, or a NumPy array. Normalise on the first line of the body withPoint(x)ornp.asarray(x, dtype=float).Typing such a parameter np.ndarray is the defect this exists to stop: it rejected
Bezier.begin([0, 0], 45)– which is what the docstring examples write, and what any caller writes – while accepting only the form the library happens to hand back.Declared here rather than at the top of the module so its value can be a real expression: as a string it is a forward reference the linter cannot see through, and the NDArray import it needs gets pruned as unused.