Skip to content

Commit

Permalink
Merge pull request #238 from tscircuit/refactorschcompute
Browse files Browse the repository at this point in the history
refactor schematic box computation
  • Loading branch information
seveibar authored Nov 5, 2024
2 parents 22c3ff2 + c1a550f commit 49bae44
Show file tree
Hide file tree
Showing 23 changed files with 295 additions and 330 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/components/primitive-components/Port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class Port extends PrimitiveComponent<typeof portProps> {
center: portCenter,
source_port_id: this.source_port_id!,
facing_direction: this.facingDirection,
distance_from_component_edge: localPortInfo?.distanceFromEdge,
distance_from_component_edge: 0.4,
side_of_component: localPortInfo?.side,
pin_number: props.pinNumber,
true_ccw_index: localPortInfo?.trueIndex,
Expand Down
36 changes: 3 additions & 33 deletions lib/components/primitive-components/Trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ export class Trace extends PrimitiveComponent<typeof traceProps> {

if (!parent) throw new Error("Trace has no parent")

const { allPortsFound, portsWithSelectors: ports } =
const { allPortsFound, portsWithSelectors: connectedPorts } =
this._findConnectedPorts()

if (!allPortsFound) return
Expand Down Expand Up @@ -617,7 +617,7 @@ export class Trace extends PrimitiveComponent<typeof traceProps> {
}

// Get port positions for later use
const portsWithPosition = ports.map(({ port }) => ({
const portsWithPosition = connectedPorts.map(({ port }) => ({
port,
position: port._getGlobalSchematicPositionAfterLayout(),
schematic_port_id: port.schematic_port_id ?? undefined,
Expand Down Expand Up @@ -660,8 +660,7 @@ export class Trace extends PrimitiveComponent<typeof traceProps> {

if (results.length === 0) return

const [result] = results
const { route } = result
const [{ route }] = results

const edges: SchematicTrace["edges"] = []

Expand All @@ -673,35 +672,6 @@ export class Trace extends PrimitiveComponent<typeof traceProps> {
})
}

// Add small segments at the ends to connect to ports
const STUB_LENGTH = 0.15

// First port stub
edges.unshift({
from: {
...projectPointInDirection(
route[0],
portsWithPosition[0].facingDirection!,
STUB_LENGTH,
),
},
to: route[0],
from_schematic_port_id: portsWithPosition[0].schematic_port_id!,
})

// Last port stub
edges.push({
from: route[route.length - 1],
to: {
...projectPointInOppositeDirection(
route[route.length - 1],
portsWithPosition[1].facingDirection!,
STUB_LENGTH,
),
},
from_schematic_port_id: portsWithPosition[1].schematic_port_id!,
})

const trace = db.schematic_trace.insert({
source_trace_id: this.source_trace_id!,
edges,
Expand Down
Loading

0 comments on commit 49bae44

Please sign in to comment.