rework structure of everything

This commit is contained in:
Jan Petykiewicz 2026-03-30 15:32:29 -07:00
commit 941d3e01df

View file

@ -1,8 +1,10 @@
from dataclasses import FrozenInstanceError
from typing import Any
from hypothesis import given, strategies as st
import pytest
from inire.geometry.primitives import Port, rotate_port, translate_port
from inire.geometry.primitives import Port
@st.composite
@ -24,11 +26,11 @@ def test_port_transform_invariants(p: Port) -> None:
# Rotating 90 degrees 4 times should return to same orientation
p_rot = p
for _ in range(4):
p_rot = rotate_port(p_rot, 90)
p_rot = p_rot.rotated(90)
assert abs(p_rot.x - p.x) < 1e-6
assert abs(p_rot.y - p.y) < 1e-6
assert (p_rot.orientation % 360) == (p.orientation % 360)
assert (p_rot.r % 360) == (p.r % 360)
@given(
@ -37,14 +39,21 @@ def test_port_transform_invariants(p: Port) -> None:
dy=st.floats(min_value=-1000, max_value=1000),
)
def test_translate_snapping(p: Port, dx: float, dy: float) -> None:
p_trans = translate_port(p, dx, dy)
p_trans = p.translate(dx, dy)
assert isinstance(p_trans.x, int)
assert isinstance(p_trans.y, int)
def test_orientation_normalization() -> None:
p = Port(0, 0, 360)
assert p.orientation == 0
assert p.r == 0
p2 = Port(0, 0, -90)
assert p2.orientation == 270
assert p2.r == 270
def test_port_is_immutable_value_type() -> None:
p = Port(1, 2, 90)
with pytest.raises(FrozenInstanceError):
p.x = 3