Skip to content

fix: add net label orientation solver and validation tests#27

Open
Bilal-Lodhi wants to merge 5 commits into
tscircuit:mainfrom
Bilal-Lodhi:fix-issue-23
Open

fix: add net label orientation solver and validation tests#27
Bilal-Lodhi wants to merge 5 commits into
tscircuit:mainfrom
Bilal-Lodhi:fix-issue-23

Conversation

@Bilal-Lodhi

Copy link
Copy Markdown

Description

Addresses #23 by checking and normalizing the text angle of schematic_net_label elements.

Changes

  • Added NetLabelOrientationSolver to check if net labels fall outside a readable landscape window ([-90°, 90°]).
  • Normalizes unreadable angles using standard modulo mapping (((angle + 90) % 180) - 90).
  • Registered the new solver step into SchematicPlacementPipeline.
  • Added NetLabelOrientationUnreadable types and string conversion utilities.
  • Added unit tests in tests/cases/net-label-orientation.test.ts evaluating both flagged (135°) and unflagged (-45°) orientations.

Copilot AI review requested due to automatic review settings May 20, 2026 07:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new schematic-placement validation step that detects net labels whose computed orientation falls outside a readable landscape range (intended [-90°, 90°]), and surfaces those as placement issues with a proposed normalized angle.

Changes:

  • Introduced NetLabelOrientationSolver and registered it in SchematicPlacementPipeline.
  • Added NetLabelOrientationUnreadable to the placement issue union and wired string rendering into SchematicPlacementAnalysis.
  • Added a new Bun unit test covering a flagged vs unflagged net label orientation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/cases/net-label-orientation.test.ts Adds a test case asserting a net label orientation issue and its string formatting.
lib/types.ts Introduces NetLabelOrientationUnreadable and adds it to SchematicPlacementIssue.
lib/solvers/SchematicPlacementPipeline/SchematicPlacementPipeline.ts Registers the new solver step in the analysis pipeline.
lib/solvers/NetLabelOrientationSolver/NetLabelOrientationSolver.ts Implements angle computation, unreadable detection, normalization, and issue stringification.
lib/analyze-schematic-placement.ts Routes the new issue type to the solver’s issueToString for analysis.toString().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +77 to +78
private normalizeAngle(angleDeg: number): number {
return ((angleDeg + 90) % 180) - 90
Comment on lines +69 to +71
private computeAngleDeg(center: { x: number; y: number }, anchor: { x: number; y: number }): number {
return Math.atan2(anchor.y - center.y, anchor.x - center.x) * (180 / Math.PI)
}
Comment thread lib/types.ts Outdated
lineItemType: "NetLabelOrientationUnreadable"
schematicNetLabelId: string
text: string
anchorSide: "top" | "bottom" | "left" | "right"
@@ -0,0 +1,53 @@
// Run: bun test tests/cases/net-label-orientation.test.ts
import { expect, test } from "bun:test"
import { analyzeSchematicPlacement } from "../../lib/index"

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 10 changed files in this pull request and generated 4 comments.

}

private normalizeAngle(angleDeg: number): number {
return ((angleDeg + 90) % 180) - 90
Comment thread lib/types.ts Outdated
lineItemType: "NetLabelOrientationUnreadable"
schematicNetLabelId: string
text: string
anchorSide: "top" | "bottom" | "left" | "right"
@@ -0,0 +1,63 @@
// Run: bun test tests/cases/net-label-orientation.test.ts
import { expect, test } from "bun:test"
import { analyzeSchematicPlacement } from "../../lib/index"
Comment on lines +39 to +56
test("detects unreadable net label orientation", () => {
const analysis = analyzeSchematicPlacement(netLabelUpsideDownCircuitJson)
const issuesLineItem = analysis
.getLineItems()
.find((lineItem) => lineItem.lineItemType === "SchematicPlacementIssues")

expect(issuesLineItem).toMatchObject({
lineItemType: "SchematicPlacementIssues",
issues: [
{
lineItemType: "NetLabelOrientationUnreadable",
text: "GND",
anchorSide: "left",
currentAngleDeg: 135,
normalizedAngleDeg: -45,
},
],
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants