Skip to content

Commit

Permalink
refactor: rename Polygon2D to Polygon
Browse files Browse the repository at this point in the history
PR Closed: #822
  • Loading branch information
edsn60 committed Jul 14, 2021
1 parent 58fcf1d commit 21a3186
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 128 deletions.
14 changes: 7 additions & 7 deletions tensorbay/dataset/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def loads(contents: Dict[str, Any]) -> "_Type":
"CLASSIFICATION": {...},
"BOX2D": {...},
"BOX3D": {...},
"POLYGON2D": {...},
"POLYGON": {...},
"POLYLINE2D": {...},
"KEYPOINTS2D": {...},
"SENTENCE": {...}
Expand Down Expand Up @@ -146,7 +146,7 @@ def loads(cls: Type[_T], contents: Dict[str, Any]) -> _T:
"CLASSIFICATION": {...},
"BOX2D": {...},
"BOX3D": {...},
"POLYGON2D": {...},
"POLYGON": {...},
"POLYLINE2D": {...},
"KEYPOINTS2D": {...},
"SENTENCE": {...}
Expand Down Expand Up @@ -203,7 +203,7 @@ def dumps(self) -> Dict[str, Any]:
"CLASSIFICATION": {...},
"BOX2D": {...},
"BOX3D": {...},
"POLYGON2D": {...},
"POLYGON": {...},
"POLYLINE2D": {...},
"KEYPOINTS2D": {...},
"SENTENCE": {...}
Expand Down Expand Up @@ -273,7 +273,7 @@ def loads(cls: Type[_T], contents: Dict[str, Any]) -> _T:
"CLASSIFICATION": {...},
"BOX2D": {...},
"BOX3D": {...},
"POLYGON2D": {...},
"POLYGON": {...},
"POLYLINE2D": {...},
"KEYPOINTS2D": {...},
"SENTENCE": {...}
Expand Down Expand Up @@ -327,7 +327,7 @@ def dumps(self) -> Dict[str, Any]:
"CLASSIFICATION": {...},
"BOX2D": {...},
"BOX3D": {...},
"POLYGON2D": {...},
"POLYGON": {...},
"POLYLINE2D": {...},
"KEYPOINTS2D": {...},
"SENTENCE": {...}
Expand Down Expand Up @@ -391,7 +391,7 @@ def loads(cls: Type[_T], contents: Dict[str, Any]) -> _T:
"CLASSIFICATION": {...},
"BOX2D": {...},
"BOX3D": {...},
"POLYGON2D": {...},
"POLYGON": {...},
"POLYLINE2D": {...},
"KEYPOINTS2D": {...},
"SENTENCE": {...}
Expand All @@ -417,7 +417,7 @@ def dumps(self) -> Dict[str, Any]:
"CLASSIFICATION": {...},
"BOX2D": {...},
"BOX3D": {...},
"POLYGON2D": {...},
"POLYGON": {...},
"POLYLINE2D": {...},
"KEYPOINTS2D": {...},
"SENTENCE": {...}
Expand Down
4 changes: 2 additions & 2 deletions tensorbay/geometry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .box import Box2D, Box3D
from .keypoint import Keypoint2D, Keypoints2D
from .polygon import Polygon2D
from .polygon import Polygon
from .polyline import MultiPolyline2D, Polyline2D
from .transform import Transform3D
from .vector import Vector, Vector2D, Vector3D
Expand All @@ -17,7 +17,7 @@
"Box3D",
"Keypoint2D",
"Keypoints2D",
"Polygon2D",
"Polygon",
"Polyline2D",
"MultiPolyline2D",
"Transform3D",
Expand Down
32 changes: 16 additions & 16 deletions tensorbay/geometry/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Copyright 2021 Graviti. Licensed under MIT License.
#

"""PointList2D, Polygon2D.
"""PointList2D, Polygon.
:class:`PointList2D` contains a list of 2D points.
:class:`Polygon` contains the coordinates of the vertexes of the polygon
and provides :meth:`Polygon2D.area` to calculate the area of the polygon.
and provides :meth:`Polygon.area` to calculate the area of the polygon.
"""

Expand All @@ -21,7 +21,7 @@
_T = TypeVar("_T", bound=Vector2D)


class PointList2D(UserMutableSequence[_T]):
class PointList2D(UserMutableSequence[_T]): # pylint: disable=too-many-ancestors
"""This class defines the concept of PointList2D.
:class:`PointList2D` contains a list of 2D points.
Expand Down Expand Up @@ -110,7 +110,7 @@ def bounds(self) -> Box2D:
_L = TypeVar("_L", bound=PointList2D[Any])


