Skip to content

feat: implement relative-layout-mode <constraint /> between groups with centerX/centerY#1980

Open
769066112-ops wants to merge 2 commits intotscircuit:mainfrom
769066112-ops:feat/constraint-between-groups
Open

feat: implement relative-layout-mode <constraint /> between groups with centerX/centerY#1980
769066112-ops wants to merge 2 commits intotscircuit:mainfrom
769066112-ops:feat/constraint-between-groups

Conversation

@769066112-ops
Copy link

Summary

Implements <constraint /> component support for constraining the distance between groups (not just individual components), with optional centerX/centerY props for absolute positioning.

Closes #1391

Changes

Extended Constraint Props (Constraint.ts)

  • Added centerX and centerY optional props to PcbXDistConstraint and PcbYDistConstraint
  • Extended the zod schema locally to support these new props
  • Fixed the constructor check from xdist/ydist (lowercase) to xDist/yDist (camelCase)

Group Selector Support (applyComponentConstraintClusters.ts)

  • Updated getIdFromSelector() to resolve group names (e.g. .group1) to their source_group_id, in addition to component pcb_component_id
  • Added absoluteCenter to ClusterInfo — when centerX/centerY is specified, the cluster is placed at that absolute position instead of wherever the packer places it

Group Transform Support (applyPackOutput.ts)

  • Extended cluster member handling to support both pcb_component members and pcb_group members
  • For group members, finds all descendant elements and applies the transform correctly
  • Uses absoluteCenter when available for cluster positioning

JSX Types (intrinsic-jsx.ts)

  • Extended the constraint element type to include centerX and centerY props

Usage

<board pcbPack>
  <group name="group1">
    <resistor name="R1" resistance="1k" footprint="0402" />
  </group>
  <group name="group2">
    <resistor name="R2" resistance="1k" footprint="0402" />
  </group>
  <constraint pcb centerToCenter left=".group1" right=".group2" xDist="20mm" centerX={0} />
</board>

Tests

  • constraint between groups with xDist and centerX — verifies 20mm distance between groups and midpoint at x=0
  • constraint between components with xDist and centerX — verifies 10mm distance between components and midpoint at x=0

/claim #1391

@vercel
Copy link

vercel bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tscircuit-core-benchmarks Ready Ready Preview, Comment Feb 27, 2026 7:53pm

Request Review

Comment on lines 293 to 298
if (hasCenterX || hasCenterY) {
info.absoluteCenter = {
x: hasCenterX ? constraintCenterX : 0,
y: hasCenterY ? constraintCenterY : 0,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic error with partial absolute positioning. When only centerX is specified (without centerY), this sets y: 0. Similarly, when only centerY is specified, it sets x: 0. This forces the unspecified axis to zero instead of using the packer's computed position.

If a user specifies only centerX={10}, they likely want to constrain only the x-axis while letting the packer determine the y-position. Instead, this will force y=0.

Fix:

if (hasCenterX || hasCenterY) {
  info.absoluteCenter = {
    x: hasCenterX ? constraintCenterX : undefined,
    y: hasCenterY ? constraintCenterY : undefined,
  }
}

Then in applyPackOutput.ts, handle undefined values:

const effectiveCenter = {
  x: cluster.absoluteCenter?.x ?? center.x,
  y: cluster.absoluteCenter?.y ?? center.y,
}
Suggested change
if (hasCenterX || hasCenterY) {
info.absoluteCenter = {
x: hasCenterX ? constraintCenterX : 0,
y: hasCenterY ? constraintCenterY : 0,
}
}
if (hasCenterX || hasCenterY) {
info.absoluteCenter = {
x: hasCenterX ? constraintCenterX : undefined,
y: hasCenterY ? constraintCenterY : undefined,
}
}

Spotted by Graphite

Fix in Graphite


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement relative-layout-mode <constraint /> between groups

1 participant