Add links

This commit is contained in:
Elod Csirmaz 2024-12-01 15:51:43 +00:00
parent bb7155a5fd
commit dc0a58c342
9 changed files with 68 additions and 23 deletions

5
Makefile Normal file
View file

@ -0,0 +1,5 @@
documentation:
pdoc --html -f -o doc --config show_inherited_members=True openscad_py

View file

@ -7,8 +7,11 @@ from openscad_py.object_ import Object
class Color(Object): class Color(Object):
"""Represents a color applied to an object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#color
"""
def __init__(self, child: Object, r, g, b, a=1.): def __init__(self, child: Object, r: float, g: float, b: float, a: float = 1.):
self.color = [r, g, b, a] self.color = [r, g, b, a]
self.child = child self.child = child
@ -16,4 +19,3 @@ class Color(Object):
"""Render the object into OpenSCAD code""" """Render the object into OpenSCAD code"""
return f"color(c=[{','.join([str(c) for c in self.color])}]){{ {self.child.render()} }}" return f"color(c=[{','.join([str(c) for c in self.color])}]){{ {self.child.render()} }}"

View file

@ -8,7 +8,9 @@ from openscad_py.collection import Collection
class Difference(Object): class Difference(Object):
"""Represents a difference""" """Represents a difference.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#difference
"""
def __init__(self, subject: Object, tool: TUnion[list, Object]): def __init__(self, subject: Object, tool: TUnion[list, Object]):
self.subject = subject self.subject = subject

View file

@ -8,7 +8,9 @@ from openscad_py.collection import Collection
class Intersection(Object): class Intersection(Object):
"""Represents an intersection applied to an object (usually a collection of objects)""" """Represents an intersection applied to an object (usually a collection of objects).
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#intersection
"""
def __init__(self, child: TUnion[Object, list]): def __init__(self, child: TUnion[Object, list]):
self.child = Collection.c(child) self.child = Collection.c(child)

View file

