|
| 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; |
0 commit comments