Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ArcWedge #585

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
87 changes: 87 additions & 0 deletions packages/maker.js/src/models/ArcWedge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
namespace MakerJs.models {

export class ArcWedge implements IModel {

public paths: IPathMap = {};
public models: IModelMap;

constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number, isolateCaps = false) {

var capRoot: IModel;

if (isolateCaps) {
capRoot = { models: {} };
this.models = { 'Caps': capRoot };
}

if (slotRadius <= 0 || sweepRadius <= 0) return;

startAngle = angle.noRevolutions(startAngle);
endAngle = angle.noRevolutions(endAngle);

if (endAngle < startAngle) endAngle += 360;

var addCap = (id: string, tiltAngle: number): IPathLine => {
var capModel: IModel;

if (isolateCaps) {
capModel = { paths: {} };
capRoot.models[id] = capModel;
} else {
capModel = this;
}

var pointA = MakerJs.point.fromPolar(MakerJs.angle.toRadians(tiltAngle), sweepRadius + slotRadius);
var pointB = MakerJs.point.fromPolar(MakerJs.angle.toRadians(tiltAngle), sweepRadius - slotRadius);

return capModel.paths[id] = new MakerJs.paths.Line(
pointA,
pointB);
};

if(endAngle != startAngle){

var addSweep = (id: string, offsetRadius: number): IPathArc => {
return this.paths[id] = new paths.Arc(
[0, 0],
sweepRadius + offsetRadius,
startAngle,
endAngle);
};

addSweep("Outer", slotRadius);

var hasInner = (sweepRadius - slotRadius) > 0;
if (hasInner) {
addSweep("Inner", -slotRadius);
}

var caps = [];
caps.push(addCap("StartCap", startAngle));
caps.push(addCap("EndCap", endAngle));

}else{

var addCirc = (id: string, offsetRadius: number): IPathCircle => {
return this.paths[id] = new paths.Circle(
[0, 0],
sweepRadius + offsetRadius);
};

addCirc("Outer", slotRadius);

var hasInner = (sweepRadius - slotRadius) > 0;
if (hasInner) {
addCirc("Inner", -slotRadius);
}
}
}
}

(<IKit>ArcWedge).metaParameters = [
{ title: "start angle", type: "range", min: -360, max: 360, step: 1, value: 180 },
{ title: "end angle", type: "range", min: -360, max: 360, step: 1, value: 0 },
{ title: "sweep", type: "range", min: 0, max: 100, step: 1, value: 50 },
{ title: "radius", type: "range", min: 0, max: 100, step: 1, value: 15 },
];
}
3 changes: 2 additions & 1 deletion packages/maker.js/target/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"compilerOptions": {
"declaration": true,
"outFile": "../dist/index.js",
Expand Down Expand Up @@ -57,6 +57,7 @@
"../src/models/RoundRectangle.ts",
"../src/models/Oval.ts",
"../src/models/OvalArc.ts",
"../src/models/ArcWedge.ts",
"../src/models/Rectangle.ts",
"../src/models/Ring.ts",
"../src/models/Belt.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/maker.js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"compilerOptions": {
"lib": ["dom", "es2015"],
"outDir": "debug/",
Expand Down Expand Up @@ -56,6 +56,7 @@
"src/models/RoundRectangle.ts",
"src/models/Oval.ts",
"src/models/OvalArc.ts",
"src/models/ArcWedge.ts",
"src/models/Rectangle.ts",
"src/models/Ring.ts",
"src/models/Belt.ts",
Expand Down