Skip to content

Commit

Permalink
Bring guideline invariants up to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed May 30, 2023
1 parent 4d8a960 commit 9a0129a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 4 additions & 12 deletions src/ufoLib2/objects/guideline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Guideline(AttrDictMixin):
data composition restrictions.
"""

x: Optional[float] = None
x: float = 0
"""The origin x coordinate of the guideline."""

y: Optional[float] = None
y: float = 0
"""The origin y coordinate of the guideline."""

angle: Optional[float] = None
angle: float = 0
"""The angle of the guideline."""

name: Optional[str] = None
Expand All @@ -36,13 +36,5 @@ class Guideline(AttrDictMixin):
"""The globally unique identifier of the guideline."""

def __attrs_post_init__(self) -> None:
x, y, angle = self.x, self.y, self.angle
if x is None and y is None:
raise ValueError("x or y must be present")
if x is None or y is None:
if angle is not None:
raise ValueError("if 'x' or 'y' are None, 'angle' must not be present")
if x is not None and y is not None and angle is None:
raise ValueError("if 'x' and 'y' are defined, 'angle' must be defined")
if angle is not None and not (0 <= angle <= 360):
if not (0 <= self.angle <= 360):
raise ValueError("angle must be between 0 and 360")
6 changes: 5 additions & 1 deletion tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@
],
},
),
(Guideline(x=0, name="foo"), {"x": 0, "name": "foo"}),
(Guideline(x=0, name="foo"), {"name": "foo"}),
(
Guideline(x=149, y=1523, identifier="aaa"),
{"x": 149, "y": 1523, "identifier": "aaa"},
),
(Guideline(y=1, name="bar"), {"y": 1, "name": "bar"}),
(
Guideline(
Expand Down

0 comments on commit 9a0129a

Please sign in to comment.