@ -7,13 +7,14 @@ from openscad_py.point import Point
class Object: class Object:
"""Abstract class for an SCAD object""" """Base class for an SCAD object. Defines convenience methods to apply transformations."""
def _center(self) -> str: def _center(self) -> str:
"""Render the `center` flag into string"""
return ('true' if self.center else 'false') return ('true' if self.center else 'false')
def _add(self, obj): def _add(self, obj: 'Object'):
"""Add an object, forming a collection""" """Add an object, forming a Collection"""
from openscad_py.collection import Collection from openscad_py.collection import Collection
return Collection([self, obj]) return Collection([self, obj])
@ -22,64 +23,88 @@ class Object:
raise Exception("abstract method") raise Exception("abstract method")
def translate(self, v: TUnion[list, Point]) -> 'Object': def translate(self, v: TUnion[list, Point]) -> 'Object':
"""Apply a translation""" """Apply a translation and return a new object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#translate
"""
from openscad_py.translate import Translate from openscad_py.translate import Translate
return Translate(v=v, child=self) return Translate(v=v, child=self)
def move(self, v: TUnion[list, Point]) -> 'Object': def move(self, v: TUnion[list, Point]) -> 'Object':
"""Apply a translation""" """Apply a translation and return a new object. Synonym of `translate()`"""
from openscad_py.translate import Translate from openscad_py.translate import Translate
return Translate(v=v, child=self) return Translate(v=v, child=self)
def rotate(self, a, v: TUnion[list, Point]) -> 'Object': def rotate(self, a, v: TUnion[list, Point]) -> 'Object':
"""Apply a rotation""" """Apply a rotation and return a new object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#rotate
"""
from openscad_py.rotate import Rotate from openscad_py.rotate import Rotate
return Rotate(a=a, v=v, child=self) return Rotate(a=a, v=v, child=self)
def scale(self, v: TUnion[list, Point, float]) -> 'Object': def scale(self, v: TUnion[list, Point, float]) -> 'Object':
"""Apply scaling. Accepts a single float for uniform scaling""" """Apply scaling and return a new object. Accepts a vector (a Point object or a list of floats)
or a single float for uniform scaling.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#scale
"""
from openscad_py.scale import Scale from openscad_py.scale import Scale
return Scale(v=v, child=self) return Scale(v=v, child=self)
def color(self, r, g, b, a=1.) -> 'Object': def color(self, r, g, b, a=1.) -> 'Object':
"""Apply a color""" """Apply a color and return a new object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#color
"""
from openscad_py.color import Color from openscad_py.color import Color
return Color(r=r, g=g, b=b, a=a, child=self) return Color(r=r, g=g, b=b, a=a, child=self)
def extrude(self, height, convexity = 10, center: bool = False) -> 'Object': def extrude(self, height, convexity = 10, center: bool = False) -> 'Object':
"""Apply a linear extrusion, """Apply a linear extrusion and return a new object.
If center is false the linear extrusion Z range is from 0 to height; if it is true, the range is from -height/2 to height/2.""" If `center` is false, the linear extrusion Z range is from 0 to height;
if it is true, the range is from -height/2 to height/2.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion
"""
from openscad_py.linear_extrude import LinearExtrude from openscad_py.linear_extrude import LinearExtrude
return LinearExtrude(height=height, child=self, convexity=convexity, center=center) return LinearExtrude(height=height, child=self, convexity=convexity, center=center)
def rotate_extrude(self, angle, convexity = 10) -> 'Object': def rotate_extrude(self, angle, convexity = 10) -> 'Object':
"""Apply a rotational extrusion. For all points x >= 0 must be true.""" """Apply a rotational extrusion and return a new object. For all points x >= 0 must be true.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion
"""
from openscad_py.rotate_extrude import RotateExtrude from openscad_py.rotate_extrude import RotateExtrude
return RotateExtrude(angle=angle, child=self, convexity=convexity) return RotateExtrude(angle=angle, child=self, convexity=convexity)
def radial_offset(self, r): def radial_offset(self, r):
"""A new 2d interior or exterior outline from an existing outline""" """Return a new 2D interior or exterior outline from an existing outline.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#offset
"""
from openscad_py.radial_offset import RadialOffset from openscad_py.radial_offset import RadialOffset
return RadialOffset(r=r, child=self) return RadialOffset(r=r, child=self)
def delta_offset(self, delta, chamfer=False): def delta_offset(self, delta, chamfer=False):
"""A new 2d interior or exterior outline from an existing outline""" """Return a new 2D interior or exterior outline from an existing outline.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#offset
"""
from openscad_py.delta_offset import DeltaOffset from openscad_py.delta_offset import DeltaOffset
return DeltaOffset(delta=delta, child=self, chamfer=chamfer) return DeltaOffset(delta=delta, child=self, chamfer=chamfer)
def diff(self, tool: TUnion[list, 'Object']) -> 'Object': def diff(self, tool: TUnion[list, 'Object']) -> 'Object':
"""Remove from the object using a difference operator""" """Remove from the object using a difference operator, and return a new object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#difference
"""
from openscad_py.difference import Difference from openscad_py.difference import Difference
return Difference(subject=self, tool=tool) return Difference(subject=self, tool=tool)
def union(self, objects: TUnion[list, 'Object']) -> 'Object': def union(self, objects: TUnion[list, 'Object']) -> 'Object':
"""Form the union of self and an object or list of objects""" """Form the union of self and an object or list of objects, and return a new object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#union
"""
from openscad_py.union import Union from openscad_py.union import Union
from openscad_py.collection import Collection from openscad_py.collection import Collection
return Union(child=Collection.c(objects)._add(self)) return Union(child=Collection.c(objects)._add(self))
def intersection(self, objects: TUnion[list, 'Object']) -> 'Object': def intersection(self, objects: TUnion[list, 'Object']) -> 'Object':
"""Get the intersection of self and an object of list of objects""" """Get the intersection of self and an object of list of objects, and return a new object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#intersection
"""
from openscad_py.intersection import Intersection from openscad_py.intersection import Intersection
from openscad_py.collection import Collection from openscad_py.collection import Collection
return Intersection(child=Collection.c(objects)._add(self)) return Intersection(child=Collection.c(objects)._add(self))

View file

@ -8,7 +8,9 @@ from openscad_py.object_ import Object
class Rotate(Object): class Rotate(Object):
"""Represents a rotation transformation applied to an object""" """Represents a rotation transformation applied to an object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#rotate
"""
def __init__(self, a, v: TUnion[list, Point], child: Object): def __init__(self, a, v: TUnion[list, Point], child: Object):
self.a = a self.a = a

View file

@ -8,6 +8,9 @@ from openscad_py.object_ import Object
class Scale(Object): class Scale(Object):
"""Represents a scale transformation applied to an object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#scale
"""
def __init__(self, v: TUnion[list, Point, float, int], child: Object): def __init__(self, v: TUnion[list, Point, float, int], child: Object):
if isinstance(v, float) or isinstance(v, int): if isinstance(v, float) or isinstance(v, int):

View file

@ -8,7 +8,9 @@ from openscad_py.object_ import Object
class Translate(Object): class Translate(Object):
"""Represents a translation transformation applied to an object""" """Represents a translation transformation applied to an object.
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#translate
"""
def __init__(self, v: TUnion[list, Point], child: Object): def __init__(self, v: TUnion[list, Point], child: Object):
self.v = Point.c(v) self.v = Point.c(v)

View file

@ -9,7 +9,9 @@ from openscad_py.collection import Collection
class Union(Object): class Union(Object):
"""Represents a union applied to an object (usually a collection of objects)""" """Represents a union applied to an object (usually a collection of objects).
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#union
"""
def __init__(self, child: TUnion[Object, list]): def __init__(self, child: TUnion[Object, list]):
self.child = Collection.c(child) self.child = Collection.c(child)