Skip to content

Commit

Permalink
Merge pull request #13 from tscircuit/overlapping-port-test
Browse files Browse the repository at this point in the history
overlapping port test
  • Loading branch information
seveibar authored Sep 13, 2024
2 parents 3258dfd + 032bff8 commit c385e17
Show file tree
Hide file tree
Showing 8 changed files with 1,985 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .aiderignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tests/assets/*.json
*.json
Binary file modified bun.lockb
Binary file not shown.
12 changes: 4 additions & 8 deletions lib/check-each-pcb-trace-non-overlapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NetManager } from "./net-manager"
import { addStartAndEndPortIdsIfMissing } from "./add-start-and-end-port-ids-if-missing"
import Debug from "debug"
import { su, getReadableNameForElement } from "@tscircuit/soup-util"
import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map"

const debug = Debug("tscircuit:checks:check-each-pcb-trace-non-overlapping")

Expand Down Expand Up @@ -167,19 +168,14 @@ function checkEachPcbTraceNonOverlapping(
soup: AnySoupElement[],
): PCBTraceError[] {
addStartAndEndPortIdsIfMissing(soup)
const connMap = getFullConnectivityMapFromCircuitJson(soup)
const pcbTraces: PCBTrace[] = soup.filter(
(item): item is PCBTrace => item.type === "pcb_trace",
)
const pcbSMTPads: PCBSMTPad[] = soup.filter(
(item): item is PCBSMTPad => item.type === "pcb_smtpad",
)
const errors: PCBTraceError[] = []
const netManager = new NetManager()

// TODO use source port ids instead of port ids, parse source ports for connections
for (const trace of pcbTraces) {
netManager.setConnected(getPcbPortIdsConnectedToTrace(trace))
}

for (let i = 0; i < pcbTraces.length; i++) {
for (let j = i + 1; j < pcbTraces.length; j++) {
Expand All @@ -202,7 +198,7 @@ function checkEachPcbTraceNonOverlapping(
continue
}

if (netManager.isConnected(connectedPorts)) {
if (connMap.areAllIdsConnected(connectedPorts)) {
continue
}
const overlapPoint = tracesOverlap(pcbTraces[i], pcbTraces[j])
Expand All @@ -228,7 +224,7 @@ function checkEachPcbTraceNonOverlapping(
for (const pad of pcbSMTPads) {
if (
pad.pcb_port_id &&
netManager.isConnected(
connMap.areAllIdsConnected(
getPcbPortIdsConnectedToTrace(pcbTraces[i]).concat([pad.pcb_port_id]),
)
) {
Expand Down
96 changes: 57 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"format": "biome format . --write"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@biomejs/biome": "^1.9.0",
"@tscircuit/log-soup": "^1.0.2",
"@tscircuit/soup": "^0.0.40",
"@types/bun": "latest",
Expand All @@ -26,6 +26,7 @@
"typescript": "^5.5.3"
},
"dependencies": {
"@tscircuit/soup-util": "0.0.15"
"@tscircuit/soup-util": "0.0.15",
"circuit-json-to-connectivity-map": "^0.0.10"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test, describe } from "bun:test"
import { checkEachPcbTraceNonOverlapping } from "lib/check-each-pcb-trace-non-overlapping"
import type { AnySoupElement, PCBTrace, PCBSMTPad } from "@tscircuit/soup"
import { logSoup } from "@tscircuit/log-soup"

describe("checkEachPcbTraceNonOverlapping", () => {
test("should return no errors when traces don't overlap", () => {
Expand All @@ -25,8 +26,20 @@ describe("checkEachPcbTraceNonOverlapping", () => {
expect(checkEachPcbTraceNonOverlapping(soup)).toEqual([])
})

test("should return an error when traces overlap", async () => {
test.only("should return an error when traces overlap", async () => {
const soup: AnySoupElement[] = [
{
type: "source_trace",
source_trace_id: "trace1",
connected_source_port_ids: ["port1", "port2"],
connected_source_net_ids: [],
},
{
type: "source_trace",
source_trace_id: "trace2",
connected_source_port_ids: ["port3", "port4"],
connected_source_net_ids: [],
},
{
type: "pcb_trace",
pcb_trace_id: "trace1",
Expand Down
Loading

0 comments on commit c385e17

Please sign in to comment.