Skip to content
Merged

Dev #61

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: 3 additions & 1 deletion debug/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<script src="../src/core/intersect.js"></script>
<script src="../src/models/BoltCircle.js"></script>
<script src="../src/models/BoltRectangle.js"></script>
<script src="../src/models/Dome.js"></script>
<script src="../src/models/RoundRectangle.js"></script>
<script src="../src/models/Oval.js"></script>
<script src="../src/models/OvalArc.js"></script>
Expand All @@ -62,7 +63,8 @@
<label for="selectModelCode">model: </label>
<select id="selectModelCode" onchange="Viewer.loadModelCode(this.value)">
<option>polygonstackbox</option>
<option>stackbox</option>
<option>Rimbox</option>
<option>starbox</option>
<option>combine</option>
<option>logo</option>
<option>smile</option>
Expand Down
38 changes: 28 additions & 10 deletions debug/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Viewer = {

//apply slider parameters
if (typeof index !== 'undefined') {
Viewer.Params[index] = makerjs.round(arg, .001);
Viewer.Params[index] = arg;
}

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

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

var div = new makerjs.exporter.XmlTag('div');
div.innerText = label.toString() + input.toString();
div.innerTextEscaped = true;
paramsHtml += div.toString();
switch (attrs.type) {

case 'range':
attrs.title = attrs.value;
input = new makerjs.exporter.XmlTag('input', attrs);
input.attrs['onchange'] = 'this.title=this.value;Viewer.Refresh(' + i + ', makerjs.round(this.valueAsNumber, .001))';
input.attrs['id'] = id;

break;

case 'bool':
input = new makerjs.exporter.XmlTag('input', {
id: id,
type: 'checkbox',
checked: attrs.value ? 'checked' : '',
onchange: 'Viewer.Refresh(' + i + ', this.checked)'
});

break;
}

if (!input) continue;

var div = new makerjs.exporter.XmlTag('div');
div.innerText = label.toString() + input.toString();
div.innerTextEscaped = true;
paramsHtml += div.toString();
}
}
document.getElementById("params").innerHTML = paramsHtml;
Expand Down
67 changes: 67 additions & 0 deletions examples/Rimbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/// <reference path="typings/tsd.d.ts" />
var makerjs = require('makerjs');
var RimboxCorner = (function () {
function RimboxCorner(holeRadius, rimThickness) {
var rim = Math.min(rimThickness, holeRadius);
var hr = holeRadius + rim;
this.paths = {
centerRound: new makerjs.paths.Arc([0, 0], hr, 0, 90),
hFillet: new makerjs.paths.Arc([0, hr + holeRadius], holeRadius, 180, 270),
wFillet: new makerjs.paths.Arc([hr + holeRadius, 0], holeRadius, 180, 270)
};
}
return RimboxCorner;
})();
var RimboxInner = (function () {
function RimboxInner(width, height, holeRadius, rimThickness) {
var mm = makerjs.model;
var corner = new RimboxCorner(holeRadius, rimThickness);
this.models = {
bottomLeft: corner,
bottomRight: mm.move(mm.mirror(corner, true, false), [width, 0]),
topLeft: mm.move(mm.mirror(corner, false, true), [0, height]),
topRight: mm.move(mm.mirror(corner, true, true), [width, height])
};
var line = makerjs.paths.Line;
var rim = Math.min(rimThickness, holeRadius);
var d = 2 * holeRadius + rim;
this.paths = {
bottom: new line([d, -holeRadius], [width - d, -holeRadius]),
top: new line([d, height + holeRadius], [width - d, height + holeRadius]),
left: new line([-holeRadius, d], [-holeRadius, height - d]),
right: new line([width + holeRadius, d], [width + holeRadius, height - d])
};
}
return RimboxInner;
})();
var Rimbox = (function () {
function Rimbox(width, height, holeRadius, rimThickness, hollow) {
if (arguments.length == 0) {
var defaultValues = makerjs.kit.getParameterValues(Rimbox);
width = defaultValues.shift();
height = defaultValues.shift();
holeRadius = defaultValues.shift();
rimThickness = defaultValues.shift();
}
var mm = makerjs.models;
var cornerRadius = holeRadius + rimThickness;
var c2 = cornerRadius * 2;
this.models = {
bolts: new mm.BoltRectangle(width, height, holeRadius),
outer: new mm.RoundRectangle(width + c2, height + c2, cornerRadius)
};
if (hollow) {
this.models['inner'] = new RimboxInner(width, height, holeRadius, rimThickness);
}
this.models['outer'].origin = [-cornerRadius, -cornerRadius];
}
return Rimbox;
})();
Rimbox.metaParameters = [
{ title: "width", type: "range", min: 10, max: 500, value: 120 },
{ title: "height", type: "range", min: 10, max: 500, value: 100 },
{ title: "holeRadius", type: "range", min: 1, max: 20, value: 3 },
{ title: "rimThickness", type: "range", min: 1, max: 20, value: 2 },
{ title: "hollow", type: "bool", value: true }
];
module.exports = Rimbox;
7 changes: 4 additions & 3 deletions examples/combine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

