Source code for pygerber.renderer.spec

# -*- coding: utf-8 -*-
from __future__ import annotations

from abc import ABC, abstractmethod
from dataclasses import dataclass

import pygerber.renderer.aperture as meta_ap
from pygerber.mathclasses import Vector2D


[docs]class Spec(ABC):
[docs] @abstractmethod def draw(self, aperture): raise TypeError()
[docs] @abstractmethod def bbox(self, aperture): raise TypeError()
[docs]@dataclass class FlashSpec(Spec): location: Vector2D is_region: bool = False
[docs] def draw(self, aperture: meta_ap.Aperture): return aperture.flash(self)
[docs] def bbox(self, aperture: meta_ap.Aperture): return aperture.flash_bbox(self)
[docs]@dataclass class LineSpec(Spec): begin: Vector2D end: Vector2D is_region: bool = False
[docs] def draw(self, aperture: meta_ap.Aperture): return aperture.line(self)
[docs] def bbox(self, aperture: meta_ap.Aperture): return aperture.line_bbox(self)
[docs]@dataclass class ArcSpec(Spec): begin: Vector2D end: Vector2D center: Vector2D is_region: bool = False
[docs] def draw(self, aperture: meta_ap.Aperture): return aperture.arc(self)
[docs] def bbox(self, aperture: meta_ap.Aperture): return aperture.arc_bbox(self)
[docs] def get_radius(spec: ArcSpec): return (spec.begin - spec.center).length()