Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type CommonPassiveOptionKey =
| "ph"
| "w"
| "h"
| "nonpolarized"
| "textbottom"

export type Footprinter = {
Expand Down
80 changes: 65 additions & 15 deletions src/helpers/passive-fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type StandardSize = {
w_mm_min: number // body width
courtyard_width_mm?: number
courtyard_height_mm?: number
nonpolarizedSilkscreen?: {
line_half_length_mm?: number
line_y_mm?: number
stroke_width_mm?: number
}
}

// Updated footprint sizes
Expand Down Expand Up @@ -55,6 +60,11 @@ export const footprintSizes: StandardSize[] = [
h_mm_min: 3.4,
courtyard_width_mm: 5.9,
courtyard_height_mm: 3.9,
nonpolarizedSilkscreen: {
line_half_length_mm: 1.386252,
line_y_mm: 1.71,
stroke_width_mm: 0.12,
},
},
{
imperial: "0201",
Expand All @@ -77,6 +87,11 @@ export const footprintSizes: StandardSize[] = [
h_mm_min: 0.64,
courtyard_width_mm: 1.86,
courtyard_height_mm: 0.94,
nonpolarizedSilkscreen: {
line_half_length_mm: 0.153641,
line_y_mm: 0.38,
stroke_width_mm: 0.12,
},
},
{
imperial: "0603",
Expand All @@ -88,6 +103,11 @@ export const footprintSizes: StandardSize[] = [
h_mm_min: 0.95,
courtyard_width_mm: 2.96,
courtyard_height_mm: 1.46,
nonpolarizedSilkscreen: {
line_half_length_mm: 0.237258,
line_y_mm: 0.5225,
stroke_width_mm: 0.12,
},
},
{
imperial: "0805",
Expand All @@ -99,6 +119,11 @@ export const footprintSizes: StandardSize[] = [
h_mm_min: 1.4,
courtyard_width_mm: 3.36,
courtyard_height_mm: 1.9,
nonpolarizedSilkscreen: {
line_half_length_mm: 0.227064,
line_y_mm: 0.735,
stroke_width_mm: 0.12,
},
},
{
imperial: "1206",
Expand All @@ -110,6 +135,11 @@ export const footprintSizes: StandardSize[] = [
h_mm_min: 1.75,
courtyard_width_mm: 4.56,
courtyard_height_mm: 2.26,
nonpolarizedSilkscreen: {
line_half_length_mm: 0.727064,
line_y_mm: 0.91,
stroke_width_mm: 0.12,
},
},
{
imperial: "1210",
Expand All @@ -121,6 +151,11 @@ export const footprintSizes: StandardSize[] = [
h_mm_min: 2.65,
courtyard_width_mm: 4.56,
courtyard_height_mm: 3.16,
nonpolarizedSilkscreen: {
line_half_length_mm: 0.723737,
line_y_mm: 1.355,
stroke_width_mm: 0.12,
},
},
{
imperial: "2010",
Expand All @@ -132,6 +167,11 @@ export const footprintSizes: StandardSize[] = [
h_mm_min: 2.65,
courtyard_width_mm: 6.36,
courtyard_height_mm: 3.16,
nonpolarizedSilkscreen: {
line_half_length_mm: 1.527064,
line_y_mm: 1.36,
stroke_width_mm: 0.12,
},
},
{
imperial: "2512",
Expand All @@ -143,6 +183,11 @@ export const footprintSizes: StandardSize[] = [
h_mm_min: 3.35,
courtyard_width_mm: 7.66,
courtyard_height_mm: 3.86,
nonpolarizedSilkscreen: {
line_half_length_mm: 2.177064,
line_y_mm: 1.71,
stroke_width_mm: 0.12,
},
},
]

Expand Down Expand Up @@ -175,6 +220,7 @@ export const passive_def = base_def.extend({
imperial: distance.optional(),
w: length.optional(),
h: length.optional(),
nonpolarized: z.boolean().optional(),
textbottom: z.boolean().optional(),
})

Expand All @@ -191,6 +237,7 @@ export const passive = (params: PassiveDef): AnyCircuitElement[] => {
imperial,
w,
h,
nonpolarized,
textbottom,
string: footprintString,
} = params
Expand Down Expand Up @@ -223,39 +270,42 @@ export const passive = (params: PassiveDef): AnyCircuitElement[] => {
throw new Error("Could not determine required pad dimensions (p, pw, ph)")
}

const lineLength = (p - pw) * 0.6
const lineY = ph / 2 + 0.06
let silkscreenLines: PcbSilkscreenPath[] = []

// `res0402` uses the nonpolarized silkscreen style: two symmetric lines
// instead of the polarized-style 3-sided outline used to show orientation.
const usesNonPolarized0402ResistorSilkscreen =
const nonpolarizedSilkscreen =
fn === "res" &&
typeof footprintString === "string" &&
/^res0402(?:_|$)/i.test(footprintString)
(nonpolarized === true ||
typeof footprintString !== "string" ||
/^res(?:\d{4}|\d{5})(?:_|$)/i.test(footprintString))
Comment thread
techmannih marked this conversation as resolved.
? sz?.nonpolarizedSilkscreen
: undefined
Comment thread
techmannih marked this conversation as resolved.

if (usesNonPolarized0402ResistorSilkscreen) {
if (nonpolarizedSilkscreen?.stroke_width_mm) {
const {
line_half_length_mm = 0,
line_y_mm = 0,
stroke_width_mm,
} = nonpolarizedSilkscreen
silkscreenLines = [
{
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{ x: -lineLength / 2, y: lineY },
{ x: lineLength / 2, y: lineY },
{ x: -line_half_length_mm, y: line_y_mm },
{ x: line_half_length_mm, y: line_y_mm },
],
stroke_width: 0.12,
stroke_width: stroke_width_mm,
pcb_silkscreen_path_id: "",
},
{
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{ x: -lineLength / 2, y: -lineY },
{ x: lineLength / 2, y: -lineY },
{ x: -line_half_length_mm, y: -line_y_mm },
{ x: line_half_length_mm, y: -line_y_mm },
],
stroke_width: 0.12,
stroke_width: stroke_width_mm,
pcb_silkscreen_path_id: "",
},
]
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/0603_bottomleft_origin.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions tests/kicad-parity/0402_nonpolarized_kicad_parity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect, test } from "bun:test"
import { compareFootprinterVsKicad } from "../fixtures/compareFootprinterVsKicad"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"

test("parity/0402_nonpolarized", async () => {
const {
avgRelDiff,
combinedFootprintElements,
booleanDifferenceSvg,
courtyardDiffPercent,
} = await compareFootprinterVsKicad(
"0402_nonpolarized",
"Resistor_SMD.pretty/R_0402_1005Metric.circuit.json",
)

const svgContent = convertCircuitJsonToPcbSvg(combinedFootprintElements, {
showCourtyards: true,
})
expect(courtyardDiffPercent).toBeLessThan(5)
expect(svgContent).toMatchSvgSnapshot(
import.meta.path,
"0402_nonpolarized_parity",
)
expect(booleanDifferenceSvg).toMatchSvgSnapshot(
import.meta.path,
"0402_nonpolarized_parity._boolean_difference",
)
}, 15_000)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading