mirror of
https://github.com/johndoe6345789/bamboogenerator.git
synced 2026-04-24 13:24:54 +00:00
Refactor primitives as dataclasses
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from parametric_cad.core import tm
|
||||
from .base import Primitive
|
||||
|
||||
|
||||
@dataclass
|
||||
class Box(Primitive):
|
||||
def __init__(self, width: float, depth: float, height: float) -> None:
|
||||
"""Axis-aligned rectangular prism primitive."""
|
||||
|
||||
width: float
|
||||
depth: float
|
||||
height: float
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
super().__init__()
|
||||
self.width = width
|
||||
self.depth = depth
|
||||
self.height = height
|
||||
|
||||
def _create_mesh(self) -> tm.Trimesh:
|
||||
return tm.creation.box(extents=(self.width, self.depth, self.height))
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
from typing import Sequence
|
||||
from dataclasses import dataclass
|
||||
|
||||
from parametric_cad.core import tm
|
||||
from .base import Primitive
|
||||
|
||||
|
||||
@dataclass
|
||||
class Cylinder(Primitive):
|
||||
def __init__(self, radius: float, height: float, sections: int = 32) -> None:
|
||||
"""Circular cylinder primitive."""
|
||||
|
||||
radius: float
|
||||
height: float
|
||||
sections: int = 32
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
super().__init__()
|
||||
self.radius = radius
|
||||
self.height = height
|
||||
self.sections = sections
|
||||
|
||||
def _create_mesh(self) -> tm.Trimesh:
|
||||
return tm.creation.cylinder(
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from parametric_cad.core import tm
|
||||
from .base import Primitive
|
||||
|
||||
|
||||
@dataclass
|
||||
class Sphere(Primitive):
|
||||
def __init__(self, radius: float, subdivisions: int = 3) -> None:
|
||||
"""Icosphere primitive."""
|
||||
|
||||
radius: float
|
||||
subdivisions: int = 3
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
super().__init__()
|
||||
self.radius = radius
|
||||
self.subdivisions = subdivisions
|
||||
|
||||
def _create_mesh(self) -> tm.Trimesh:
|
||||
return tm.creation.icosphere(
|
||||
|
||||
Reference in New Issue
Block a user