From ae02c3efc2fd1a55565d0febb400190dd4ef4523 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Mon, 6 Jul 2015 22:59:58 +0200 Subject: [PATCH] Fixed error with handling clipper no longer need to comment clipper error alerts --- library/clipper.js | 6 +++--- settings/user_settings.json | 2 +- src/paths.js | 12 ++++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/library/clipper.js b/library/clipper.js index cccf9ac..0da4886 100755 --- a/library/clipper.js +++ b/library/clipper.js @@ -4884,8 +4884,8 @@ else ClipperLib.Clipper.Round = R2; // eg. browser.chrome || browser.firefox || browser.opera ClipperLib.Clipper.TopX = function (edge, currentY) { - //if (edge.Bot == edge.Curr) console.warn ("edge.Bot = edge.Curr"); - //if (edge.Bot == edge.Top) console.warn ("edge.Bot = edge.Top"); + //if (edge.Bot == edge.Curr) alert ("edge.Bot = edge.Curr"); + //if (edge.Bot == edge.Top) alert ("edge.Bot = edge.Top"); if (currentY == edge.Top.Y) return edge.Top.X; return edge.Bot.X + ClipperLib.Clipper.Round(edge.Dx * (currentY - edge.Bot.Y)); @@ -6596,7 +6596,7 @@ } catch (err) { - //console.warn(err.message); + console.warn(err.message); } }; // --------------------------------- diff --git a/settings/user_settings.json b/settings/user_settings.json index 3ad72f7..7dc1cd8 100644 --- a/settings/user_settings.json +++ b/settings/user_settings.json @@ -3,7 +3,7 @@ "bottomThickness": 0.4, "topThickness": 0.8, "shellThickness": 0.4, - "brimOffset": 5.0, + "brimOffset": 4.0, "fillGridSize": 5.0, "infillOverlap": 0.5, "travelSpeed": 200.0, diff --git a/src/paths.js b/src/paths.js index 80e1e48..27babea 100644 --- a/src/paths.js +++ b/src/paths.js @@ -32,14 +32,16 @@ D3D.Paths.prototype.setPaths = function (paths) { D3D.Paths.prototype._clip = function (path, type) { 'use strict'; - var solution = new ClipperLib.Paths(); + var solution = new ClipperLib.PolyTree(); var clipper = new ClipperLib.Clipper(); clipper.AddPaths(this, ClipperLib.PolyType.ptSubject, this.closed); clipper.AddPaths(path, ClipperLib.PolyType.ptClip, path.closed); clipper.Execute(type, solution); - return new D3D.Paths(solution, this.closed); + var paths = this.closed ? ClipperLib.Clipper.ClosedPathsFromPolyTree(solution) : ClipperLib.Clipper.OpenPathsFromPolyTree(solution); + + return new D3D.Paths(paths, this.closed); }; D3D.Paths.prototype.union = function (path) { 'use strict'; @@ -236,12 +238,14 @@ D3D.Paths.prototype.draw = function (context, color) { //context.fillText(i, point.X*2, point.Y*2); context.beginPath(); - var length = this.closed ? (shape.length + 1) : shape.length; - for (var j = 0; j < length; j ++) { + for (var j = 0; j < shape.length; j ++) { var point = shape[j % shape.length]; context.lineTo(point.X*2, point.Y*2); } + if (this.closed) { + context.closePath(); + } context.stroke(); } }; \ No newline at end of file