Skip to content

Commit af94bdd

Browse files
committed
new build with Dome and fix to combine
1 parent 206f61a commit af94bdd

File tree

5 files changed

+132
-32
lines changed

5 files changed

+132
-32
lines changed

index.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,10 @@ var MakerJs;
568568
*/
569569
var pathAreEqualMap = {};
570570
pathAreEqualMap[MakerJs.pathType.Line] = function (line1, line2) {
571-
return MakerJs.point.areEqual(line1.end, line2.end);
571+
return (MakerJs.point.areEqual(line1.origin, line2.origin) && MakerJs.point.areEqual(line1.end, line2.end)) || (MakerJs.point.areEqual(line1.origin, line2.end) && MakerJs.point.areEqual(line1.end, line2.origin));
572572
};
573573
pathAreEqualMap[MakerJs.pathType.Circle] = function (circle1, circle2) {
574-
return circle1.radius == circle2.radius;
574+
return MakerJs.point.areEqual(circle1.origin, circle2.origin) && circle1.radius == circle2.radius;
575575
};
576576
pathAreEqualMap[MakerJs.pathType.Arc] = function (arc1, arc2) {
577577
return pathAreEqualMap[MakerJs.pathType.Circle](arc1, arc2) && MakerJs.angle.areEqual(arc1.startAngle, arc2.startAngle) && MakerJs.angle.areEqual(arc1.endAngle, arc2.endAngle);
@@ -585,7 +585,7 @@ var MakerJs;
585585
*/
586586
function areEqual(path1, path2) {
587587
var result = false;
588-
if (path1.type == path2.type && MakerJs.point.areEqual(path1.origin, path2.origin)) {
588+
if (path1.type == path2.type) {
589589
var fn = pathAreEqualMap[path1.type];
590590
if (fn) {
591591
result = fn(path1, path2);
@@ -1139,7 +1139,7 @@ var MakerJs;
11391139
function breakAlongForeignPath(segments, overlappedSegments, foreignPath) {
11401140
if (MakerJs.path.areEqual(segments[0].path, foreignPath)) {
11411141
segments[0].overlapped = true;
1142-
segments[0].overlappedEqual = true;
1142+
segments[0].duplicate = true;
11431143
overlappedSegments.push(segments[0]);
11441144
return;
11451145
}
@@ -1283,7 +1283,7 @@ var MakerJs;
12831283
function checkForEqualOverlaps(crossedPathsA, crossedPathsB) {
12841284
function compareSegments(segment1, segment2) {
12851285
if (MakerJs.path.areEqual(segment1.path, segment2.path)) {
1286-
segment1.overlappedEqual = segment2.overlappedEqual = true;
1286+
segment1.duplicate = segment2.duplicate = true;
12871287
}
12881288
}
12891289
function compareAll(segment) {
@@ -1298,7 +1298,7 @@ var MakerJs;
12981298
/**
12991299
* @private
13001300
*/
1301-
function addOrDeleteSegments(crossedPath, includeInside, includeOutside, firstPass) {
1301+
function addOrDeleteSegments(crossedPath, includeInside, includeOutside, keepDuplicates) {
13021302
function addSegment(model, pathIdBase, segment) {
13031303
var id = model_1.getSimilarPathId(model, pathIdBase);
13041304
model.paths[id] = segment.path;
@@ -1311,8 +1311,8 @@ var MakerJs;
13111311
//delete the original, its segments will be added
13121312
delete crossedPath.modelContext.paths[crossedPath.pathId];
13131313
for (var i = 0; i < crossedPath.segments.length; i++) {
1314-
if (crossedPath.segments[i].overlappedEqual) {
1315-
if (firstPass) {
1314+
if (crossedPath.segments[i].duplicate) {
1315+
if (keepDuplicates) {
13161316
addSegment(crossedPath.modelContext, crossedPath.pathId, crossedPath.segments[i]);
13171317
}
13181318
}
@@ -1330,14 +1330,16 @@ var MakerJs;
13301330
* @param includeAOutsideB Flag to include paths from modelA which are outside of modelB.
13311331
* @param includeBInsideA Flag to include paths from modelB which are inside of modelA.
13321332
* @param includeBOutsideA Flag to include paths from modelB which are outside of modelA.
1333+
* @param keepDuplicates Flag to include paths which are duplicate in both models.
13331334
* @param farPoint Optional point of reference which is outside the bounds of both models.
13341335
*/
1335-
function combine(modelA, modelB, includeAInsideB, includeAOutsideB, includeBInsideA, includeBOutsideA, farPoint) {
1336+
function combine(modelA, modelB, includeAInsideB, includeAOutsideB, includeBInsideA, includeBOutsideA, keepDuplicates, farPoint) {
1337+
if (keepDuplicates === void 0) { keepDuplicates = true; }
13361338
var pathsA = breakAllPathsAtIntersections(modelA, modelB, farPoint);
13371339
var pathsB = breakAllPathsAtIntersections(modelB, modelA, farPoint);
13381340
checkForEqualOverlaps(pathsA.overlappedSegments, pathsB.overlappedSegments);
13391341
for (var i = 0; i < pathsA.crossedPaths.length; i++) {
1340-
addOrDeleteSegments(pathsA.crossedPaths[i], includeAInsideB, includeAOutsideB, true);
1342+
addOrDeleteSegments(pathsA.crossedPaths[i], includeAInsideB, includeAOutsideB, keepDuplicates);
13411343
}
13421344
for (var i = 0; i < pathsB.crossedPaths.length; i++) {
13431345
addOrDeleteSegments(pathsB.crossedPaths[i], includeBInsideA, includeBOutsideA);
@@ -3383,6 +3385,35 @@ var MakerJs;
33833385
})(models = MakerJs.models || (MakerJs.models = {}));
33843386
})(MakerJs || (MakerJs = {}));
33853387
var MakerJs;
3388+
(function (MakerJs) {
3389+
var models;
3390+
(function (models) {
3391+
var Dome = (function () {
3392+
function Dome(width, height, radius) {
3393+
if (radius === void 0) { radius = Math.min(width / 2, height); }
3394+
this.paths = {};
3395+
var w2 = width / 2;
3396+
var wt = Math.max(w2 - radius, 0);
3397+
var hr = Math.max(height - radius, 0);
3398+
this.paths["Bottom"] = new MakerJs.paths.Line([-w2, 0], [w2, 0]);
3399+
if (hr) {
3400+
this.paths["Left"] = new MakerJs.paths.Line([-w2, 0], [-w2, hr]);
3401+
this.paths["Right"] = new MakerJs.paths.Line([w2, 0], [w2, hr]);
3402+
}
3403+
if (radius > 0) {
3404+
this.paths["TopLeft"] = new MakerJs.paths.Arc([-wt, hr], radius, 90, 180);
3405+
this.paths["TopRight"] = new MakerJs.paths.Arc([wt, hr], radius, 0, 90);
3406+
}
3407+
if (wt) {
3408+
this.paths["Top"] = new MakerJs.paths.Line([-wt, height], [wt, height]);
3409+
}
3410+
}
3411+
return Dome;
3412+
})();
3413+
models.Dome = Dome;
3414+
})(models = MakerJs.models || (MakerJs.models = {}));
3415+
})(MakerJs || (MakerJs = {}));
3416+
var MakerJs;
33863417
(function (MakerJs) {
33873418
var models;
33883419
(function (models) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "makerjs",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.",
55
"main": "index.js",
66
"scripts": {

target/js/browser.maker.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,10 @@ var MakerJs;
569569
*/
570570
var pathAreEqualMap = {};
571571
pathAreEqualMap[MakerJs.pathType.Line] = function (line1, line2) {
572-
return MakerJs.point.areEqual(line1.end, line2.end);
572+
return (MakerJs.point.areEqual(line1.origin, line2.origin) && MakerJs.point.areEqual(line1.end, line2.end)) || (MakerJs.point.areEqual(line1.origin, line2.end) && MakerJs.point.areEqual(line1.end, line2.origin));
573573
};
574574
pathAreEqualMap[MakerJs.pathType.Circle] = function (circle1, circle2) {
575-
return circle1.radius == circle2.radius;
575+
return MakerJs.point.areEqual(circle1.origin, circle2.origin) && circle1.radius == circle2.radius;
576576
};
577577
pathAreEqualMap[MakerJs.pathType.Arc] = function (arc1, arc2) {
578578
return pathAreEqualMap[MakerJs.pathType.Circle](arc1, arc2) && MakerJs.angle.areEqual(arc1.startAngle, arc2.startAngle) && MakerJs.angle.areEqual(arc1.endAngle, arc2.endAngle);
@@ -586,7 +586,7 @@ var MakerJs;
586586
*/
587587
function areEqual(path1, path2) {
588588
var result = false;
589-
if (path1.type == path2.type && MakerJs.point.areEqual(path1.origin, path2.origin)) {
589+
if (path1.type == path2.type) {
590590
var fn = pathAreEqualMap[path1.type];
591591
if (fn) {
592592
result = fn(path1, path2);
@@ -1140,7 +1140,7 @@ var MakerJs;
11401140
function breakAlongForeignPath(segments, overlappedSegments, foreignPath) {
11411141
if (MakerJs.path.areEqual(segments[0].path, foreignPath)) {
11421142
segments[0].overlapped = true;
1143-
segments[0].overlappedEqual = true;
1143+
segments[0].duplicate = true;
11441144
overlappedSegments.push(segments[0]);
11451145
return;
11461146
}
@@ -1284,7 +1284,7 @@ var MakerJs;
12841284
function checkForEqualOverlaps(crossedPathsA, crossedPathsB) {
12851285
function compareSegments(segment1, segment2) {
12861286
if (MakerJs.path.areEqual(segment1.path, segment2.path)) {
1287-
segment1.overlappedEqual = segment2.overlappedEqual = true;
1287+
segment1.duplicate = segment2.duplicate = true;
12881288
}
12891289
}
12901290
function compareAll(segment) {
@@ -1299,7 +1299,7 @@ var MakerJs;
12991299
/**
13001300
* @private
13011301
*/
1302-
function addOrDeleteSegments(crossedPath, includeInside, includeOutside, firstPass) {
1302+
function addOrDeleteSegments(crossedPath, includeInside, includeOutside, keepDuplicates) {
13031303
function addSegment(model, pathIdBase, segment) {
13041304
var id = model_1.getSimilarPathId(model, pathIdBase);
13051305
model.paths[id] = segment.path;
@@ -1312,8 +1312,8 @@ var MakerJs;
13121312
//delete the original, its segments will be added
13131313
delete crossedPath.modelContext.paths[crossedPath.pathId];
13141314
for (var i = 0; i < crossedPath.segments.length; i++) {
1315-
if (crossedPath.segments[i].overlappedEqual) {
1316-
if (firstPass) {
1315+
if (crossedPath.segments[i].duplicate) {
1316+
if (keepDuplicates) {
13171317
addSegment(crossedPath.modelContext, crossedPath.pathId, crossedPath.segments[i]);
13181318
}
13191319
}
@@ -1331,14 +1331,16 @@ var MakerJs;
13311331
* @param includeAOutsideB Flag to include paths from modelA which are outside of modelB.
13321332
* @param includeBInsideA Flag to include paths from modelB which are inside of modelA.
13331333
* @param includeBOutsideA Flag to include paths from modelB which are outside of modelA.
1334+
* @param keepDuplicates Flag to include paths which are duplicate in both models.
13341335
* @param farPoint Optional point of reference which is outside the bounds of both models.
13351336
*/
1336-
function combine(modelA, modelB, includeAInsideB, includeAOutsideB, includeBInsideA, includeBOutsideA, farPoint) {
1337+
function combine(modelA, modelB, includeAInsideB, includeAOutsideB, includeBInsideA, includeBOutsideA, keepDuplicates, farPoint) {
1338+
if (keepDuplicates === void 0) { keepDuplicates = true; }
13371339
var pathsA = breakAllPathsAtIntersections(modelA, modelB, farPoint);
13381340
var pathsB = breakAllPathsAtIntersections(modelB, modelA, farPoint);
13391341
checkForEqualOverlaps(pathsA.overlappedSegments, pathsB.overlappedSegments);
13401342
for (var i = 0; i < pathsA.crossedPaths.length; i++) {
1341-
addOrDeleteSegments(pathsA.crossedPaths[i], includeAInsideB, includeAOutsideB, true);
1343+
addOrDeleteSegments(pathsA.crossedPaths[i], includeAInsideB, includeAOutsideB, keepDuplicates);
13421344
}
13431345
for (var i = 0; i < pathsB.crossedPaths.length; i++) {
13441346
addOrDeleteSegments(pathsB.crossedPaths[i], includeBInsideA, includeBOutsideA);
@@ -3384,6 +3386,35 @@ var MakerJs;
33843386
})(models = MakerJs.models || (MakerJs.models = {}));
33853387
})(MakerJs || (MakerJs = {}));
33863388
var MakerJs;
3389+
(function (MakerJs) {
3390+
var models;
3391+
(function (models) {
3392+
var Dome = (function () {
3393+
function Dome(width, height, radius) {
3394+
if (radius === void 0) { radius = Math.min(width / 2, height); }
3395+
this.paths = {};
3396+
var w2 = width / 2;
3397+
var wt = Math.max(w2 - radius, 0);
3398+
var hr = Math.max(height - radius, 0);
3399+
this.paths["Bottom"] = new MakerJs.paths.Line([-w2, 0], [w2, 0]);
3400+
if (hr) {
3401+
this.paths["Left"] = new MakerJs.paths.Line([-w2, 0], [-w2, hr]);
3402+
this.paths["Right"] = new MakerJs.paths.Line([w2, 0], [w2, hr]);
3403+
}
3404+
if (radius > 0) {
3405+
this.paths["TopLeft"] = new MakerJs.paths.Arc([-wt, hr], radius, 90, 180);
3406+
this.paths["TopRight"] = new MakerJs.paths.Arc([wt, hr], radius, 0, 90);
3407+
}
3408+
if (wt) {
3409+
this.paths["Top"] = new MakerJs.paths.Line([-wt, height], [wt, height]);
3410+
}
3411+
}
3412+
return Dome;
3413+
})();
3414+
models.Dome = Dome;
3415+
})(models = MakerJs.models || (MakerJs.models = {}));
3416+
})(MakerJs || (MakerJs = {}));
3417+
var MakerJs;
33873418
(function (MakerJs) {
33883419
var models;
33893420
(function (models) {

target/js/node.maker.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,10 @@ var MakerJs;
568568
*/
569569
var pathAreEqualMap = {};
570570
pathAreEqualMap[MakerJs.pathType.Line] = function (line1, line2) {
571-
return MakerJs.point.areEqual(line1.end, line2.end);
571+
return (MakerJs.point.areEqual(line1.origin, line2.origin) && MakerJs.point.areEqual(line1.end, line2.end)) || (MakerJs.point.areEqual(line1.origin, line2.end) && MakerJs.point.areEqual(line1.end, line2.origin));
572572
};
573573
pathAreEqualMap[MakerJs.pathType.Circle] = function (circle1, circle2) {
574-
return circle1.radius == circle2.radius;
574+
return MakerJs.point.areEqual(circle1.origin, circle2.origin) && circle1.radius == circle2.radius;
575575
};
576576
pathAreEqualMap[MakerJs.pathType.Arc] = function (arc1, arc2) {
577577
return pathAreEqualMap[MakerJs.pathType.Circle](arc1, arc2) && MakerJs.angle.areEqual(arc1.startAngle, arc2.startAngle) && MakerJs.angle.areEqual(arc1.endAngle, arc2.endAngle);
@@ -585,7 +585,7 @@ var MakerJs;
585585
*/
586586
function areEqual(path1, path2) {
587587
var result = false;
588-
if (path1.type == path2.type && MakerJs.point.areEqual(path1.origin, path2.origin)) {
588+
if (path1.type == path2.type) {
589589
var fn = pathAreEqualMap[path1.type];
590590
if (fn) {
591591
result = fn(path1, path2);
@@ -1139,7 +1139,7 @@ var MakerJs;
11391139
function breakAlongForeignPath(segments, overlappedSegments, foreignPath) {
11401140
if (MakerJs.path.areEqual(segments[0].path, foreignPath)) {
11411141
segments[0].overlapped = true;
1142-
segments[0].overlappedEqual = true;
1142+
segments[0].duplicate = true;
11431143
overlappedSegments.push(segments[0]);
11441144
return;
11451145
}
@@ -1283,7 +1283,7 @@ var MakerJs;
12831283
function checkForEqualOverlaps(crossedPathsA, crossedPathsB) {
12841284
function compareSegments(segment1, segment2) {
12851285
if (MakerJs.path.areEqual(segment1.path, segment2.path)) {
1286-
segment1.overlappedEqual = segment2.overlappedEqual = true;
1286+
segment1.duplicate = segment2.duplicate = true;
12871287
}
12881288
}
12891289
function compareAll(segment) {
@@ -1298,7 +1298,7 @@ var MakerJs;
12981298
/**
12991299
* @private
13001300
*/
1301-
function addOrDeleteSegments(crossedPath, includeInside, includeOutside, firstPass) {
1301+
function addOrDeleteSegments(crossedPath, includeInside, includeOutside, keepDuplicates) {
13021302
function addSegment(model, pathIdBase, segment) {
13031303
var id = model_1.getSimilarPathId(model, pathIdBase);
13041304
model.paths[id] = segment.path;
@@ -1311,8 +1311,8 @@ var MakerJs;
13111311
//delete the original, its segments will be added
13121312
delete crossedPath.modelContext.paths[crossedPath.pathId];
13131313
for (var i = 0; i < crossedPath.segments.length; i++) {
1314-
if (crossedPath.segments[i].overlappedEqual) {
1315-
if (firstPass) {
1314+
if (crossedPath.segments[i].duplicate) {
1315+
if (keepDuplicates) {
13161316
addSegment(crossedPath.modelContext, crossedPath.pathId, crossedPath.segments[i]);
13171317
}
13181318
}
@@ -1330,14 +1330,16 @@ var MakerJs;
13301330
* @param includeAOutsideB Flag to include paths from modelA which are outside of modelB.
13311331
* @param includeBInsideA Flag to include paths from modelB which are inside of modelA.
13321332
* @param includeBOutsideA Flag to include paths from modelB which are outside of modelA.
1333+
* @param keepDuplicates Flag to include paths which are duplicate in both models.
13331334
* @param farPoint Optional point of reference which is outside the bounds of both models.
13341335
*/
1335-
function combine(modelA, modelB, includeAInsideB, includeAOutsideB, includeBInsideA, includeBOutsideA, farPoint) {
1336+
function combine(modelA, modelB, includeAInsideB, includeAOutsideB, includeBInsideA, includeBOutsideA, keepDuplicates, farPoint) {
1337+
if (keepDuplicates === void 0) { keepDuplicates = true; }
13361338
var pathsA = breakAllPathsAtIntersections(modelA, modelB, farPoint);
13371339
var pathsB = breakAllPathsAtIntersections(modelB, modelA, farPoint);
13381340
checkForEqualOverlaps(pathsA.overlappedSegments, pathsB.overlappedSegments);
13391341
for (var i = 0; i < pathsA.crossedPaths.length; i++) {
1340-
addOrDeleteSegments(pathsA.crossedPaths[i], includeAInsideB, includeAOutsideB, true);
1342+
addOrDeleteSegments(pathsA.crossedPaths[i], includeAInsideB, includeAOutsideB, keepDuplicates);
13411343
}
13421344
for (var i = 0; i < pathsB.crossedPaths.length; i++) {
13431345
addOrDeleteSegments(pathsB.crossedPaths[i], includeBInsideA, includeBOutsideA);
@@ -3383,6 +3385,35 @@ var MakerJs;
33833385
})(models = MakerJs.models || (MakerJs.models = {}));
33843386
})(MakerJs || (MakerJs = {}));
33853387
var MakerJs;
3388+
(function (MakerJs) {
3389+
var models;
3390+
(function (models) {
3391+
var Dome = (function () {
3392+
function Dome(width, height, radius) {
3393+
if (radius === void 0) { radius = Math.min(width / 2, height); }
3394+
this.paths = {};
3395+
var w2 = width / 2;
3396+
var wt = Math.max(w2 - radius, 0);
3397+
var hr = Math.max(height - radius, 0);
3398+
this.paths["Bottom"] = new MakerJs.paths.Line([-w2, 0], [w2, 0]);
3399+
if (hr) {
3400+
this.paths["Left"] = new MakerJs.paths.Line([-w2, 0], [-w2, hr]);
3401+
this.paths["Right"] = new MakerJs.paths.Line([w2, 0], [w2, hr]);
3402+
}
3403+
if (radius > 0) {
3404+
this.paths["TopLeft"] = new MakerJs.paths.Arc([-wt, hr], radius, 90, 180);
3405+
this.paths["TopRight"] = new MakerJs.paths.Arc([wt, hr], radius, 0, 90);
3406+
}
3407+
if (wt) {
3408+
this.paths["Top"] = new MakerJs.paths.Line([-wt, height], [wt, height]);
3409+
}
3410+
}
3411+
return Dome;
3412+
})();
3413+
models.Dome = Dome;
3414+
})(models = MakerJs.models || (MakerJs.models = {}));
3415+
})(MakerJs || (MakerJs = {}));
3416+
var MakerJs;
33863417
(function (MakerJs) {
33873418
var models;
33883419
(function (models) {

0 commit comments

Comments
 (0)