Skip to content

Commit

Permalink
add center parameter to box
Browse files Browse the repository at this point in the history
  • Loading branch information
bat52 committed Dec 26, 2024
1 parent 6fa4775 commit 1fa28df
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/b1scad/scad2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def shape_set(self, t):

@_('CUBE LPAREN vector RPAREN')
def shape(self, p):
return f"self.api.box({p.vector})"
return f"self.api.box({p.vector}, center=False)"

@_('CUBE LPAREN NUMBER RPAREN')
def shape(self, p):
return f"self.api.box({p.NUMBER},{p.NUMBER},{p.NUMBER})"
return f"self.api.box({p.NUMBER},{p.NUMBER},{p.NUMBER}, center=False)"

@_('SPHERE LPAREN NUMBER RPAREN')
def shape(self, p):
Expand Down
7 changes: 5 additions & 2 deletions src/pylele/api/bpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ def add_material(obj: bpy.types.Object, name: str, color: tuple[int, int, int]):
def sphere(self, rad: float) -> BlenderShape:
return BlenderBall(rad, self)

def box(self, ln: float, wth: float, ht: float) -> BlenderShape:
return BlenderBox(ln, wth, ht, self)
def box(self, ln: float, wth: float, ht: float, center: bool = True) -> BlenderShape:
retval = BlenderBox(ln, wth, ht, self)
if center:
return retval
return retval.mv(-l / 2, -wth / 2, -ht / 2)

def cone_x(self, l: float, r1: float, r2: float) -> BlenderShape:
return BlenderConeX(l, r1, r2, self).mv(l / 2, 0, 0)
Expand Down
7 changes: 5 additions & 2 deletions src/pylele/api/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ def export_best_multishapes(
def sphere(self, rad: float) -> CQShape:
return CQBall(rad, self)

def box(self, ln: float, wth: float, ht: float) -> CQShape:
return CQBox(ln, wth, ht, self)
def box(self, ln: float, wth: float, ht: float, center: bool = True) -> CQShape:
retval = CQBox(ln, wth, ht, self)
if center:
return retval
return retval.mv(ln/2,wth/2,ht/2)

def cone_x(self, l: float, r1: float, r2: float) -> CQShape:
return CQCone(l, r1, r2, (1, 0, 0), self)
Expand Down
10 changes: 6 additions & 4 deletions src/pylele/api/mf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def export(self, shape: MFShape, path: Union[str, Path],fmt=".stl") -> None:
def sphere(self, rad: float) -> MFShape:
return MFBall(rad, self)

def box(self, l: float, wth: float, ht: float) -> MFShape:
return MFBox(l, wth, ht, self)
def box(self, l: float, wth: float, ht: float, center: bool = True) -> MFShape:
return MFBox(l, wth, ht, center, self)

def cone_x(self, l: float, r1: float, r2: float) -> MFShape:
return MFConeZ(l, r1, r2, None, self).rotate_y(90)
Expand Down Expand Up @@ -240,12 +240,14 @@ def __init__(self, rad: float, api: MFShapeAPI):


class MFBox(MFShape):
def __init__(self, l: float, wth: float, ht: float, api: MFShapeAPI):
def __init__(self, l: float, wth: float, ht: float, center: bool, api: MFShapeAPI ):
super().__init__(api)
self.ln = l
self.wth = wth
self.ht = ht
self.solid = Manifold.cube((l, wth, ht)).translate((-l / 2, -wth / 2, -ht / 2))
self.solid = Manifold.cube((l, wth, ht))
if center:
self.solid = self.solid.translate((-l / 2, -wth / 2, -ht / 2))


class MFConeZ(MFShape):
Expand Down
2 changes: 1 addition & 1 deletion src/pylele/api/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def export_best(self, shape: MockShape, path: Union[str, Path]) -> None:
def sphere(self, rad: float) -> MockShape:
return MockShape(self)

def box(self, l: float, wth: float, ht: float) -> MockShape:
def box(self, l: float, wth: float, ht: float, center: bool = True) -> MockShape:
return MockShape(self)

def cone_x(self, l: float, r1: float, r2: float) -> MockShape:
Expand Down
7 changes: 5 additions & 2 deletions src/pylele/api/sp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ def export_scad(self, shape: Sp2Shape, path: Union[str, Path]) -> str:
def sphere(self, rad: float) -> Sp2Shape:
return Sp2Ball(rad, self)

def box(self, l: float, wth: float, ht: float) -> Sp2Shape:
return Sp2Box(l, wth, ht, self).mv(-l / 2, -wth / 2, -ht / 2)
def box(self, l: float, wth: float, ht: float, center: bool = True) -> Sp2Shape:
retval = Sp2Box(l, wth, ht, self).
if center:
return retval.mv(-l / 2, -wth / 2, -ht / 2)
return retval

def cone_x(self, l: float, r1: float, r2: float) -> Sp2Shape:
return Sp2Cone(l, r1, r2, direction="X", sides=None, api=self).mv(l / 2, 0, 0)
Expand Down
7 changes: 5 additions & 2 deletions src/pylele/api/tm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ def export_best_multishapes(
def sphere(self, rad: float) -> TMShape:
return TMBall(rad, self)

def box(self, l: float, wth: float, ht: float) -> TMShape:
return TMBox(l, wth, ht, self)
def box(self, l: float, wth: float, ht: float, center: bool = True) -> TMShape:
retval = TMBox(l, wth, ht, self)
if center:
return retval
return retval.mv(-l / 2, -wth / 2, -ht / 2)

def cone_x(self, l: float, r1: float, r2: float) -> TMShape:
return TMCone(l, r1, r2, None, self.rotZtoX, self)
Expand Down

0 comments on commit 1fa28df

Please sign in to comment.