def test_point_arithmetic(): p = Point5D(x=100, y=200, z=300, t=400, c=500) assert p + Point5D.zero(x=100) == Point5D(x=200, y=200, z=300, t=400, c=500) assert p + Point5D.inf(x=100) == Point5D.inf(x=200) assert p + Point5D(x=1, y=2, z=3, t=4, c=5) == Point5D(x=101, y=202, z=303, t=404, c=505) other = Point5D(x=1, y=2, z=3, t=4, c=5) for op in ("__add__", "__sub__", "__mul__", "__floordiv__"): p_as_np = p.to_np(Point5D.LABELS) np_result = getattr(p_as_np, op)(other.to_np(Point5D.LABELS)) assert all(getattr(p, op)(other).to_np(Point5D.LABELS) == np_result)
def test_clamped_keeps_values_within_limits(): p = Point5D(x=100, y=200, z=300, t=400, c=500) assert p.clamped(maximum=Point5D.inf(y=50, c=600)).to_tuple("yc") == (50, 500) assert p.clamped(minimum=Point5D.ninf(y=300, x=90)).to_tuple("yx") == (300, 100) min_pt = Point5D(x=10, y=20, z=30, t=40, c=1000) assert p.clamped(minimum=min_pt).to_tuple("xyztc") == (100, 200, 300, 400, 1000) max_pt = Point5D(x=1, y=2, z=3, t=4, c=1000) assert p.clamped(maximum=max_pt).to_tuple("xyztc") == (1, 2, 3, 4, 500) clamped_pt = p.clamped(minimum=Point5D.ninf(x=20, t=50), maximum=Point5D.inf(x=120, t=500)) assert clamped_pt.to_tuple("xt") == (100, 400)
def test_inf_factory_method_defaults_coords_to_inf(): p = Point5D.inf(c=123, y=456) assert p.x == Point5D.INF assert p.y == 456 assert p.z == Point5D.INF assert p.t == Point5D.INF assert p.c == 123