Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit c95389a

Browse files
committed
Merge branch 'marker-str'
2 parents 8804db3 + dc5ad31 commit c95389a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

robot/markers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,12 @@ def spherical(self) -> SphericalCoord:
178178
space is different to the usual representation of a spherical space.
179179
"""
180180
return SphericalCoord(*self._raw_data['spherical'])
181+
182+
def __str__(self):
183+
bearing = self.spherical.rot_y_degrees
184+
return "<Marker {}: {:.0f}° {}, {:.2f}m away>".format(
185+
self.id,
186+
abs(bearing),
187+
"right" if bearing > 0 else "left",
188+
self.distance_metres,
189+
)

tests/test_markers.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
22
import unittest
33

4-
from robot.markers import Metres, Radians, SphericalCoord
4+
from robot.markers import Marker, Metres, Radians, SphericalCoord
55

66

77
class SphericalCoordTest(unittest.TestCase):
@@ -23,3 +23,33 @@ def test_conversion_to_degrees(self):
2323
coords.rot_y_degrees,
2424
"Wrong y rotation",
2525
)
26+
27+
28+
class MarkerTest(unittest.TestCase):
29+
def test_str_left(self):
30+
data = {
31+
'id': 13,
32+
'spherical': [
33+
0, # rot_x
34+
-0.21467549799530256, # rot_y, -12.3 degrees
35+
0.12, # distance
36+
],
37+
}
38+
self.assertEqual(
39+
str(Marker(data)),
40+
"<Marker 13: 12° left, 0.12m away>",
41+
)
42+
43+
def test_str_right(self):
44+
data = {
45+
'id': 13,
46+
'spherical': [
47+
0, # rot_x
48+
0.21467549799530256, # rot_y, 12.3 degrees
49+
0.12, # distance
50+
],
51+
}
52+
self.assertEqual(
53+
str(Marker(data)),
54+
"<Marker 13: 12° right, 0.12m away>",
55+
)

0 commit comments

Comments
 (0)