Skip to content

Commit

Permalink
Refactor Stampboard and Stampreceiver functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AnasSarkiz committed Nov 27, 2024
1 parent 6ce4f65 commit c59722d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/fn/sod123.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { length } from "circuit-json"

export const sod_def = z.object({
fn: z.string(),
num_pins: z.literal(3).default(3),
num_pins: z.literal(2).default(2),
w: z.string().default("2.36mm"),
h: z.string().default("1.22mm"),
pl: z.string().default("0.9mm"),
Expand Down
34 changes: 23 additions & 11 deletions src/fn/stampboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export const stampboard = (
let routes: { x: number; y: number }[] = []
const innerDiameter = 1
const outerDiameter = 1.2
const totalPadsNumber =
params.left + params.right + (params.bottom ?? 0) + (params.top ?? 0)
if (params.right) {
const yoff = -((params.right - 1) / 2) * params.p
for (let i = 0; i < params.right; i++) {
Expand All @@ -146,7 +148,7 @@ export const stampboard = (
}
rectpads.push(
rectpad(
i + 1,
i + 1 + params.left + (params.bottom ?? 0),
params.w / 2 - params.pl / 2,
yoff + i * params.p,
params.pl,
Expand All @@ -156,7 +158,7 @@ export const stampboard = (
if (params.innerhole) {
holes.push(
platedhole(
i + 1,
i + 1 + params.left + (params.bottom ?? 0) + totalPadsNumber,
params.w / 2,
yoff + i * params.p,
innerDiameter,
Expand All @@ -165,7 +167,7 @@ export const stampboard = (
)
holes.push(
platedhole(
i + 1,
i + 1 + params.left + (params.bottom ?? 0) + totalPadsNumber * 2,
params.w / 2 - params.innerholeedgedistance,
yoff + i * params.p,
innerDiameter,
Expand Down Expand Up @@ -197,7 +199,7 @@ export const stampboard = (
if (params.innerhole) {
holes.push(
platedhole(
i + 1,
i + 1 + totalPadsNumber,
-params.w / 2,
yoff + i * params.p,
innerDiameter,
Expand All @@ -206,7 +208,7 @@ export const stampboard = (
)
holes.push(
platedhole(
i + 1,
i + 1 + totalPadsNumber * 2,
-params.w / 2 + params.innerholeedgedistance,
yoff + i * params.p,
innerDiameter,
Expand All @@ -233,7 +235,7 @@ export const stampboard = (
}
rectpads.push(
rectpad(
i + 1,
i + 1 + params.left + params.right + (params.bottom ?? 0),
xoff + i * params.p,
getHeight(params) / 2 - params.pl / 2,
params.pw,
Expand All @@ -243,7 +245,12 @@ export const stampboard = (
if (params.innerhole) {
holes.push(
platedhole(
i + 1,
i +
1 +
params.left +
params.right +
(params.bottom ?? 0) +
totalPadsNumber,
xoff + i * params.p,
getHeight(params) / 2,
innerDiameter,
Expand All @@ -252,7 +259,12 @@ export const stampboard = (
)
holes.push(
platedhole(
i + 1,
i +
1 +
params.left +
params.right +
(params.bottom ?? 0) +
totalPadsNumber * 2,
xoff + i * params.p,
getHeight(params) / 2 - params.innerholeedgedistance,
innerDiameter,
Expand All @@ -274,7 +286,7 @@ export const stampboard = (
}
rectpads.push(
rectpad(
i + 1,
i + 1 + params.left,
xoff + i * params.p,
-getHeight(params) / 2 + params.pl / 2,
params.pw,
Expand All @@ -284,7 +296,7 @@ export const stampboard = (
if (params.innerhole) {
holes.push(
platedhole(
i + 1,
i + 1 + params.left + totalPadsNumber,
xoff + i * params.p,
-getHeight(params) / 2,
innerDiameter,
Expand All @@ -293,7 +305,7 @@ export const stampboard = (
)
holes.push(
platedhole(
i + 1,
i + 1 + params.left + totalPadsNumber * 2,
xoff + i * params.p,
-getHeight(params) / 2 + params.innerholeedgedistance,
innerDiameter,
Expand Down
155 changes: 62 additions & 93 deletions src/fn/stampreceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,104 +25,66 @@ export const stampreceiver_def = z.object({

export type Stampreceiver_def = z.input<typeof stampreceiver_def>

const getHeight = (parameters: Stampreceiver_def) => {
const getHeight = (parameters: Stampreceiver_def): number => {
const params = stampreceiver_def.parse(parameters)

// Calculate height based on the presence of left and right parameters
if (params.left && params.right) {
return Math.max(params.left, params.right) * params.p
}

if (params.left) {
return params.left * params.p
}

if (params.right) {
return params.right * params.p
}
return 51 // Default height if no pins are provided

// Return default height if neither left nor right is provided
return 51
}
const getTriangleDir = (x: number, y: number, side: string) => {
let routes: { x: number; y: number }[] = []
const triangleHeight = 1 // Adjust triangle size as needed
const triangleWidth = 0.6 // Adjust triangle width as needed
if (side === "left") {
routes = [
{
x: x + triangleHeight / 2,
y: y,
}, // Tip of the triangle (pointing right)
{
x: x - triangleHeight / 2,
y: y + triangleWidth / 2,
}, // Bottom corner of the base
{
x: x - triangleHeight / 2,
y: y - triangleWidth / 2,
}, // Top corner of the base
{
x: x + triangleHeight / 2,
y: y,
}, // Close the path at the tip
]
}
if (side === "right") {
routes = [
{
x: x - triangleHeight / 2,
y: y,
}, // Tip of the triangle (pointing left)
{
x: x + triangleHeight / 2,
y: y + triangleWidth / 2,
}, // Top corner of the base
{
x: x + triangleHeight / 2,
y: y - triangleWidth / 2,
}, // Bottom corner of the base
{
x: x - triangleHeight / 2,
y: y,
}, // Close the path at the tip
]
}
if (side === "bottom") {
routes = [
{
x: x,
y: y + triangleHeight / 2,
}, // Tip of the triangle (pointing up)
{
x: x - triangleWidth / 2,
y: y - triangleHeight / 2,
}, // Left corner of the base
{
x: x + triangleWidth / 2,
y: y - triangleHeight / 2,
}, // Right corner of the base
{
x: x,
y: y + triangleHeight / 2,
}, // Close the path at the tip
]
}
if (side === "top") {
routes = [
{
x: x,
y: y - triangleHeight / 2,
}, // Tip of the triangle (pointing down)
{
x: x - triangleWidth / 2,
y: y + triangleHeight / 2,
}, // Left corner of the base
{
x: x + triangleWidth / 2,
y: y + triangleHeight / 2,
}, // Right corner of the base
{
x: x,
y: y - triangleHeight / 2,
}, // Close the path at the tip
]
type Point = { x: number; y: number }
type Direction = "left" | "right" | "top" | "bottom"

const getTriangleDir = (
x: number,
y: number,
side: Direction,
triangleHeight = 1,
triangleWidth = 0.6,
): Point[] => {
const halfHeight = triangleHeight / 2
const halfWidth = triangleWidth / 2

const routes: Record<Direction, Point[]> = {
left: [
{ x: x + halfHeight, y }, // Tip
{ x: x - halfHeight, y: y + halfWidth }, // Bottom corner
{ x: x - halfHeight, y: y - halfWidth }, // Top corner
{ x: x + halfHeight, y }, // Close path
],
right: [
{ x: x - halfHeight, y }, // Tip
{ x: x + halfHeight, y: y + halfWidth }, // Top corner
{ x: x + halfHeight, y: y - halfWidth }, // Bottom corner
{ x: x - halfHeight, y }, // Close path
],
top: [
{ x, y: y - halfHeight }, // Tip
{ x: x - halfWidth, y: y + halfHeight }, // Left corner
{ x: x + halfWidth, y: y + halfHeight }, // Right corner
{ x, y: y - halfHeight }, // Close path
],
bottom: [
{ x, y: y + halfHeight }, // Tip
{ x: x - halfWidth, y: y - halfHeight }, // Left corner
{ x: x + halfWidth, y: y - halfHeight }, // Right corner
{ x, y: y + halfHeight }, // Close path
],
}
return routes

return routes[side]
}
export const stampreceiver = (
raw_params: Stampreceiver_def,
Expand All @@ -132,6 +94,8 @@ export const stampreceiver = (
const holes: PcbPlatedHole[] = []
const innerDiameter = 1
const outerDiameter = 1.2
const totalPadsNumber =
params.left + params.right + (params.bottom ?? 0) + (params.top ?? 0)
let routes: { x: number; y: number }[] = []
if (params.right) {
const yoff = -((params.right - 1) / 2) * params.p
Expand All @@ -145,7 +109,7 @@ export const stampreceiver = (
}
rectpads.push(
rectpad(
i + 1,
i + 1 + params.left + (params.bottom ?? 0),
params.w / 2 - params.pl / 2,
yoff + i * params.p,
params.pl,
Expand All @@ -155,7 +119,7 @@ export const stampreceiver = (
params.innerhole &&
holes.push(
platedhole(
i + 1,
i + 1 + params.left + (params.bottom ?? 0) + totalPadsNumber,
params.w / 2 - params.innerholeedgedistance,
yoff + i * params.p,
innerDiameter,
Expand Down Expand Up @@ -186,7 +150,7 @@ export const stampreceiver = (
params.innerhole &&
holes.push(
platedhole(
i + 1,
i + 1 + totalPadsNumber,
-params.w / 2 + params.innerholeedgedistance,
yoff + i * params.p,
innerDiameter,
Expand All @@ -212,7 +176,7 @@ export const stampreceiver = (
}
rectpads.push(
rectpad(
i + 1,
i + 1 + params.right + (params.bottom ?? 0) + params.left,
xoff + i * params.p,
getHeight(params) / 2 - params.pl / 2,
params.pw,
Expand All @@ -222,7 +186,12 @@ export const stampreceiver = (
params.innerhole &&
holes.push(
platedhole(
i + 1,
i +
1 +
params.right +
(params.bottom ?? 0) +
params.left +
totalPadsNumber,
xoff + i * params.p,
getHeight(params) / 2 - params.innerholeedgedistance,
innerDiameter,
Expand All @@ -243,7 +212,7 @@ export const stampreceiver = (
}
rectpads.push(
rectpad(
i + 1,
i + 1 + params.left,
xoff + i * params.p,
-getHeight(params) / 2 + params.pl / 2,
params.pw,
Expand All @@ -253,7 +222,7 @@ export const stampreceiver = (
params.innerhole &&
holes.push(
platedhole(
i + 1,
i + 1 + params.left + totalPadsNumber,
xoff + i * params.p,
-getHeight(params) / 2 + params.innerholeedgedistance,
innerDiameter,
Expand Down

0 comments on commit c59722d

Please sign in to comment.