[Port] fix printing of None rotation
This commit is contained in:
parent
06f8611a90
commit
548b51df47
2 changed files with 8 additions and 3 deletions
|
|
@ -147,7 +147,7 @@ class Port(PivotableImpl, PositionableImpl, Mirrorable, Flippable, Copyable):
|
||||||
"""
|
"""
|
||||||
Returns a human-readable description of the port's state including cardinal directions.
|
Returns a human-readable description of the port's state including cardinal directions.
|
||||||
"""
|
"""
|
||||||
deg = numpy.rad2deg(self.rotation) if self.rotation is not None else "any"
|
deg = numpy.rad2deg(self.rotation) if self.rotation is not None else None
|
||||||
|
|
||||||
cardinal = ""
|
cardinal = ""
|
||||||
travel_dir = ""
|
travel_dir = ""
|
||||||
|
|
@ -168,7 +168,8 @@ class Port(PivotableImpl, PositionableImpl, Mirrorable, Flippable, Copyable):
|
||||||
if numpy.isclose((t_deg - closest_t + 180) % 360 - 180, 0, atol=1e-3):
|
if numpy.isclose((t_deg - closest_t + 180) % 360 - 180, 0, atol=1e-3):
|
||||||
travel_dir = f" (Travel -> {dirs[closest_t]})"
|
travel_dir = f" (Travel -> {dirs[closest_t]})"
|
||||||
|
|
||||||
return f"pos=({self.x:g}, {self.y:g}), rot={deg:g}{cardinal}{travel_dir}"
|
deg_text = 'any' if deg is None else f'{deg:g}'
|
||||||
|
return f"pos=({self.x:g}, {self.y:g}), rot={deg_text}{cardinal}{travel_dir}"
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
if self.rotation is None:
|
if self.rotation is None:
|
||||||
|
|
@ -655,4 +656,3 @@ class PortList(metaclass=ABCMeta):
|
||||||
raise PortError(msg)
|
raise PortError(msg)
|
||||||
|
|
||||||
return translations[0], rotations[0], o_offsets[0]
|
return translations[0], rotations[0], o_offsets[0]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,11 @@ def test_port_measure_travel() -> None:
|
||||||
assert rotation == pi
|
assert rotation == pi
|
||||||
|
|
||||||
|
|
||||||
|
def test_port_describe_any_rotation() -> None:
|
||||||
|
p = Port((0, 0), None)
|
||||||
|
assert p.describe() == "pos=(0, 0), rot=any"
|
||||||
|
|
||||||
|
|
||||||
def test_port_list_rename() -> None:
|
def test_port_list_rename() -> None:
|
||||||
class MyPorts(PortList):
|
class MyPorts(PortList):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue