Skip to content

Commit d77a913

Browse files
committed
Merge pull request #61 from Microsoft/dev
Dev
2 parents 1d23d7f + af94bdd commit d77a913

File tree

13 files changed

+291
-73
lines changed

13 files changed

+291
-73
lines changed

debug/viewer.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<script src="../src/core/intersect.js"></script>
3737
<script src="../src/models/BoltCircle.js"></script>
3838
<script src="../src/models/BoltRectangle.js"></script>
39+
<script src="../src/models/Dome.js"></script>
3940
<script src="../src/models/RoundRectangle.js"></script>
4041
<script src="../src/models/Oval.js"></script>
4142
<script src="../src/models/OvalArc.js"></script>
@@ -62,7 +63,8 @@
6263
<label for="selectModelCode">model: </label>
6364
<select id="selectModelCode" onchange="Viewer.loadModelCode(this.value)">
6465
<option>polygonstackbox</option>
65-
<option>stackbox</option>
66+
<option>Rimbox</option>
67+
<option>starbox</option>
6668
<option>combine</option>
6769
<option>logo</option>
6870
<option>smile</option>

debug/viewer.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var Viewer = {
1010

1111
//apply slider parameters
1212
if (typeof index !== 'undefined') {
13-
Viewer.Params[index] = makerjs.round(arg, .001);
13+
Viewer.Params[index] = arg;
1414
}
1515

1616
var model = makerjs.kit.construct(Viewer.Constructor, Viewer.Params);
@@ -155,17 +155,35 @@ var Viewer = {
155155
var label = new makerjs.exporter.XmlTag('label', { "for": id, title: attrs.title });
156156
label.innerText = attrs.title + ': ';
157157

158-
if (attrs.type == 'range') {
159-
attrs.title = attrs.value;
160-
var input = new makerjs.exporter.XmlTag('input', attrs);
161-
input.attrs['onchange'] = 'this.title=this.value;Viewer.Refresh(' + i + ', this.valueAsNumber)';
162-
input.attrs['id'] = id;
158+
var input = null;
163159

164-
var div = new makerjs.exporter.XmlTag('div');
165-
div.innerText = label.toString() + input.toString();
166-
div.innerTextEscaped = true;
167-
paramsHtml += div.toString();
160+
switch (attrs.type) {
161+
162+
case 'range':
163+
attrs.title = attrs.value;
164+
input = new makerjs.exporter.XmlTag('input', attrs);
165+
input.attrs['onchange'] = 'this.title=this.value;Viewer.Refresh(' + i + ', makerjs.round(this.valueAsNumber, .001))';
166+
input.attrs['id'] = id;
167+
168+
break;
169+
170+
case 'bool':
171+
input = new makerjs.exporter.XmlTag('input', {
172+
id: id,
173+
type: 'checkbox',
174+
checked: attrs.value ? 'checked' : '',
175+
onchange: 'Viewer.Refresh(' + i + ', this.checked)'
176+
});
177+
178+
break;
168179
}
180+
181+
if (!input) continue;
182+
183+
var div = new makerjs.exporter.XmlTag('div');
184+
div.innerText = label.toString() + input.toString();
185+
div.innerTextEscaped = true;
186+
paramsHtml += div.toString();
169187
}
170188
}
171189
document.getElementById("params").innerHTML = paramsHtml;

examples/Rimbox.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/// <reference path="typings/tsd.d.ts" />
2+
var makerjs = require('makerjs');
3+
var RimboxCorner = (function () {
4+
function RimboxCorner(holeRadius, rimThickness) {
5+
var rim = Math.min(rimThickness, holeRadius);
6+
var hr = holeRadius + rim;
7+
this.paths = {
8+
centerRound: new makerjs.paths.Arc([0, 0], hr, 0, 90),
9+
hFillet: new makerjs.paths.Arc([0, hr + holeRadius], holeRadius, 180, 270),
10+
wFillet: new makerjs.paths.Arc([hr + holeRadius, 0], holeRadius, 180, 270)
11+
};
12+
}
13+
return RimboxCorner;
14+
})();
15+
var RimboxInner = (function () {
16+
function RimboxInner(width, height, holeRadius, rimThickness) {
17+
var mm = makerjs.model;
18+
var corner = new RimboxCorner(holeRadius, rimThickness);
19+
this.models = {
20+
bottomLeft: corner,
21+
bottomRight: mm.move(mm.mirror(corner, true, false), [width, 0]),
22+
topLeft: mm.move(mm.mirror(corner, false, true), [0, height]),
23+
topRight: mm.move(mm.mirror(corner, true, true), [width, height])
24+
};
25+
var line = makerjs.paths.Line;
26+
var rim = Math.min(rimThickness, holeRadius);
27+
var d = 2 * holeRadius + rim;
28+
this.paths = {
29+
bottom: new line([d, -holeRadius], [width - d, -holeRadius]),
30+
top: new line([d, height + holeRadius], [width - d, height + holeRadius]),
31+
left: new line([-holeRadius, d], [-holeRadius, height - d]),
32+
right: new line([width + holeRadius, d], [width + holeRadius, height - d])
33+
};
34+
}
35+
return RimboxInner;
36+
})();
37+
var Rimbox = (function () {
38+
function Rimbox(width, height, holeRadius, rimThickness, hollow) {
39+
if (arguments.length == 0) {
40+
var defaultValues = makerjs.kit.getParameterValues(Rimbox);
41+
width = defaultValues.shift();
42+
height = defaultValues.shift();
43+
holeRadius = defaultValues.shift();
44+
rimThickness = defaultValues.shift();
45+
}
46+
var mm = makerjs.models;
47+
var cornerRadius = holeRadius + rimThickness;
48+
var c2 = cornerRadius * 2;
49+
this.models = {
50+
bolts: new mm.BoltRectangle(width, height, holeRadius),
51+
outer: new mm.RoundRectangle(width + c2, height + c2, cornerRadius)
52+
};
53+
if (hollow) {
54+
this.models['inner'] = new RimboxInner(width, height, holeRadius, rimThickness);
55+
}
56+
this.models['outer'].origin = [-cornerRadius, -cornerRadius];
57+
}
58+
return Rimbox;
59+
})();
60+
Rimbox.metaParameters = [
61+
{ title: "width", type: "range", min: 10, max: 500, value: 120 },
62+
{ title: "height", type: "range", min: 10, max: 500, value: 100 },
63+
{ title: "holeRadius", type: "range", min: 1, max: 20, value: 3 },
64+
{ title: "rimThickness", type: "range", min: 1, max: 20, value: 2 },
65+
{ title: "hollow", type: "bool", value: true }
66+
];
67+
module.exports = Rimbox;

examples/combine.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
function combine(angle) {
2+
function combine(angle, add) {
33

44
var star1 = new makerjs.models.Oval(50, 100);
55

@@ -31,11 +31,12 @@ function combine(angle) {
3131
star2: star2
3232
};
3333

34-
makerjs.model.combine(star1, star2, false, true, false, true);
34+
makerjs.model.combine(star1, star2, false, true, !add, add, add);
3535
}
3636

3737
combine.metaParameters = [
38-
{ title: "angle", type: "range", min: -180, max: 180, step: 1, value: 40 }
38+
{ title: "angle", type: "range", min: -180, max: 180, step: 1, value: 40 },
39+
{ title: "add", type: "bool", value: true }
3940
];
4041

4142

examples/stackbox.js renamed to examples/starbox.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="typings/tsd.d.ts" />
22
var makerjs = require('makerjs');
3-
var stackboxCorner = (function () {
4-
function stackboxCorner(holeRadius, rimThickness) {
3+
var starboxCorner = (function () {
4+
function starboxCorner(holeRadius, rimThickness) {
55
var rim = Math.min(rimThickness, holeRadius);
66
var hr = holeRadius + rim;
77
this.paths = {
@@ -10,12 +10,12 @@ var stackboxCorner = (function () {
1010
wFillet: new makerjs.paths.Arc([hr + holeRadius, 0], holeRadius, 180, 270)
1111
};
1212
}
13-
return stackboxCorner;
13+
return starboxCorner;
1414
})();
15-
var stackboxInner = (function () {
16-
function stackboxInner(width, height, holeRadius, rimThickness) {
15+
var starboxInner = (function () {
16+
function starboxInner(width, height, holeRadius, rimThickness) {
1717
var mm = makerjs.model;
18-
var corner = new stackboxCorner(holeRadius, rimThickness);
18+
var corner = new starboxCorner(holeRadius, rimThickness);
1919
this.models = {
2020
bottomLeft: corner,
2121
bottomRight: mm.move(mm.mirror(corner, true, false), [width, 0]),
@@ -32,12 +32,12 @@ var stackboxInner = (function () {
3232
right: new line([width + holeRadius, d], [width + holeRadius, height - d])
3333
};
3434
}
35-
return stackboxInner;
35+
return starboxInner;
3636
})();
37-
var stackbox = (function () {
38-
function stackbox(width, height, holeRadius, rimThickness, angle) {
37+
var starbox = (function () {
38+
function starbox(width, height, holeRadius, rimThickness, angle) {
3939
if (arguments.length == 0) {
40-
var defaultValues = makerjs.kit.getParameterValues(stackbox);
40+
var defaultValues = makerjs.kit.getParameterValues(starbox);
4141
width = defaultValues.shift();
4242
height = defaultValues.shift();
4343
holeRadius = defaultValues.shift();
@@ -49,7 +49,7 @@ var stackbox = (function () {
4949
this.models = {
5050
bolts: new mm.BoltRectangle(width, height, holeRadius),
5151
outer: new mm.RoundRectangle(width + c2, height + c2, cornerRadius),
52-
inner: new stackboxInner(width, height, holeRadius, rimThickness)
52+
inner: new starboxInner(width, height, holeRadius, rimThickness)
5353
};
5454
this.models['outer'].origin = [-cornerRadius, -cornerRadius];
5555

@@ -64,13 +64,13 @@ var stackbox = (function () {
6464

6565
makerjs.model.combine(this.models.inner, star, false, true, true, false);
6666
}
67-
return stackbox;
67+
return starbox;
6868
})();
69-
stackbox.metaParameters = [
69+
starbox.metaParameters = [
7070
{ title: "width", type: "range", min: 10, max: 500, value: 120 },
7171
{ title: "height", type: "range", min: 10, max: 500, value: 100 },
7272
{ title: "holeRadius", type: "range", min: 1, max: 20, value: 3 },
7373
{ title: "rimThickness", type: "range", min: 1, max: 20, value: 2 },
7474
{ title: "angle", type: "range", min: -180, max: 180, value: 45 }
7575
];
76-
module.exports = stackbox;
76+
module.exports = starbox;

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": {

0 commit comments

Comments
 (0)