class MultiPointList2D(UserMutableSequence[_L]):
class MultiPointList2D(UserMutableSequence[_L]): # pylint: disable=too-many-ancestors
"""This class defines the concept of MultiPointList2D.
:class:`MultiPointList2D` contains multiple 2D point lists.
Expand Down Expand Up @@ -194,41 +194,41 @@ def bounds(self) -> Box2D:
return Box2D(x_min, y_min, x_max, y_max)


class Polygon2D(PointList2D[Vector2D]):
"""This class defines the concept of Polygon2D.
class Polygon(PointList2D[Vector2D]): # pylint: disable=too-many-ancestors
"""This class defines the concept of Polygon.
:class:`Polygon2D` contains the coordinates of the vertexes of the polygon and provides
:meth:`Polygon2D.area` to calculate the area of the polygon.
:class:`Polygon` contains the coordinates of the vertexes of the polygon and provides
:meth:`Polygon.area` to calculate the area of the polygon.
Examples:
>>> Polygon2D([[1, 2], [2, 3], [2, 2]])
Polygon2D [
>>> Polygon([[1, 2], [2, 3], [2, 2]])
Polygon [
Vector2D(1, 2),
Vector2D(2, 3),
Vector2D(2, 2)
]
"""

_P = TypeVar("_P", bound="Polygon2D")
_P = TypeVar("_P", bound="Polygon")

_ElementType = Vector2D

