Skip to content

Commit

Permalink
feat: Size2d.from_json()
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Nov 4, 2024
1 parent dab6451 commit 6ae1039
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
4 changes: 2 additions & 2 deletions raillabel/format/point2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Point2d:
"""A 2d point in an image."""

x: int | float
"The x-coordinate of the point in the image in pixels."
"The x-coordinate of the point in the image in pixels from the left."

y: int | float
"The y-coordinate of the point in the image in pixels."
"The y-coordinate of the point in the image in pixels from the top."

@classmethod
def from_json(cls, json: tuple[int | float, int | float]) -> Point2d:
Expand Down
19 changes: 9 additions & 10 deletions raillabel/format/size2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@

@dataclass
class Size2d:
"""The size of a rectangle in a 2d image.
"""The size of a rectangle in a 2d image."""

Parameters
----------
x: float or int
The size along the x-axis.
y: float or int
The size along the y-axis.
x: int | float
"The size along the x-axis."

"""
y: int | float
"The size along the y-axis."

x: float
y: float
@classmethod
def from_json(cls, json: tuple[int | float, int | float]) -> Size2d:
"""Construct an instant of this class from RailLabel JSON data."""
return Size2d(x=json[0], y=json[1])

@classmethod
def fromdict(cls, data_dict: dict) -> Size2d:
Expand Down
9 changes: 1 addition & 8 deletions tests/test_raillabel/format/test_point2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@

from __future__ import annotations

import os
import sys
from pathlib import Path

import pytest

sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent))

from raillabel.format import Point2d

# == Fixtures =========================
Expand Down Expand Up @@ -61,5 +55,4 @@ def test_asdict():


if __name__ == "__main__":
os.system("clear")
pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])
pytest.main([__file__, "-v"])
14 changes: 6 additions & 8 deletions tests/test_raillabel/format/test_size2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@

from __future__ import annotations

import os
import sys
from pathlib import Path

import pytest

sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent))

from raillabel.format import Size2d

# == Fixtures =========================
Expand All @@ -29,6 +23,11 @@ def size2d() -> dict:
# == Tests ============================


def test_from_json(size2d, size2d_dict):
actual = Size2d.from_json(size2d_dict)
assert actual == size2d


def test_fromdict():
size2d = Size2d.fromdict([25, 1.344])

Expand All @@ -46,5 +45,4 @@ def test_asdict():


if __name__ == "__main__":
os.system("clear")
pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])
pytest.main([__file__, "-v"])

0 comments on commit 6ae1039

Please sign in to comment.