forked from microsoft/maker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRimbox.js
More file actions
67 lines (67 loc) · 2.84 KB
/
Rimbox.js
File metadata and controls
67 lines (67 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;