-
Notifications
You must be signed in to change notification settings - Fork 117
Fix rotation for CourtyardRect #2052
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { test, expect } from "bun:test" | ||
| import { getTestFixture } from "../fixtures/get-test-fixture" | ||
|
|
||
| /** | ||
| * Two 0805 inductors, L2 rotated 90°, placed so their courtyards overlap. | ||
| * | ||
| * 0805 courtyard: width=3.35mm, height=1.9mm. | ||
| * L1 (0°) at (0,0): courtyard x=[-1.675, 1.675], y=[-0.95, 0.95]. | ||
| * L2 (90°) at (2.5, 0): with pcb_courtyard_outline the polygon rotates correctly, | ||
| * so effective x=[-0.95,0.95], y=[-1.675,1.675] shifted → x=[1.55, 3.45]. | ||
| * Courtyards overlap in x at [1.55, 1.675]. | ||
| * Pads of L2 are at x=2.5±0.5125, well clear of L1's pads ending at x=1.425. | ||
| */ | ||
| test("drc courtyard overlap detects overlapping 0805 inductors (one rotated 90°)", async () => { | ||
| const { circuit } = getTestFixture() | ||
|
|
||
| circuit.add( | ||
| <board width="20mm" height="20mm"> | ||
| <inductor | ||
| name="L1" | ||
| footprint="0805" | ||
| inductance="10uH" | ||
| pcbX={0} | ||
| pcbY={0} | ||
| /> | ||
| <inductor | ||
| name="L2" | ||
| footprint="0805" | ||
| inductance="10uH" | ||
| pcbX={2.5} | ||
| pcbY={0} | ||
| pcbRotation={90} | ||
| /> | ||
| </board>, | ||
| ) | ||
|
|
||
| await circuit.renderUntilSettled() | ||
|
|
||
| const circuitJson = circuit.getCircuitJson() | ||
|
|
||
| const padOverlapErrors = circuitJson.filter( | ||
| (e: any) => e.type === "pcb_footprint_overlap_error", | ||
| ) | ||
| expect(padOverlapErrors.length).toBe(0) | ||
|
|
||
| const courtyardErrors = circuitJson.filter( | ||
| (e: any) => e.type === "pcb_courtyard_overlap_error", | ||
| ) | ||
| expect(courtyardErrors.length).toBeGreaterThan(0) | ||
| expect((courtyardErrors[0] as any).message).toContain("overlaps") | ||
|
|
||
| expect(circuit).toMatchPcbSnapshot(import.meta.path, { | ||
| shouldDrawErrors: true, | ||
| showCourtyards: true, | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { test, expect } from "bun:test" | ||
| import { getTestFixture } from "../fixtures/get-test-fixture" | ||
|
|
||
| /** | ||
| * Two 0603 capacitors, C2 rotated 45°, placed so their courtyards overlap. | ||
| * | ||
| * 0603 courtyard: width=2.95mm, height=1.45mm. | ||
| * At 45°, AABB = (2.95 + 1.45) * cos(45°) ≈ 3.111mm on each side, half = 1.556mm. | ||
| * C1 (0°) at (0,0): courtyard x=[-1.475, 1.475]. | ||
| * C2 (45°) at (2.7,0): courtyard x=[1.144, 4.256]. | ||
| * Courtyards overlap by ~0.331mm. | ||
| * | ||
| * 0603 pads: width=2.45mm, height=0.95mm. | ||
| * C1 pads right edge = 1.225mm; C2 pads left edge ≈ 1.498mm → no pad overlap. | ||
| */ | ||
| test("drc courtyard overlap detects overlapping 0603 capacitors (one rotated 45°)", async () => { | ||
| const { circuit } = getTestFixture() | ||
|
|
||
| circuit.add( | ||
| <board width="20mm" height="20mm"> | ||
| <capacitor | ||
| name="C1" | ||
| footprint="0603" | ||
| capacitance="100nF" | ||
| pcbX={0} | ||
| pcbY={0} | ||
| /> | ||
| <capacitor | ||
| name="C2" | ||
| footprint="0603" | ||
| capacitance="100nF" | ||
| pcbX={2.7} | ||
| pcbY={0} | ||
| pcbRotation={45} | ||
| /> | ||
| </board>, | ||
| ) | ||
|
|
||
| await circuit.renderUntilSettled() | ||
|
|
||
| const circuitJson = circuit.getCircuitJson() | ||
|
|
||
| const padOverlapErrors = circuitJson.filter( | ||
| (e: any) => e.type === "pcb_footprint_overlap_error", | ||
| ) | ||
| expect(padOverlapErrors.length).toBe(0) | ||
|
|
||
| const courtyardErrors = circuitJson.filter( | ||
| (e: any) => e.type === "pcb_courtyard_overlap_error", | ||
| ) | ||
| expect(courtyardErrors.length).toBeGreaterThan(0) | ||
| expect((courtyardErrors[0] as any).message).toContain("overlaps") | ||
|
|
||
| expect(circuit).toMatchPcbSnapshot(import.meta.path, { | ||
| shouldDrawErrors: true, | ||
| showCourtyards: true, | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical Bug: Zero rotation will be stored as
undefinedThe expression
ccw_rotation || undefinedwill incorrectly evaluate toundefinedwhenccw_rotationis0(zero degrees). This is because0is a falsy value in JavaScript.Impact: Components with 0° rotation will have their rotation stored as
undefinedinstead of0, potentially breaking rotation-dependent logic elsewhere in the codebase.Fix: Either remove the
|| undefinedentirely, or use a proper nullish check:or simply:
Spotted by Graphite

Is this helpful? React 👍 or 👎 to let us know.