Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions inkcut/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ def path_element_to_point(element):

def trailing_angle(path):
if path.elementCount() < 10:
return path.angleAtPercent(1)
return path.angleAtPercent(0.99999)
else:
p = QPainterPath()
p.reserve(10)
pos = path.elementCount() - 5
while pos < path.elementCount():
add_item_to_path(p, path.elementAt(pos), pos, path)
pos += 1
return p.angleAtPercent(1)
return p.angleAtPercent(0.99999)


def rect_to_path(rect):
Expand Down
43 changes: 34 additions & 9 deletions inkcut/device/filters/blade_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,26 @@ def add_continuity_correction(self, offset_path, blade_path, point):
next_angle = sp.angleAtPercent(1)

# Direction of last move
angle = trailing_angle(blade_path)
if blade_path.elementCount() > 1:
angle = trailing_angle(blade_path)
else:
#initial corner, blade orientation unknown
#extend in the initial movement direction, might result in a bit of overcut
angle = sp.angleAtPercent(0.00001)
a = radians(angle)
offset_path.moveTo(cur - QPointF(cos(a), -sin(a)) * self.config.offset)

# If not continuous it needs corrected with an arc
if isnan(angle) or isnan(next_angle):
return
if abs(angle - next_angle) > self.config.cutoff:
diff = next_angle - angle
if diff > 180:
diff -= 360
if diff < -180:
diff += 360
if abs(diff) > self.config.cutoff:
r = self.config.offset
circle_size = QPointF(r, r)
diff = next_angle - angle
if diff > 180:
diff -= 360
if diff < -180:
diff += 360
offset_path.arcTo(
QRectF(cur - circle_size, QSizeF(2 * r, 2 * r)), angle, diff
)
Expand Down Expand Up @@ -202,11 +209,18 @@ def process_quad(self, offset_path, blade_path, params, quality):
r = self.config.offset
p0 = blade_path.currentPosition()
p1, p2 = params
self.add_continuity_correction(offset_path, blade_path, p1)

curve = QPainterPath()
curve.moveTo(p0)
curve.quadTo(*params)

first_anchor = p1
start_offset = 0
if (p0-p1).manhattanLength() <= 0.00000000001:
start_offset = 0.00001
first_anchor = curve.pointAtPercent(start_offset)
self.add_continuity_correction(offset_path, blade_path, first_anchor)

p = QPainterPath()
p.moveTo(p0)

Expand All @@ -220,6 +234,8 @@ def process_quad(self, offset_path, blade_path, params, quality):
for point in polygon:
p.lineTo(point)
t = curve.percentAtLength(p.length())
if t == 0:
t = start_offset
angle = curve.angleAtPercent(t)
a = radians(angle)
dx, dy = r * cos(a), -r * sin(a)
Expand All @@ -232,11 +248,18 @@ def process_cubic(self, offset_path, blade_path, params, quality):
r = self.config.offset
p0 = blade_path.currentPosition()
p1, p2, p3 = params
self.add_continuity_correction(offset_path, blade_path, p1)

curve = QPainterPath()
curve.moveTo(p0)
curve.cubicTo(*params)

first_anchor = p1
start_offset = 0
if (p0 - p1).manhattanLength() <= 0.00000000001:
start_offset = 0.00001
first_anchor = curve.pointAtPercent(start_offset)
self.add_continuity_correction(offset_path, blade_path, first_anchor)

p = QPainterPath()
p.moveTo(p0)

Expand All @@ -250,6 +273,8 @@ def process_cubic(self, offset_path, blade_path, params, quality):
for point in polygon:
p.lineTo(point)
t = curve.percentAtLength(p.length())
if t == 0:
t = start_offset
angle = curve.angleAtPercent(t)
a = radians(angle)
dx, dy = r * cos(a), -r * sin(a)
Expand Down
Loading