-
Notifications
You must be signed in to change notification settings - Fork 13
/
guideline.py
48 lines (35 loc) · 1.46 KB
/
guideline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from __future__ import annotations
from typing import Optional
from attrs import define
from ufoLib2.objects.misc import AttrDictMixin
from ufoLib2.serde import serde
@serde
@define
class Guideline(AttrDictMixin):
"""Represents a single guideline.
See http://unifiedfontobject.org/versions/ufo3/glyphs/glif/#guideline. Has some
data composition restrictions.
"""
x: Optional[float] = None
"""The origin x coordinate of the guideline."""
y: Optional[float] = None
"""The origin y coordinate of the guideline."""
angle: Optional[float] = None
"""The angle of the guideline."""
name: Optional[str] = None
"""The name of the guideline, no uniqueness required."""
color: Optional[str] = None
"""The color of the guideline."""
identifier: Optional[str] = None
"""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):
raise ValueError("angle must be between 0 and 360")