48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Literal
|
|
|
|
|
|
BendDirection = Literal["CW", "CCW"]
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class StraightSeed:
|
|
length: float
|
|
|
|
def __post_init__(self) -> None:
|
|
object.__setattr__(self, "length", float(self.length))
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class Bend90Seed:
|
|
radius: float
|
|
direction: BendDirection
|
|
|
|
def __post_init__(self) -> None:
|
|
object.__setattr__(self, "radius", float(self.radius))
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class SBendSeed:
|
|
offset: float
|
|
radius: float
|
|
|
|
def __post_init__(self) -> None:
|
|
object.__setattr__(self, "offset", float(self.offset))
|
|
object.__setattr__(self, "radius", float(self.radius))
|
|
|
|
|
|
PathSegmentSeed = StraightSeed | Bend90Seed | SBendSeed
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class PathSeed:
|
|
segments: tuple[PathSegmentSeed, ...]
|
|
|
|
def __post_init__(self) -> None:
|
|
segments = tuple(self.segments)
|
|
if any(not isinstance(segment, StraightSeed | Bend90Seed | SBendSeed) for segment in segments):
|
|
raise TypeError("PathSeed segments must be StraightSeed, Bend90Seed, or SBendSeed instances")
|
|
object.__setattr__(self, "segments", segments)
|