@classmethod
def loads(cls: Type[_P], contents: List[Dict[str, float]]) -> _P:
"""Loads the information of :class:`Polygon2D`.
"""Loads the information of :class:`Polygon`.
Arguments:
contents: A list of dictionary lists containing the coordinates
of the vertexes of the polygon.
Returns:
The loaded :class:`Polygon2D` object.
The loaded :class:`Polygon` object.
Examples:
>>> contents = [{"x": 1.0, "y": 1.0}, {"x": 2.0, "y": 2.0}, {"x": 2.0, "y": 3.0}]
>>> Polygon2D.loads(contents)
Polygon2D [
>>> Polygon.loads(contents)
Polygon [
Vector2D(1.0, 1.0),
Vector2D(2.0, 2.0),
Vector2D(2.0, 3.0)
Expand All @@ -247,7 +247,7 @@ def area(self) -> float:
The area of the polygon.
Examples:
>>> polygon = Polygon2D([[1, 2], [2, 2], [2, 3]])
>>> polygon = Polygon([[1, 2], [2, 2], [2, 3]])
>>> polygon.area()
0.5
Expand Down
6 changes: 3 additions & 3 deletions tensorbay/geometry/polyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _dist(point1: Iterable[float], point2: Iterable[float]) -> float: # type: i
return hypot(*((p1 - p2) for p1, p2 in zip(point1, point2)))


class Polyline2D(PointList2D[Vector2D]):
class Polyline2D(PointList2D[Vector2D]): # pylint: disable=too-many-ancestors
"""This class defines the concept of Polyline2D.
:class:`Polyline2D` contains the coordinates of the vertexes of the polyline
Expand Down Expand Up @@ -207,7 +207,7 @@ def loads(cls: Type[_P], contents: List[Dict[str, float]]) -> _P:
return common_loads(cls, contents)


class MultiPolyline2D(MultiPointList2D[Polyline2D]):
class MultiPolyline2D(MultiPointList2D[Polyline2D]): # pylint: disable=too-many-ancestors
"""This class defines the concept of MultiPolyline2D.
:class:`MultiPolyline2D` contains a list of polylines.
Expand Down Expand Up @@ -268,7 +268,7 @@ def dumps(self) -> List[List[Dict[str, float]]]:
>>> multipolyline.dumps()
[
[{'x': 1, 'y': 1}, {'x': 1, 'y': 2}, {'x': 2, 'y': 2}],
[{'x': 2, 'y': 3}, {'x': 3, 'y': 5}
[{'x': 2, 'y': 3}, {'x': 3, 'y': 5}]
]
"""
Expand Down
26 changes: 13 additions & 13 deletions tensorbay/geometry/tests/test_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@
# Copyright 2021 Graviti. Licensed under MIT License.
#

from .. import Box2D, Polygon2D, Vector2D
from .. import Box2D, Polygon, Vector2D

_DATA_POLYGON2D = [{"x": 1.0, "y": 1.0}, {"x": 2.0, "y": 2.0}, {"x": 2.0, "y": 3.0}]
_DATA_POLYGON = [{"x": 1.0, "y": 1.0}, {"x": 2.0, "y": 2.0}, {"x": 2.0, "y": 3.0}]


class TestPolygon2D:
class TestPolygon:
def test_init(self):
sequence = [[1, 2], [2, 3], [2, 2]]
assert Polygon2D(None) == Polygon2D([])
assert Polygon2D(sequence) == Polygon2D([Vector2D(1, 2), Vector2D(2, 3), Vector2D(2, 2)])
assert Polygon(None) == Polygon([])
assert Polygon(sequence) == Polygon([Vector2D(1, 2), Vector2D(2, 3), Vector2D(2, 2)])

def test_eq(self):
polygon_1 = Polygon2D([[1, 2], [2, 3], [2, 2]])
polygon_2 = Polygon2D([[1, 2], [2, 3], [2, 2]])
polygon_3 = Polygon2D([[1, 2], [3, 4], [2, 2]])
polygon_1 = Polygon([[1, 2], [2, 3], [2, 2]])
polygon_2 = Polygon([[1, 2], [2, 3], [2, 2]])
polygon_3 = Polygon([[1, 2], [3, 4], [2, 2]])
assert (polygon_1 == polygon_2) == True
assert (polygon_1 == polygon_3) == False

def test_loads(self):
polygon = Polygon2D.loads(_DATA_POLYGON2D)
polygon = Polygon.loads(_DATA_POLYGON)
assert polygon._data == [Vector2D(1.0, 1.0), Vector2D(2.0, 2.0), Vector2D(2.0, 3.0)]

def test_dumps(self):
polygon = Polygon2D([[1, 1], [2, 2], [2, 3]])
assert polygon.dumps() == _DATA_POLYGON2D
polygon = Polygon([[1, 1], [2, 2], [2, 3]])
assert polygon.dumps() == _DATA_POLYGON

def test_area(self):
polygon = Polygon2D([[1, 2], [2, 2], [2, 3]])
polygon = Polygon([[1, 2], [2, 2], [2, 3]])
assert polygon.area() == 0.5

def test_bounds(self):
polygon = Polygon2D([[1, 2], [2, 4], [2, 3]])
polygon = Polygon([[1, 2], [2, 4], [2, 3]])
assert polygon.bounds() == Box2D(1, 2, 2, 4)
6 changes: 3 additions & 3 deletions tensorbay/label/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .label_box import Box2DSubcatalog, Box3DSubcatalog, LabeledBox2D, LabeledBox3D
from .label_classification import Classification, ClassificationSubcatalog
from .label_keypoints import Keypoints2DSubcatalog, LabeledKeypoints2D
from .label_polygon import LabeledPolygon2D, Polygon2DSubcatalog
from .label_polygon import LabeledPolygon, PolygonSubcatalog
from .label_polyline import LabeledPolyline2D, Polyline2DSubcatalog
from .label_sentence import LabeledSentence, SentenceSubcatalog, Word
from .supports import CategoryInfo, KeypointsInfo
Expand All @@ -32,11 +32,11 @@
"LabeledBox2D",
"LabeledBox3D",
"LabeledKeypoints2D",
"LabeledPolygon2D",
"LabeledPolygon",
"LabeledPolyline2D",
"LabeledSentence",
"Items",
"Polygon2DSubcatalog",
"PolygonSubcatalog",
"Polyline2DSubcatalog",
"SentenceSubcatalog",
"Subcatalogs",
Expand Down
2 changes: 1 addition & 1 deletion tensorbay/label/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LabelType(TypeEnum):
CLASSIFICATION = "classification"
BOX2D = "box2d"
BOX3D = "box3d"
POLYGON2D = "polygon2d"
POLYGON = "polygon"
POLYLINE2D = "polyline2d"
KEYPOINTS2D = "keypoints2d"
SENTENCE = "sentence"
Expand Down
12 changes: 6 additions & 6 deletions tensorbay/label/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
:class:`.ClassificationSubcatalog` subcatalog for classification type of label
:class:`.Box2DSubcatalog` subcatalog for 2D bounding box type of label
:class:`.Box3DSubcatalog` subcatalog for 3D bounding box type of label
:class:`.Keypoints2DSubcatalog` subcatalog for 2D polygon type of label
:class:`.Polygon2DSubcatalog` subcatalog for 2D polyline type of label
:class:`.Polyline2DSubcatalog` subcatalog for 2D keypoints type of label
:class:`.Keypoints2DSubcatalog` subcatalog for 2D keypoints type of label
:class:`.PolygonSubcatalog` subcatalog for polygon type of label
:class:`.Polyline2DSubcatalog` subcatalog for 2D polyline type of label
:class:`.SentenceSubcatalog` subcatalog for transcripted sentence type of label
================================== ==================================================
Expand All @@ -37,15 +37,15 @@
from .label_box import Box2DSubcatalog, Box3DSubcatalog
from .label_classification import ClassificationSubcatalog
from .label_keypoints import Keypoints2DSubcatalog
from .label_polygon import Polygon2DSubcatalog
from .label_polygon import PolygonSubcatalog
from .label_polyline import Polyline2DSubcatalog
from .label_sentence import SentenceSubcatalog

Subcatalogs = Union[
ClassificationSubcatalog,
Box2DSubcatalog,
Box3DSubcatalog,
Polygon2DSubcatalog,
PolygonSubcatalog,
Polyline2DSubcatalog,
Keypoints2DSubcatalog,
SentenceSubcatalog,
Expand Down Expand Up @@ -95,7 +95,7 @@ class Catalog(ReprMixin, AttrsMixin):
classification: ClassificationSubcatalog = _attr()
box2d: Box2DSubcatalog = _attr()
box3d: Box3DSubcatalog = _attr()
polygon2d: Polygon2DSubcatalog = _attr()
polygon: PolygonSubcatalog = _attr()
polyline2d: Polyline2DSubcatalog = _attr()
keypoints2d: Keypoints2DSubcatalog = _attr()
sentence: SentenceSubcatalog = _attr()
Expand Down
6 changes: 3 additions & 3 deletions tensorbay/label/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:class:`~tensorbay.label.label_classification.Classification` classification type of label
:class:`~tensorbay.label.label_box.LabeledBox2D` 2D bounding box type of label
:class:`~tensorbay.label.label_box.LabeledBox3D` 3D bounding box type of label
:class:`~tensorbay.label.label_polygon.LabeledPolygon2D` 2D polygon type of label
:class:`~tensorbay.label.label_polygon.LabeledPolygon` polygon type of label
:class:`~tensorbay.label.label_polyline.LabeledPolyline2D` 2D polyline type of label
:class:`~tensorbay.label.label_keypoints.LabeledKeypoints2D` 2D keypoints type of label
:class:`~tensorbay.label.label_sentence.LabeledSentence` transcripted sentence type of label
Expand All @@ -35,7 +35,7 @@
from .label_box import LabeledBox2D, LabeledBox3D
from .label_classification import Classification
from .label_keypoints import LabeledKeypoints2D
from .label_polygon import LabeledPolygon2D
from .label_polygon import LabeledPolygon
from .label_polyline import LabeledPolyline2D
from .label_sentence import LabeledSentence

Expand Down Expand Up @@ -71,7 +71,7 @@ class Label(ReprMixin, AttrsMixin):
classification: Classification = _attr()
box2d: List[LabeledBox2D] = _attr()
box3d: List[LabeledBox3D] = _attr()
polygon2d: List[LabeledPolygon2D] = _attr()
polygon: List[LabeledPolygon] = _attr()
polyline2d: List[LabeledPolyline2D] = _attr()
keypoints2d: List[LabeledKeypoints2D] = _attr()
sentence: List[LabeledSentence] = _attr()
Expand Down

0 comments on commit 21a3186

Please sign in to comment.