function combine(angle) {
function combine(angle, add) {

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

Expand Down Expand Up @@ -31,11 +31,12 @@ function combine(angle) {
star2: star2
};

makerjs.model.combine(star1, star2, false, true, false, true);
makerjs.model.combine(star1, star2, false, true, !add, add, add);
}

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


Expand Down
28 changes: 14 additions & 14 deletions examples/stackbox.js → examples/starbox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path="typings/tsd.d.ts" />
var makerjs = require('makerjs');
var stackboxCorner = (function () {
function stackboxCorner(holeRadius, rimThickness) {
var starboxCorner = (function () {
function starboxCorner(holeRadius, rimThickness) {
var rim = Math.min(rimThickness, holeRadius);
var hr = holeRadius + rim;
this.paths = {
Expand All @@ -10,12 +10,12 @@ var stackboxCorner = (function () {
wFillet: new makerjs.paths.Arc([hr + holeRadius, 0], holeRadius, 180, 270)
};
}
return stackboxCorner;
return starboxCorner;
})();
var stackboxInner = (function () {
function stackboxInner(width, height, holeRadius, rimThickness) {
var starboxInner = (function () {
function starboxInner(width, height, holeRadius, rimThickness) {
var mm = makerjs.model;
var corner = new stackboxCorner(holeRadius, rimThickness);
var corner = new starboxCorner(holeRadius, rimThickness);
this.models = {
bottomLeft: corner,
bottomRight: mm.move(mm.mirror(corner, true, false), [width, 0]),
Expand All @@ -32,12 +32,12 @@ var stackboxInner = (function () {
right: new line([width + holeRadius, d], [width + holeRadius, height - d])
};
}
return stackboxInner;
return starboxInner;
})();
var stackbox = (function () {
function stackbox(width, height, holeRadius, rimThickness, angle) {
var starbox = (function () {
function starbox(width, height, holeRadius, rimThickness, angle) {
if (arguments.length == 0) {
var defaultValues = makerjs.kit.getParameterValues(stackbox);
var defaultValues = makerjs.kit.getParameterValues(starbox);
width = defaultValues.shift();
height = defaultValues.shift();
holeRadius = defaultValues.shift();
Expand All @@ -49,7 +49,7 @@ var stackbox = (function () {
this.models = {
bolts: new mm.BoltRectangle(width, height, holeRadius),
outer: new mm.RoundRectangle(width + c2, height + c2, cornerRadius),
inner: new stackboxInner(width, height, holeRadius, rimThickness)
inner: new starboxInner(width, height, holeRadius, rimThickness)
};
this.models['outer'].origin = [-cornerRadius, -cornerRadius];

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

makerjs.model.combine(this.models.inner, star, false, true, true, false);
}
return stackbox;
return starbox;
})();
stackbox.metaParameters = [
starbox.metaParameters = [
{ title: "width", type: "range", min: 10, max: 500, value: 120 },
{ title: "height", type: "range", min: 10, max: 500, value: 100 },
{ title: "holeRadius", type: "range", min: 1, max: 20, value: 3 },
{ title: "rimThickness", type: "range", min: 1, max: 20, value: 2 },
{ title: "angle", type: "range", min: -180, max: 180, value: 45 }
];
module.exports = stackbox;
module.exports = starbox;
51 changes: 41 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,10 @@ var MakerJs;
*/
var pathAreEqualMap = {};
pathAreEqualMap[MakerJs.pathType.Line] = function (line1, line2) {
return MakerJs.point.areEqual(line1.end, line2.end);
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));
};
pathAreEqualMap[MakerJs.pathType.Circle] = function (circle1, circle2) {
return circle1.radius == circle2.radius;
return MakerJs.point.areEqual(circle1.origin, circle2.origin) && circle1.radius == circle2.radius;
};
pathAreEqualMap[MakerJs.pathType.Arc] = function (arc1, arc2) {
return pathAreEqualMap[MakerJs.pathType.Circle](arc1, arc2) && MakerJs.angle.areEqual(arc1.startAngle, arc2.startAngle) && MakerJs.angle.areEqual(arc1.endAngle, arc2.endAngle);
Expand All @@ -585,7 +585,7 @@ var MakerJs;
*/
function areEqual(path1, path2) {
var result = false;
if (path1.type == path2.type && MakerJs.point.areEqual(path1.origin, path2.origin)) {
if (path1.type == path2.type) {
var fn = pathAreEqualMap[path1.type];
if (fn) {
result = fn(path1, path2);
Expand Down Expand Up @@ -1139,7 +1139,7 @@ var MakerJs;
function breakAlongForeignPath(segments, overlappedSegments, foreignPath) {
if (MakerJs.path.areEqual(segments[0].path, foreignPath)) {
segments[0].overlapped = true;
segments[0].overlappedEqual = true;
segments[0].duplicate = true;
overlappedSegments.push(segments[0]);
return;
}
Expand Down Expand Up @@ -1283,7 +1283,7 @@ var MakerJs;
function checkForEqualOverlaps(crossedPathsA, crossedPathsB) {
function compareSegments(segment1, segment2) {
if (MakerJs.path.areEqual(segment1.path, segment2.path)) {
segment1.overlappedEqual = segment2.overlappedEqual = true;
segment1.duplicate = segment2.duplicate = true;
}
}
function compareAll(segment) {
Expand All @@ -1298,7 +1298,7 @@ var MakerJs;
/**
* @private
*/
function addOrDeleteSegments(crossedPath, includeInside, includeOutside, firstPass) {
function addOrDeleteSegments(crossedPath, includeInside, includeOutside, keepDuplicates) {
function addSegment(model, pathIdBase, segment) {
var id = model_1.getSimilarPathId(model, pathIdBase);
model.paths[id] = segment.path;
Expand All @@ -1311,8 +1311,8 @@ var MakerJs;
//delete the original, its segments will be added
delete crossedPath.modelContext.paths[crossedPath.pathId];
for (var i = 0; i < crossedPath.segments.length; i++) {
if (crossedPath.segments[i].overlappedEqual) {
if (firstPass) {
if (crossedPath.segments[i].duplicate) {
if (keepDuplicates) {
addSegment(crossedPath.modelContext, crossedPath.pathId, crossedPath.segments[i]);
}
}
Expand All @@ -1330,14 +1330,16 @@ var MakerJs;
* @param includeAOutsideB Flag to include paths from modelA which are outside of modelB.
* @param includeBInsideA Flag to include paths from modelB which are inside of modelA.
* @param includeBOutsideA Flag to include paths from modelB which are outside of modelA.
* @param keepDuplicates Flag to include paths which are duplicate in both models.
* @param farPoint Optional point of reference which is outside the bounds of both models.
*/
function combine(modelA, modelB, includeAInsideB, includeAOutsideB, includeBInsideA, includeBOutsideA, farPoint) {
function combine(modelA, modelB, includeAInsideB, includeAOutsideB, includeBInsideA, includeBOutsideA, keepDuplicates, farPoint) {
if (keepDuplicates === void 0) { keepDuplicates = true; }
var pathsA = breakAllPathsAtIntersections(modelA, modelB, farPoint);
var pathsB = breakAllPathsAtIntersections(modelB, modelA, farPoint);
checkForEqualOverlaps(pathsA.overlappedSegments, pathsB.overlappedSegments);
for (var i = 0; i < pathsA.crossedPaths.length; i++) {
addOrDeleteSegments(pathsA.crossedPaths[i], includeAInsideB, includeAOutsideB, true);
addOrDeleteSegments(pathsA.crossedPaths[i], includeAInsideB, includeAOutsideB, keepDuplicates);
}
for (var i = 0; i < pathsB.crossedPaths.length; i++) {
addOrDeleteSegments(pathsB.crossedPaths[i], includeBInsideA, includeBOutsideA);
Expand Down Expand Up @@ -3383,6 +3385,35 @@ var MakerJs;
})(models = MakerJs.models || (MakerJs.models = {}));
})(MakerJs || (MakerJs = {}));
var MakerJs;
(function (MakerJs) {
var models;
(function (models) {
var Dome = (function () {
function Dome(width, height, radius) {
if (radius === void 0) { radius = Math.min(width / 2, height); }
this.paths = {};
var w2 = width / 2;
var wt = Math.max(w2 - radius, 0);
var hr = Math.max(height - radius, 0);
this.paths["Bottom"] = new MakerJs.paths.Line([-w2, 0], [w2, 0]);
if (hr) {
this.paths["Left"] = new MakerJs.paths.Line([-w2, 0], [-w2, hr]);
this.paths["Right"] = new MakerJs.paths.Line([w2, 0], [w2, hr]);
}
if (radius > 0) {
this.paths["TopLeft"] = new MakerJs.paths.Arc([-wt, hr], radius, 90, 180);
this.paths["TopRight"] = new MakerJs.paths.Arc([wt, hr], radius, 0, 90);
}
if (wt) {
this.paths["Top"] = new MakerJs.paths.Line([-wt, height], [wt, height]);
}
}
return Dome;
})();
models.Dome = Dome;
})(models = MakerJs.models || (MakerJs.models = {}));
})(MakerJs || (MakerJs = {}));
var MakerJs;
(function (MakerJs) {
var models;
(function (models) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "makerjs",
"version": "0.5.0",
"version": "0.5.1",
"description": "Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.",
"main": "index.js",
"scripts": {
Expand Down
Loading