Skip to content

Point2D

SUMMARY

A point in 2D space.

python
from telekinesis import datatypes
point2d = datatypes.Point2D([1.0, 2.0])
API Reference
Complete API documentation for Point2D, including parameters, attributes, and methods.
View Reference →

Parameters

ParameterTypeDefaultDescription
datanp.ndarray | list | tupleRequiredArray-like input, shape (2,): [x, y].

Raises

ExceptionCondition
TypeErrordata can't be converted to a float32 array (e.g. ragged nested lists, non-numeric elements)
ValueErrorThe converted array isn't 1-D, its length isn't 2, or it contains a non-finite value (NaN/Inf)

Attributes

AttributeTypeDescription
datanp.ndarrayThe wrapped point, shape (2,). Reading it returns a copy, so mutating the result doesn't affect the Point2D; assigning a new value re-validates it the same way as construction.
shapetuple[int, ...]Always (2,).
ndimintAlways 1.
dtypenp.dtypeAlways float32.
sizeintAlways 2.
shape_specClassVar[tuple[int, ...]]Class-level shape contract, (2,), inherited from Vector2D. Same for every Point2D instance.

Methods

MethodTypeDescription
Point2D.coerce(value)Point2DConverts array-like data into a Point2D. Accepts a np.ndarray, list, or tuple of shape (2,): [x, y]. If value is already a Point2D, it is returned unchanged. A Vector2D with the same values is not accepted — pass its raw array instead.
to_numpy(copy=True)np.ndarrayReturns the point as a plain array, shape (2,). With the default copy=True you get an independent copy; pass copy=False to get a direct reference to the internal array instead, so mutating it also mutates the Point2D.
copy()Point2DReturns a new, independent Point2D with the same data.

Operators

OperationBehavior
point == otherTrue only if other is also exactly a Point2D (not a Vector2D or any other type, even with identical coordinates) with equal values (NaN counts as equal to NaN). False for anything else.
len(point)Always 2 — the length of axis 0 of the underlying (2,) array, not a "number of points" count.
np.asarray(point)Returns a copy of data as an np.ndarray; NumPy functions accept a Point2D directly.
point + arr, point - arr, point * arr, point / arrNot implemented on Point2D itself (no __add__/__array_ufunc__). Verified empirically: with a NumPy array operand, NumPy coerces the Point2D via __array__ and performs plain elementwise arithmetic — the result is a plain np.ndarray, not a Point2D.

Visualization

python
import rerun as rr

# Your code block
# ....

rr.init("point2d_example", spawn=True)
datatypes.visualize(point2d, entity_path="/point2d", label="Point2D")

Example

python
"""Demonstrates the Telekinesis Point2D datatype."""

import time

import numpy as np
import rerun as rr
from loguru import logger

from telekinesis import datatypes

def point2d_example():
    """Demonstrate creation, inspection, operations, visualization, and serialization."""

    # ======================= Create ============================================
    point = [1.0, 2.0]
    point2d = datatypes.Point2D(point)
    logger.info(f"Created Point2D: {point2d}")

    # ======================= Inspect ===========================================
    logger.info(f"shape={point2d.shape}")
    logger.info(f"size={point2d.size}")
    logger.info(f"ndim={point2d.ndim}")
    logger.info(f"dtype={point2d.dtype}")
    logger.info(f"data={point2d.data}")

    # ======================= Operations =========================================
    updated_data = [3.0, 4.0]
    point2d.data = updated_data
    logger.info(f"Updated Point2D: {point2d}")

    point2d_copy = point2d.copy()
    logger.info(f"Copied Point2D: {point2d_copy}")

    point2d_numpy = point2d.to_numpy(copy=False)
    logger.info(f"NumPy Point2D: {point2d_numpy}")

    # Translate by operating on the underlying NumPy array directly.
    translation = [1.0, 1.0]
    translated_data = point2d.data + np.asarray(translation, dtype=np.float32)
    translated_point2d = datatypes.Point2D(translated_data)
    logger.info(f"Translated Point2D: {translated_point2d}")

    numpy_point2d = np.asarray(point2d)
    logger.info(f"NumPy array via __array__: {numpy_point2d}")

    # ======================= Visualize =========================================
    rr.init("point2d_example", spawn=True)
    datatypes.visualize(point2d, entity_path="/point2d/updated", label="Updated Point2D")
    datatypes.visualize(
        translated_point2d, entity_path="/point2d/translated", label="Translated Point2D"
    )

    # ======================= Serialize / Deserialize ===========================
    start = time.perf_counter()
    serialized = datatypes.serialize(point2d)
    serialization_ms = (time.perf_counter() - start) * 1000

    start = time.perf_counter()
    deserialized = datatypes.deserialize(serialized)["param_0"]
    deserialization_ms = (time.perf_counter() - start) * 1000

    logger.info(f"Deserialized Point2D: {deserialized}")
    logger.info(f"Round-trip successful: {point2d == deserialized}")
    logger.info(f"Serialization time: {serialization_ms:.3f} ms")
    logger.info(f"Deserialization time: {deserialization_ms:.3f} ms")


if __name__ == "__main__":
    point2d_example()