Move finger calculation into FingerJointBase class

This commit is contained in:
Florian Festi 2016-10-30 19:45:38 +01:00
parent dc045eefe2
commit 7203320e70
1 changed files with 25 additions and 19 deletions

View File

@ -440,8 +440,25 @@ Values:
"edge_width": 1.0, "edge_width": 1.0,
} }
class FingerJointBase:
class FingerJointEdge(BaseEdge): def calcFingers(self, length, bedBolts):
space, finger = self.settings.space, self.settings.finger
fingers = int((length - (self.settings.surroundingspaces - 1) * space) //
(space + finger))
if not finger:
fingers = 0
if bedBolts:
fingers = bedBolts.numFingers(fingers)
leftover = length - fingers * (space + finger) + space
if fingers <= 0:
fingers = 0
leftover = length
return fingers, leftover
class FingerJointEdge(BaseEdge, FingerJointBase):
"""Finger joint edge """ """Finger joint edge """
char = 'f' char = 'f'
description = "Finger Joint" description = "Finger Joint"
@ -450,20 +467,13 @@ class FingerJointEdge(BaseEdge):
def __call__(self, length, bedBolts=None, bedBoltSettings=None, **kw): def __call__(self, length, bedBolts=None, bedBoltSettings=None, **kw):
positive = self.positive positive = self.positive
space, finger = self.settings.space, self.settings.finger
fingers = int((length - (self.settings.surroundingspaces - 1) * space) //
(space + finger))
if bedBolts: s, f, thickness = self.settings.space, self.settings.finger, self.thickness
fingers = bedBolts.numFingers(fingers)
leftover = length - fingers * (space + finger) + space
s, f, thickness = space, finger, self.thickness
p = 1 if positive else -1 p = 1 if positive else -1
if fingers <= 0: fingers, leftover = self.calcFingers(length, bedBolts)
fingers = 0
leftover = length
self.edge(leftover / 2.0) self.edge(leftover / 2.0)
@ -508,7 +518,7 @@ class FingerJointEdgeCounterPart(FingerJointEdge):
return 0.0 return 0.0
class FingerHoles: class FingerHoles(FingerJointBase):
"""Hole matching a finger joint edge""" """Hole matching a finger joint edge"""
def __init__(self, boxes, settings): def __init__(self, boxes, settings):
@ -532,14 +542,10 @@ class FingerHoles:
self.boxes.moveTo(x, y, angle) self.boxes.moveTo(x, y, angle)
s, f = self.settings.space, self.settings.finger s, f = self.settings.space, self.settings.finger
fingers = int((length - (self.settings.surroundingspaces - 1) * s) //
(s + f))
if bedBolts:
fingers = bedBolts.numFingers(fingers)
leftover = length - fingers * (s + f) - s
b = self.boxes.burn b = self.boxes.burn
fingers, leftover = self.calcFingers(length, bedBolts)
if self.boxes.debug: if self.boxes.debug:
self.ctx.rectangle(0, -self.settings.width / 2 + b, self.ctx.rectangle(0, -self.settings.width / 2 + b,
length, self.settings.width - 2 * b) length, self.settings.width - 2 * b)
@ -549,7 +555,7 @@ class FingerHoles:
if bedBolts and bedBolts.drawBolt(i): if bedBolts and bedBolts.drawBolt(i):
self.boxes.hole(pos + 0.5 * s, 0, d * 0.5) self.boxes.hole(pos + 0.5 * s, 0, d * 0.5)
self.boxes.rectangularHole(pos + s + 0.5 * f, 0, self.boxes.rectangularHole(pos + 0.5 * f, 0,
f, self.settings.width) f, self.settings.width)
self.ctx.restore() self.ctx.restore()