FlexBox3: Use .move()

Use .edgeCorner() instead of own implementation
This commit is contained in:
Florian Festi 2018-10-19 22:11:18 +02:00
parent f7c2d91e42
commit 397cc81690
1 changed files with 44 additions and 36 deletions

View File

@ -41,17 +41,12 @@ class FlexBox3(Boxes):
"--c", action="store", type=float, default=1.0, "--c", action="store", type=float, default=1.0,
dest="d", help="clearance of the lid") dest="d", help="clearance of the lid")
def rectangleCorner(self, edge1=None, edge2=None): def flexBoxSide(self, x, y, r, callback=None, move=None):
edge1 = self.edges.get(edge1, edge1) t = self.thickness
edge2 = self.edges.get(edge2, edge2) if self.move(x+2*t, y+t, move, True):
if edge2: return
self.edge(edge2.startwidth())
self.corner(90)
if edge1:
self.edge(edge1.endwidth())
@restore self.moveTo(t, t)
def flexBoxSide(self, x, y, r, callback=None):
self.cc(callback, 0) self.cc(callback, 0)
self.edges["f"](x) self.edges["f"](x)
self.corner(90, 0) self.corner(90, 0)
@ -65,17 +60,28 @@ class FlexBox3(Boxes):
self.edges["f"](y) self.edges["f"](y)
self.corner(90) self.corner(90)
def surroundingWall(self): self.move(x+2*t, y+t, move)
def surroundingWall(self, move=None):
x, y, z, r, d = self.x, self.y, self.z, self.radius, self.d x, y, z, r, d = self.x, self.y, self.z, self.radius, self.d
t = self.thickness
tw = x + y - 2*r + self.c4 + 2*t + d
th = z + 4*t + 2*d
if self.move(tw, th, move, True):
return
self.moveTo(t, d + t)
self.edges["F"](y - r, False) self.edges["F"](y - r, False)
self.edges["X"](self.c4, z + 2 * self.thickness) self.edges["X"](self.c4, z + 2 * t)
self.corner(-90) self.corner(-90)
self.edge(d) self.edge(d)
self.corner(90) self.corner(90)
self.edges["f"](x - r + d) self.edges["f"](x - r + d)
self.corner(90) self.corner(90)
self.edges["f"](z + 2 * self.thickness + 2 * d) self.edges["f"](z + 2 * t + 2 * d)
self.corner(90) self.corner(90)
self.edges["f"](x - r + d) self.edges["f"](x - r + d)
self.corner(90) self.corner(90)
@ -84,37 +90,46 @@ class FlexBox3(Boxes):
self.edge(self.c4) self.edge(self.c4)
self.edges["F"](y - r) self.edges["F"](y - r)
self.corner(90) self.corner(90)
self.edge(self.thickness) self.edge(t)
self.edges["f"](z) self.edges["f"](z)
self.edge(self.thickness) self.edge(t)
self.corner(90) self.corner(90)
@restore self.move(tw, th, move)
def lidSide(self):
def lidSide(self, move=None):
x, y, z, r, d, h = self.x, self.y, self.z, self.radius, self.d, self.h x, y, z, r, d, h = self.x, self.y, self.z, self.radius, self.d, self.h
t = self.thickness t = self.thickness
r2 = r + t if r + t <= h + t else h + t r2 = r + t if r + t <= h + t else h + t
self.moveTo(self.thickness, 0)
if r < h: if r < h:
r2 = r + t r2 = r + t
base_l = x + 2 * t
if self.move(h+t, base_l+t, move, True):
return
self.edge(h + self.thickness - r2) self.edge(h + self.thickness - r2)
self.corner(90, r2) self.corner(90, r2)
self.edge(r - r2 + 2 * t) self.edge(r - r2 + 2 * t)
base_l = x + 2 * t
else: else:
a = math.acos((r-h)/(r+t)) a = math.acos((r-h)/(r+t))
ang = math.degrees(a) ang = math.degrees(a)
base_l = x + (r+t) * math.sin(a) - r base_l = x + (r+t) * math.sin(a) - r
if self.move(h+t, base_l+t, move, True):
return
self.corner(90-ang) self.corner(90-ang)
self.corner(ang, r+t) self.corner(ang, r+t)
self.edges["F"](x - r) self.edges["F"](x - r)
self.rectangleCorner("F", "f") self.edgeCorner("F", "f")
self.edges["g"](h) self.edges["g"](h)
self.rectangleCorner("f", "e") self.edgeCorner("f", "e")
self.edge(base_l) self.edge(base_l)
self.corner(90) self.corner(90)
self.move(h+t, base_l+t, move)
def render(self): def render(self):
if self.outside: if self.outside:
self.x = self.adjustSize(self.x) self.x = self.adjustSize(self.x)
@ -137,25 +152,18 @@ class FlexBox3(Boxes):
space=1., surroundingspaces=1) space=1., surroundingspaces=1)
s.edgeObjects(self, "gGH") s.edgeObjects(self, "gGH")
self.moveTo(2 * self.thickness, self.thickness + 2 * d)
self.ctx.save() self.ctx.save()
self.surroundingWall() self.surroundingWall(move="right")
self.moveTo(x + y - 2 * r + self.c4 + 2 * self.thickness, -2 * d - self.thickness)
self.rectangularWall(x, z, edges="FFFF", move="right") self.rectangularWall(x, z, edges="FFFF", move="right")
self.rectangularWall(h, z + 2 * (d + self.thickness), edges="GeGF", move="right") self.rectangularWall(h, z + 2 * (d + self.thickness), edges="GeGF", move="right")
self.lidSide() self.lidSide(move="right")
self.moveTo(2 * h + 5 * self.thickness, 0) self.lidSide(move="mirror right")
self.ctx.scale(-1, 1)
self.lidSide()
self.ctx.restore() self.ctx.restore()
self.moveTo(0, z + 4 * self.thickness + 2 * d)
self.flexBoxSide(x, y, r) self.surroundingWall(move="up only")
self.moveTo(2 * x + 3 * self.thickness, 2 * d)
self.ctx.scale(-1, 1) self.flexBoxSide(x, y, r, move="right")
self.flexBoxSide(x, y, r) self.flexBoxSide(x, y, r, move="mirror right")
self.ctx.scale(-1, 1)
self.moveTo(2 * self.thickness, -self.thickness)
self.rectangularWall(z, y, edges="fFeF") self.rectangularWall(z, y, edges="fFeF")
self.close() self.close()