You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@tscircuit/autorouting-cache-engine

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tscircuit/autorouting-cache-engine - npm Package Compare versions

Comparing version

to
0.0.7

tests/net-properties-thickness.test.ts

7

dist/index.d.ts

@@ -67,2 +67,5 @@ import { CircuitJson, PcbTrace } from 'circuit-json';

nets_to_route: number[];
net_properties: Record<number, {
trace_thickness: string;
}>;
sorted_normalized_objects: NormalizedObject[];

@@ -81,4 +84,6 @@ };

marginOutsideOfRegionOfInterest?: number;
defaultTraceThickness?: string;
}
declare const DEFAULT_TRACE_THICKNESS = "0.15";
declare const convertCircuitJsonToNormalizedAutoroutingJson: (circuitJson: CircuitJson, options?: NormalizationOptions) => {

@@ -109,2 +114,2 @@ normalizedAutoroutingJson: NormalizedAutoroutingJson;

export { type NormalizationOptions, type NormalizationTransform, type NormalizedAutoroutingJson, type NormalizedAutoroutingTrace, type NormalizedHole, type NormalizedObject, type NormalizedPad, type NormalizedRoutePoint, type NormalizedTraceObstacle, convertCircuitJsonToNormalizedAutoroutingJson, denormalizeTraces, generateCacheKey, normalizePcbTraces };
export { DEFAULT_TRACE_THICKNESS, type NormalizationOptions, type NormalizationTransform, type NormalizedAutoroutingJson, type NormalizedAutoroutingTrace, type NormalizedHole, type NormalizedObject, type NormalizedPad, type NormalizedRoutePoint, type NormalizedTraceObstacle, convertCircuitJsonToNormalizedAutoroutingJson, denormalizeTraces, generateCacheKey, normalizePcbTraces };

68

dist/index.js
// lib/convertCircuitJsonToNormalizedAutoroutingJson.ts
import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map";
// lib/getBoundsOfRegionOfInterest.ts
var getBoundsOfRegionOfInterest = (circuitJson) => {
const allPoints = circuitJson.flatMap((el) => {
if (el.type === "pcb_port") {
return [{ x: el.x, y: el.y }];
}
return [];
});
const minX = Math.min(...allPoints.map((p) => p.x));
const maxX = Math.max(...allPoints.map((p) => p.x));
const minY = Math.min(...allPoints.map((p) => p.y));
const maxY = Math.max(...allPoints.map((p) => p.y));
return {
minX,
maxX,
minY,
maxY,
centerX: (minX + maxX) / 2,
centerY: (minY + maxY) / 2
};
};
// lib/circuit-json-utils/getAncestorSubcircuitIds.ts

@@ -94,4 +72,28 @@ var getAncestorSubcircuitIdsFromSubcircuitList = (subcircuitList, parentSubcircuitId) => {

// lib/getBoundsOfRegionOfInterest.ts
var getBoundsOfRegionOfInterest = (circuitJson) => {
const allPoints = circuitJson.flatMap((el) => {
if (el.type === "pcb_port") {
return [{ x: el.x, y: el.y }];
}
return [];
});
const minX = Math.min(...allPoints.map((p) => p.x));
const maxX = Math.max(...allPoints.map((p) => p.x));
const minY = Math.min(...allPoints.map((p) => p.y));
const maxY = Math.max(...allPoints.map((p) => p.y));
return {
minX,
maxX,
minY,
maxY,
centerX: (minX + maxX) / 2,
centerY: (minY + maxY) / 2
};
};
// lib/convertCircuitJsonToNormalizedAutoroutingJson.ts
var DEFAULT_TRACE_THICKNESS = "0.15";
var convertCircuitJsonToNormalizedAutoroutingJson = (circuitJson, options = {}) => {
const defaultTraceThickness = options.defaultTraceThickness ?? DEFAULT_TRACE_THICKNESS;
const connectivityMap = getFullConnectivityMapFromCircuitJson(circuitJson);

@@ -210,5 +212,26 @@ if (options.subcircuitId) {

).sort();
const netProperties = {};
for (const el of circuitJson) {
if (el.type === "source_trace") {
const connNet = connectivityMap.getNetConnectedToId(el.source_trace_id);
const netNumber = connNetToNetNumber.get(connNet);
if (!netNumber) continue;
if (netProperties[netNumber]) continue;
const thickness = el.min_trace_thickness?.toFixed(2).toString() ?? defaultTraceThickness;
netProperties[netNumber] = {
trace_thickness: thickness
};
}
}
for (const netNumber of netsToRoute) {
if (!netProperties[netNumber]) {
netProperties[netNumber] = {
trace_thickness: defaultTraceThickness
};
}
}
const normalizedAutoroutingJson = {
allowed_layers: 1,
nets_to_route: netsToRoute,
net_properties: netProperties,
sorted_normalized_objects: normalizedObstacles

@@ -420,2 +443,3 @@ };

export {
DEFAULT_TRACE_THICKNESS,
convertCircuitJsonToNormalizedAutoroutingJson,

@@ -422,0 +446,0 @@ denormalizeTraces,

import type { CircuitJson } from "circuit-json"
import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map"
import { getAncestorSubcircuitIds } from "./circuit-json-utils/getAncestorSubcircuitIds"
import { getRouteSegmentsFromTrace } from "./circuit-json-utils/getRouteSegmentsFromTrace"
import { getViasFromTrace } from "./circuit-json-utils/getViasFromTrace"
import { getBoundsOfRegionOfInterest } from "./getBoundsOfRegionOfInterest"
import type {
NormalizationOptions,
NormalizationTransform,
NormalizedAutoroutingJson,
NormalizationTransform,
NormalizedObject,
} from "./types"
import { getAncestorSubcircuitIds } from "./circuit-json-utils/getAncestorSubcircuitIds"
import { getRouteSegmentsFromTrace } from "./circuit-json-utils/getRouteSegmentsFromTrace"
import { getViasFromTrace } from "./circuit-json-utils/getViasFromTrace"
export const DEFAULT_TRACE_THICKNESS = "0.15"
export const convertCircuitJsonToNormalizedAutoroutingJson = (

@@ -21,2 +23,5 @@ circuitJson: CircuitJson,

} => {
const defaultTraceThickness =
options.defaultTraceThickness ?? DEFAULT_TRACE_THICKNESS
const connectivityMap = getFullConnectivityMapFromCircuitJson(circuitJson)

@@ -179,5 +184,36 @@ if (options.subcircuitId) {

const netProperties: Record<number, { trace_thickness: string }> = {}
for (const el of circuitJson) {
if (el.type === "source_trace") {
const connNet = connectivityMap.getNetConnectedToId(el.source_trace_id)
const netNumber = connNetToNetNumber.get(connNet!)
if (!netNumber) continue
if (netProperties[netNumber]) continue
// Get trace thickness from the element or use default
const thickness =
el.min_trace_thickness?.toFixed(2).toString() ?? defaultTraceThickness
netProperties[netNumber] = {
trace_thickness: thickness,
}
}
}
// Ensure all nets have properties
for (const netNumber of netsToRoute) {
if (!netProperties[netNumber]) {
netProperties[netNumber] = {
trace_thickness: defaultTraceThickness,
}
}
}
const normalizedAutoroutingJson: NormalizedAutoroutingJson = {
allowed_layers: 1,
nets_to_route: netsToRoute,
net_properties: netProperties,
sorted_normalized_objects: normalizedObstacles,

@@ -184,0 +220,0 @@ }

@@ -74,2 +74,3 @@ export interface NormalizedRoutePoint {

nets_to_route: number[]
net_properties: Record<number, { trace_thickness: string }>
sorted_normalized_objects: NormalizedObject[]

@@ -93,2 +94,3 @@ }

marginOutsideOfRegionOfInterest?: number
defaultTraceThickness?: string
}
{
"name": "@tscircuit/autorouting-cache-engine",
"version": "0.0.6",
"version": "0.0.7",
"repository": "https://github.com/tscircuit/autorouting-cache-engine",

@@ -19,3 +19,3 @@ "main": "dist/index.js",

"bun-match-svg": "^0.0.9",
"circuit-json": "^0.0.135",
"circuit-json": "^0.0.153",
"tsup": "^8.3.5"

@@ -22,0 +22,0 @@ },

@@ -10,6 +10,7 @@ import { test, expect } from "bun:test"

expect(cacheKey).toMatchInlineSnapshot(`"f51b182183bfa59a13d3df487f625ec2"`)
expect(cacheKey).toMatchInlineSnapshot(`"55631b6c19d07b00d2be40753be917e1"`)
expect(normalizedAutoroutingJson).toMatchInlineSnapshot(`
{
"allowed_layers": 1,
"net_properties": {},
"nets_to_route": [],

@@ -16,0 +17,0 @@ "sorted_normalized_objects": [

@@ -5,3 +5,2 @@ import { test, expect } from "bun:test"

import circuit2 from "./assets/testset1/circuit2.json"
import { convertCircuitJsonToNormalizedAutoroutingJson } from "../lib/convertCircuitJsonToNormalizedAutoroutingJson"
import { generateCacheKey } from "../lib"

@@ -17,3 +16,3 @@

expect(cacheKey1).toMatchInlineSnapshot(`"8aa5ab39715209b8f79a1c70216f6522"`)
expect(cacheKey1).toMatchInlineSnapshot(`"aeb3ced7cbdc05d1c8dbbd7849832832"`)

@@ -23,4 +22,4 @@ expect(cacheKey1).toEqual(cacheKey2)

expect(longString1).toMatchInlineSnapshot(
`"{"allowed_layers":1,"nets_to_route":[1],"sorted_normalized_objects":[{"height":"0.60","layers":["top"],"net":null,"type":"rect_pad","width":"0.60","x":"-2.50","y":"0.00"},{"height":"0.60","layers":["top"],"net":1,"type":"rect_pad","width":"0.60","x":"-3.50","y":"0.00"},{"height":"0.60","layers":["top"],"net":1,"type":"rect_pad","width":"0.60","x":"2.50","y":"0.00"},{"height":"0.60","layers":["top"],"net":null,"type":"rect_pad","width":"0.60","x":"3.50","y":"0.00"},{"net":1,"route_segments":[{"layer":"top","x1":"-1.20","x2":"-1.20","y1":"0.00","y2":"1.30"},{"layer":"top","x1":"-1.20","x2":"-3.50","y1":"1.30","y2":"1.30"},{"layer":"top","x1":"-3.50","x2":"-3.50","y1":"1.30","y2":"0.00"},{"layer":"top","x1":"2.50","x2":"-1.20","y1":"0.00","y2":"0.00"}],"type":"trace","vias":[]}]}"`,
`"{"allowed_layers":1,"net_properties":{"1":{"trace_thickness":"0.15"}},"nets_to_route":[1],"sorted_normalized_objects":[{"height":"0.60","layers":["top"],"net":null,"type":"rect_pad","width":"0.60","x":"-2.50","y":"0.00"},{"height":"0.60","layers":["top"],"net":1,"type":"rect_pad","width":"0.60","x":"-3.50","y":"0.00"},{"height":"0.60","layers":["top"],"net":1,"type":"rect_pad","width":"0.60","x":"2.50","y":"0.00"},{"height":"0.60","layers":["top"],"net":null,"type":"rect_pad","width":"0.60","x":"3.50","y":"0.00"},{"net":1,"route_segments":[{"layer":"top","x1":"-1.20","x2":"-1.20","y1":"0.00","y2":"1.30"},{"layer":"top","x1":"-1.20","x2":"-3.50","y1":"1.30","y2":"1.30"},{"layer":"top","x1":"-3.50","x2":"-3.50","y1":"1.30","y2":"0.00"},{"layer":"top","x1":"2.50","x2":"-1.20","y1":"0.00","y2":"0.00"}],"type":"trace","vias":[]}]}"`,
)
})

@@ -16,2 +16,7 @@ import { test, expect } from "bun:test"

"allowed_layers": 1,
"net_properties": {
"1": {
"trace_thickness": "0.15",
},
},
"nets_to_route": [

@@ -18,0 +23,0 @@ 1,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet