Skip to content

Commit 298529e

Browse files
authored
fix: resolve the case if the adjacent entity paths are duplicate (#165)
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent 2b87b55 commit 298529e

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

t4_devkit/viewer/viewer.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030
__all__ = ["RerunViewer", "format_entity"]
3131

3232

33-
def format_entity(root: str, *entities: Sequence[str]) -> str:
33+
def format_entity(*entities: Sequence[str]) -> str:
3434
"""Format entity path.
3535
3636
Args:
37-
root (str): Root entity path.
3837
*entities: Entity path(s).
3938
4039
Returns:
@@ -48,15 +47,16 @@ def format_entity(root: str, *entities: Sequence[str]) -> str:
4847
>>> format_entity("map", "map/base_link", "camera")
4948
"map/base_link/camera"
5049
"""
51-
if len(entities) == 0:
52-
return root
53-
54-
flattened = [s for t in entities for s in t.split("/")]
55-
56-
if osp.basename(root) == flattened[0]:
57-
return osp.join(root, "/".join(flattened[1:])) if len(flattened) > 1 else root
58-
else:
59-
return osp.join(root, "/".join(entities))
50+
if not entities:
51+
return ""
52+
53+
flattened = []
54+
for entity in entities:
55+
for part in entity.split("/"):
56+
if part and flattened and flattened[-1] == part:
57+
continue
58+
flattened.append(part)
59+
return "/".join(flattened)
6060

6161

6262
class RerunViewer:

tests/viewer/test_viewer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def test_format_entity() -> None:
1414
assert "map/base_link" == format_entity("map", "base_link")
1515
assert "map/base_link" == format_entity("map", "map/base_link")
1616
assert "map/base_link/camera" == format_entity("map", "map/base_link", "camera")
17+
assert "map/base_link/camera" == format_entity("map", "map/base_link", "base_link/camera")
1718

1819

1920
def test_render_box3ds(dummy_viewer, dummy_box3ds) -> None:

0 commit comments

Comments
 (0)