From 9a0129ad4eaae899edc337b11f934e7d16388b57 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Tue, 30 May 2023 16:57:57 +0100 Subject: [PATCH] Bring guideline invariants up to spec --- src/ufoLib2/objects/guideline.py | 16 ++++------------ tests/test_converters.py | 6 +++++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/ufoLib2/objects/guideline.py b/src/ufoLib2/objects/guideline.py index 2697b459..ee221104 100644 --- a/src/ufoLib2/objects/guideline.py +++ b/src/ufoLib2/objects/guideline.py @@ -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 @@ -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") diff --git a/tests/test_converters.py b/tests/test_converters.py index 047a43e7..85746f38 100644 --- a/tests/test_converters.py +++ b/tests/test_converters.py @@ -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(