Skip to content

Commit

Permalink
♻️ refactor(enclosure): improve section handling and width calculation
Browse files Browse the repository at this point in the history
- remove unused import 'circle' from primitives
- change isEndSection type to a specific string type for clarity
- add 'hasPort' property to SectionOptions for extended functionality
- modify width calculation to separate constants and adjusted values for end sections
- update geometry calculations to reflect new width adjustments and end section specifications
  • Loading branch information
isfopo committed Nov 29, 2024
1 parent d37f98c commit 0a4658b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions hardware/enclosure/LoopPedalEnclosure.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { arc, circle, cylinder, line } from "@jscad/modeling/src/primitives";
import { arc, cylinder, line } from "@jscad/modeling/src/primitives";
import { extrudeLinear } from "@jscad/modeling/src/operations/extrusions";
import { expand } from "@jscad/modeling/src/operations/expansions";
import { subtract, union } from "@jscad/modeling/src/operations/booleans";
import { rotate, translate } from "@jscad/modeling/src/operations/transforms";
import convert from "convert";

interface SectionOptions {
isEndSection: boolean;
isEndSection: "left" | "right" | undefined;
hasPort: boolean;
}

const rod = {
Expand All @@ -18,7 +19,10 @@ const rod = {
};

const section = {
width: (isEndSection: boolean = false) =>
/** Width of each section */
width: rod.length / 4,
/** Accounts for the length of the nut */
adjustedWidth: (isEndSection: "left" | "right" | undefined) =>
(rod.length - (isEndSection ? rod.nut.height : 0)) / 4,
};

Expand Down Expand Up @@ -64,7 +68,8 @@ const sectionGeo = ({ isEndSection }: SectionOptions) => {
radius: buttons.diameter / 2,
height: dimensions.thickness * 2,
center: [
i * (section.width(isEndSection) / buttons.countPerSection),
i * (section.width / buttons.countPerSection) -
(isEndSection === "right" ? rod.nut.height / 2 : 0),
dimensions.face / 2,
0,
],
Expand All @@ -73,11 +78,7 @@ const sectionGeo = ({ isEndSection }: SectionOptions) => {
const buttonsGeo = rotate(
[0, -Math.PI / 2, 0],
translate(
[
-section.width(isEndSection) / buttons.countPerSection / 2,
0,
-offsetRadius,
],
[-section.width / buttons.countPerSection / 2, 0, -offsetRadius],
buttonGeo(1),
buttonGeo(2)
)
Expand All @@ -86,7 +87,7 @@ const sectionGeo = ({ isEndSection }: SectionOptions) => {
return subtract(
union(
extrudeLinear(
{ height: section.width(isEndSection) },
{ height: section.adjustedWidth(isEndSection) },
expand({ delta: dimensions.thickness }, ...shafts, face, back)
)
),
Expand All @@ -95,5 +96,5 @@ const sectionGeo = ({ isEndSection }: SectionOptions) => {
};

export const main = () => {
return sectionGeo({ isEndSection: true });
return sectionGeo({ isEndSection: "right", hasPort: true });
};

0 comments on commit 0a4658b

Please sign in to comment.