From 88ff43aa88439dbcad5c393778f2d2d157f339c6 Mon Sep 17 00:00:00 2001 From: milonic <43644601+milonic@users.noreply.github.com> Date: Sat, 17 Feb 2024 09:06:51 +0000 Subject: [PATCH 1/5] Add files via upload --- packages/maker.js/src/models/ArcWedge.ts | 114 +++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 packages/maker.js/src/models/ArcWedge.ts diff --git a/packages/maker.js/src/models/ArcWedge.ts b/packages/maker.js/src/models/ArcWedge.ts new file mode 100644 index 000000000..66846599b --- /dev/null +++ b/packages/maker.js/src/models/ArcWedge.ts @@ -0,0 +1,114 @@ +namespace MakerJs.models { + + export class ArcWedge implements IModel { + + public paths: IPathMap = {}; + public models: IModelMap; + + constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number, capRadius, largeArc = false, selfIntersect = false, isolateCaps = false) { + + // Change capRadius to an array, if it is not already and create elements for start and end caps + if (!Array.isArray(capRadius))capRadius = [capRadius, capRadius]; + + // Make sure the capRadius Array contains numerics + capRadius=capRadius.map(Number); + + 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 (round(startAngle - endAngle) == 0) return; + + if (endAngle < startAngle) endAngle += 360; + + var addCap = (id: string, tiltAngle: number, _capRadius: number): IPathArc => { + var capModel: IModel; + + if (isolateCaps) { + capModel = { paths: {} }; + capRoot.models[id] = capModel; + } else { + capModel = this; + } + + var sweepSlotA = sweepRadius + slotRadius + var sweepSlotB = sweepRadius - slotRadius + + if( (id[0] == "S" && _capRadius>=0) || (id[0] == "E" && _capRadius < 0) ){ + sweepSlotA = sweepRadius - slotRadius + sweepSlotB = sweepRadius + slotRadius + } + + // Find the end points for creating the arc + var pointA = MakerJs.point.fromPolar(MakerJs.angle.toRadians(tiltAngle), sweepSlotA) + var pointB = MakerJs.point.fromPolar(MakerJs.angle.toRadians(tiltAngle), sweepSlotB) + + // Increase or decrease _capRadius by slotRadius, eliminates the dead space between a capRadius of zero and slotRadius + if(_capRadius<0)_capRadius-=slotRadius; else _capRadius+=slotRadius + + // Disable largeArc for negative _capRadius values, it does odd things! + if ( largeArc && _capRadius<0 ) largeArc = false + + return capModel.paths[id] = new MakerJs.paths.Arc(pointA, pointB, Math.abs(_capRadius), largeArc, false); + }; + + 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, capRadius[0])); + caps.push(addCap("EndCap", endAngle, capRadius[1])); + + //the distance between the cap origins + var d = measure.pointDistance(caps[0].origin, caps[1].origin); + + if ((d / 2) < slotRadius) { + //the caps intersect + + var int = path.intersection(caps[0], caps[1]); + if (int) { + + if (!hasInner || !selfIntersect) { + caps[0].startAngle = int.path1Angles[0]; + caps[1].endAngle = int.path2Angles[0]; + } + + if (!selfIntersect && hasInner && int.intersectionPoints.length == 2) { + addCap("StartCap2", startAngle, capRadius[0]).endAngle = int.path1Angles[1]; + addCap("EndCap2", endAngle, capRadius[1]).startAngle = int.path2Angles[1] + 360; + } + } + } + } + } + + (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 }, + { title: "cap radius", type: "range", min: -180, max: 180, step: 1, value: 180 }, + { title: "largeArc", type: "bool", value: false }, + { title: "self intersect", type: "bool", value: false } + ]; +} From 891cb661de201b0c7ef4f4c6d775ae711b688a40 Mon Sep 17 00:00:00 2001 From: milonic <43644601+milonic@users.noreply.github.com> Date: Sat, 17 Feb 2024 09:08:53 +0000 Subject: [PATCH 2/5] Update tsconfig.json Added ArcWedge --- packages/maker.js/target/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/maker.js/target/tsconfig.json b/packages/maker.js/target/tsconfig.json index 0084801f8..850091c6b 100644 --- a/packages/maker.js/target/tsconfig.json +++ b/packages/maker.js/target/tsconfig.json @@ -1,4 +1,4 @@ -{ +{ "compilerOptions": { "declaration": true, "outFile": "../dist/index.js", @@ -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", From 0e25d40d307f87cf695cff3de620d676e2fafe18 Mon Sep 17 00:00:00 2001 From: milonic <43644601+milonic@users.noreply.github.com> Date: Sat, 17 Feb 2024 09:10:03 +0000 Subject: [PATCH 3/5] Update tsconfig.json Added ArcWedge --- packages/maker.js/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/maker.js/tsconfig.json b/packages/maker.js/tsconfig.json index 0e2b8b39d..6f60da22e 100644 --- a/packages/maker.js/tsconfig.json +++ b/packages/maker.js/tsconfig.json @@ -1,4 +1,4 @@ -{ +{ "compilerOptions": { "lib": ["dom", "es2015"], "outDir": "debug/", @@ -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", From bcc20ad3cc0d31e8be534a8d79067e6cfa3bca0a Mon Sep 17 00:00:00 2001 From: Andy Woolley <43644601+milonic@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:25:32 +0000 Subject: [PATCH 4/5] Update ArcWedge.ts Changing ArcWedge tojust add a line at end of arcs. Works in same way as OvalArc but without the radius at each end. --- packages/maker.js/src/models/ArcWedge.ts | 64 ++++-------------------- 1 file changed, 11 insertions(+), 53 deletions(-) diff --git a/packages/maker.js/src/models/ArcWedge.ts b/packages/maker.js/src/models/ArcWedge.ts index 66846599b..25cb3fd08 100644 --- a/packages/maker.js/src/models/ArcWedge.ts +++ b/packages/maker.js/src/models/ArcWedge.ts @@ -5,14 +5,8 @@ namespace MakerJs.models { public paths: IPathMap = {}; public models: IModelMap; - constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number, capRadius, largeArc = false, selfIntersect = false, isolateCaps = false) { + constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number, selfIntersect = false, isolateCaps = false) { - // Change capRadius to an array, if it is not already and create elements for start and end caps - if (!Array.isArray(capRadius))capRadius = [capRadius, capRadius]; - - // Make sure the capRadius Array contains numerics - capRadius=capRadius.map(Number); - var capRoot: IModel; if (isolateCaps) { @@ -29,7 +23,7 @@ namespace MakerJs.models { if (endAngle < startAngle) endAngle += 360; - var addCap = (id: string, tiltAngle: number, _capRadius: number): IPathArc => { + var addCap = (id: string, tiltAngle: number): IPathLine => { var capModel: IModel; if (isolateCaps) { @@ -38,26 +32,13 @@ namespace MakerJs.models { } else { capModel = this; } - - var sweepSlotA = sweepRadius + slotRadius - var sweepSlotB = sweepRadius - slotRadius - - if( (id[0] == "S" && _capRadius>=0) || (id[0] == "E" && _capRadius < 0) ){ - sweepSlotA = sweepRadius - slotRadius - sweepSlotB = sweepRadius + slotRadius - } - - // Find the end points for creating the arc - var pointA = MakerJs.point.fromPolar(MakerJs.angle.toRadians(tiltAngle), sweepSlotA) - var pointB = MakerJs.point.fromPolar(MakerJs.angle.toRadians(tiltAngle), sweepSlotB) - - // Increase or decrease _capRadius by slotRadius, eliminates the dead space between a capRadius of zero and slotRadius - if(_capRadius<0)_capRadius-=slotRadius; else _capRadius+=slotRadius - - // Disable largeArc for negative _capRadius values, it does odd things! - if ( largeArc && _capRadius<0 ) largeArc = false - - return capModel.paths[id] = new MakerJs.paths.Arc(pointA, pointB, Math.abs(_capRadius), largeArc, false); + + 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); }; var addSweep = (id: string, offsetRadius: number): IPathArc => { @@ -76,29 +57,8 @@ namespace MakerJs.models { } var caps = []; - caps.push(addCap("StartCap", startAngle, capRadius[0])); - caps.push(addCap("EndCap", endAngle, capRadius[1])); - - //the distance between the cap origins - var d = measure.pointDistance(caps[0].origin, caps[1].origin); - - if ((d / 2) < slotRadius) { - //the caps intersect - - var int = path.intersection(caps[0], caps[1]); - if (int) { - - if (!hasInner || !selfIntersect) { - caps[0].startAngle = int.path1Angles[0]; - caps[1].endAngle = int.path2Angles[0]; - } - - if (!selfIntersect && hasInner && int.intersectionPoints.length == 2) { - addCap("StartCap2", startAngle, capRadius[0]).endAngle = int.path1Angles[1]; - addCap("EndCap2", endAngle, capRadius[1]).startAngle = int.path2Angles[1] + 360; - } - } - } + caps.push(addCap("StartCap", startAngle)); + caps.push(addCap("EndCap", endAngle)); } } @@ -107,8 +67,6 @@ namespace MakerJs.models { { 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 }, - { title: "cap radius", type: "range", min: -180, max: 180, step: 1, value: 180 }, - { title: "largeArc", type: "bool", value: false }, { title: "self intersect", type: "bool", value: false } ]; } From 6bfaf1855c37ea4cd836fb2be2f2ac1b018462d0 Mon Sep 17 00:00:00 2001 From: Andy Woolley <43644601+milonic@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:25:16 +0000 Subject: [PATCH 5/5] Update ArcWedge.ts Removed selfIntersect and added new paths.Circle if start and end angled match --- packages/maker.js/src/models/ArcWedge.ts | 57 +++++++++++++++--------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/packages/maker.js/src/models/ArcWedge.ts b/packages/maker.js/src/models/ArcWedge.ts index 25cb3fd08..f824dfad4 100644 --- a/packages/maker.js/src/models/ArcWedge.ts +++ b/packages/maker.js/src/models/ArcWedge.ts @@ -5,7 +5,7 @@ namespace MakerJs.models { public paths: IPathMap = {}; public models: IModelMap; - constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number, selfIntersect = false, isolateCaps = false) { + constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number, isolateCaps = false) { var capRoot: IModel; @@ -19,8 +19,6 @@ namespace MakerJs.models { startAngle = angle.noRevolutions(startAngle); endAngle = angle.noRevolutions(endAngle); - if (round(startAngle - endAngle) == 0) return; - if (endAngle < startAngle) endAngle += 360; var addCap = (id: string, tiltAngle: number): IPathLine => { @@ -41,24 +39,42 @@ namespace MakerJs.models { pointB); }; - 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); + 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); + } } - - var caps = []; - caps.push(addCap("StartCap", startAngle)); - caps.push(addCap("EndCap", endAngle)); } } @@ -67,6 +83,5 @@ namespace MakerJs.models { { 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 }, - { title: "self intersect", type: "bool", value: false } ]; }