Support drawing multiple rectangularTriangle(s) at once
Add support for setting diagonal edge type
This commit is contained in:
parent
cc42a8e165
commit
610a26736e
|
@ -97,7 +97,7 @@ class NutHole:
|
||||||
"M4": (7, 3.2),
|
"M4": (7, 3.2),
|
||||||
"M5": (8, 4.7),
|
"M5": (8, 4.7),
|
||||||
"M6": (10, 5.2),
|
"M6": (10, 5.2),
|
||||||
"M8": (13, 6.8),
|
"M8": (13.7, 6.8),
|
||||||
"M10": (16, 8.4),
|
"M10": (16, 8.4),
|
||||||
"M12": (18, 10.8),
|
"M12": (18, 10.8),
|
||||||
"M14": (21, 12.8),
|
"M14": (21, 12.8),
|
||||||
|
@ -1203,7 +1203,7 @@ class Boxes:
|
||||||
|
|
||||||
self.move(overallwidth, overallheight, move)
|
self.move(overallwidth, overallheight, move)
|
||||||
|
|
||||||
def rectangularTriangle(self, x, y, edges="ee",
|
def rectangularTriangle(self, x, y, edges="eee", num=1,
|
||||||
bedBolts=None, bedBoltSettings=None,
|
bedBolts=None, bedBoltSettings=None,
|
||||||
callback=None,
|
callback=None,
|
||||||
move=None):
|
move=None):
|
||||||
|
@ -1212,25 +1212,43 @@ class Boxes:
|
||||||
|
|
||||||
:param x: width
|
:param x: width
|
||||||
:param y: height
|
:param y: height
|
||||||
:param edges: (Default value = "ee") bottom, right
|
:param edges: (Default value = "eee") bottom, right[, diagonal]
|
||||||
|
:param num: (Default value = 1) number of triangles
|
||||||
:param bedBolts: (Default value = None)
|
:param bedBolts: (Default value = None)
|
||||||
:param bedBoltSettings: (Default value = None)
|
:param bedBoltSettings: (Default value = None)
|
||||||
:param callback: (Default value = None)
|
:param callback: (Default value = None)
|
||||||
:param move: (Default value = None)
|
:param move: (Default value = None)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if len(edges) != 2:
|
|
||||||
raise ValueError("two edges required")
|
|
||||||
edges = [self.edges.get(e, e) for e in edges]
|
edges = [self.edges.get(e, e) for e in edges]
|
||||||
edges.append(self.edges["e"]) # append for wrapping around
|
if len(edges) == 2:
|
||||||
overallwidth = x + edges[-1].spacing() + edges[1].spacing()
|
edges.append(self.edges["e"])
|
||||||
overallheight = y + edges[0].spacing() + edges[2].spacing()
|
if len(edges) != 3:
|
||||||
|
raise ValueError("two or three edges required")
|
||||||
|
|
||||||
|
width = x + edges[-1].spacing() + edges[1].spacing()
|
||||||
|
height = y + edges[0].spacing() + edges[2].spacing()
|
||||||
|
if num > 1:
|
||||||
|
width += edges[-1].spacing() + edges[1].spacing() + 2*self.spacing
|
||||||
|
height += edges[0].spacing() + edges[2].spacing() + self.spacing
|
||||||
|
|
||||||
|
overallwidth = width * (num // 2 + num % 2)
|
||||||
|
overallheight = height
|
||||||
|
|
||||||
alpha = math.degrees(math.atan(y/float(x)))
|
alpha = math.degrees(math.atan(y/float(x)))
|
||||||
|
|
||||||
if self.move(overallwidth, overallheight, move, before=True):
|
if self.move(overallwidth, overallheight, move, before=True):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.moveTo(edges[-1].spacing(), edges[0].margin())
|
if num > 1:
|
||||||
|
self.moveTo(self.spacing + edges[-1].spacing())
|
||||||
|
|
||||||
|
for n in range(num):
|
||||||
|
self.moveTo(edges[-1].spacing()+self.spacing, edges[0].margin())
|
||||||
|
if n % 2 == 1:
|
||||||
|
self.moveTo(2*edges[1].spacing()+self.spacing, 0)
|
||||||
|
if num > 1:
|
||||||
|
self.moveTo(edges[1].spacing(), 0)
|
||||||
for i, l in enumerate((x, y)):
|
for i, l in enumerate((x, y)):
|
||||||
self.cc(callback, i, y=edges[i].startwidth() + self.burn)
|
self.cc(callback, i, y=edges[i].startwidth() + self.burn)
|
||||||
edges[i](l,
|
edges[i](l,
|
||||||
|
@ -1240,9 +1258,14 @@ class Boxes:
|
||||||
|
|
||||||
self.corner(alpha)
|
self.corner(alpha)
|
||||||
self.cc(callback, 2)
|
self.cc(callback, 2)
|
||||||
self.edge((x**2+y**2)**0.5)
|
edges[2]((x**2+y**2)**0.5)
|
||||||
self.corner(180-alpha)
|
self.corner(180-alpha)
|
||||||
|
|
||||||
self.ctx.stroke()
|
self.ctx.stroke()
|
||||||
|
|
||||||
|
if n % 2:
|
||||||
|
self.moveTo(-edges[1].spacing()-2*self.spacing-edges[-1].spacing(), height-edges[1].spacing(), 180)
|
||||||
|
else:
|
||||||
|
self.moveTo(width+1*edges[1].spacing()-self.spacing-2*edges[-1].spacing(), height-edges[1].spacing(), 180)
|
||||||
|
|
||||||
|
|
||||||
self.move(overallwidth, overallheight, move)
|
self.move(overallwidth, overallheight, move)
|
||||||
|
|
Loading…
Reference in New Issue