mirror of
https://github.com/csirmaz/openscad-py.git
synced 2025-06-22 18:53:29 +02:00
Split code into separate class files
This commit is contained in:
parent
ffbee53da3
commit
9d24a2c85f
24 changed files with 1062 additions and 830 deletions
35
openscad_py/circle.py
Normal file
35
openscad_py/circle.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
from typing import Union as TUnion
|
||||
from typing import List
|
||||
import math
|
||||
|
||||
from openscad_py.object_ import Object
|
||||
|
||||
|
||||
class Circle(Object):
|
||||
"""A 2D primitive, circle.
|
||||
Creates a circle (or regular polygon) at the origin.
|
||||
|
||||
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#circle
|
||||
"""
|
||||
|
||||
def __init__(self, r: float, fn: TUnion[int, None] = None):
|
||||
self.r = r
|
||||
self.fn = fn
|
||||
# $fa, $fs, $fn
|
||||
|
||||
@classmethod
|
||||
def triangle(cls, r):
|
||||
"""Create a regular triangle"""
|
||||
return cls(r=r, fn=3)
|
||||
|
||||
@classmethod
|
||||
def regular_polygon(cls, r, sides: int):
|
||||
"""Create a regular polygon"""
|
||||
return cls(r=r, fn=sides)
|
||||
|
||||
def render(self) -> str:
|
||||
fnstr = '' if self.fn is None else f", $fn={self.fn}"
|
||||
return f"circle(r={self.r}{fnstr});"
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue