@tscircuit/core 0.0.922 → 0.0.924
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +134 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -19185,6 +19185,127 @@ var AnalogSimulation = class extends PrimitiveComponent2 {
|
|
|
19185
19185
|
// lib/components/primitive-components/VoltageProbe.ts
|
|
19186
19186
|
import { voltageProbeProps } from "@tscircuit/props";
|
|
19187
19187
|
import "zod";
|
|
19188
|
+
|
|
19189
|
+
// lib/utils/schematic/selectBestLabelAlignment.ts
|
|
19190
|
+
import { doBoundsOverlap as doBoundsOverlap2 } from "@tscircuit/math-utils";
|
|
19191
|
+
function getLabelBounds(probePosition, labelText, alignment, labelOffset = 0.3) {
|
|
19192
|
+
const charWidth = 0.1;
|
|
19193
|
+
const labelWidth = Math.max(labelText.length * charWidth, 0.3);
|
|
19194
|
+
const labelHeight = 0.25;
|
|
19195
|
+
const labelHeightWithPadding = labelHeight + 0.2;
|
|
19196
|
+
let anchorX = probePosition.x;
|
|
19197
|
+
let anchorY = probePosition.y;
|
|
19198
|
+
const offsetMultiplier = labelOffset + labelWidth / 2;
|
|
19199
|
+
if (alignment.includes("top")) {
|
|
19200
|
+
anchorY += offsetMultiplier;
|
|
19201
|
+
} else if (alignment.includes("bottom")) {
|
|
19202
|
+
anchorY -= offsetMultiplier;
|
|
19203
|
+
}
|
|
19204
|
+
if (alignment.includes("right")) {
|
|
19205
|
+
anchorX += offsetMultiplier;
|
|
19206
|
+
} else if (alignment.includes("left")) {
|
|
19207
|
+
anchorX -= offsetMultiplier;
|
|
19208
|
+
}
|
|
19209
|
+
let minX, maxX, minY, maxY;
|
|
19210
|
+
if (alignment.includes("left")) {
|
|
19211
|
+
minX = anchorX;
|
|
19212
|
+
maxX = anchorX + labelWidth;
|
|
19213
|
+
} else if (alignment.includes("right")) {
|
|
19214
|
+
minX = anchorX - labelWidth;
|
|
19215
|
+
maxX = anchorX;
|
|
19216
|
+
} else {
|
|
19217
|
+
minX = anchorX - labelWidth / 2;
|
|
19218
|
+
maxX = anchorX + labelWidth / 2;
|
|
19219
|
+
}
|
|
19220
|
+
if (alignment.includes("top")) {
|
|
19221
|
+
minY = anchorY - labelHeightWithPadding;
|
|
19222
|
+
maxY = anchorY;
|
|
19223
|
+
} else if (alignment.includes("bottom")) {
|
|
19224
|
+
minY = anchorY;
|
|
19225
|
+
maxY = anchorY + labelHeightWithPadding;
|
|
19226
|
+
} else {
|
|
19227
|
+
minY = anchorY - labelHeightWithPadding / 2;
|
|
19228
|
+
maxY = anchorY + labelHeightWithPadding / 2;
|
|
19229
|
+
}
|
|
19230
|
+
return { minX, maxX, minY, maxY };
|
|
19231
|
+
}
|
|
19232
|
+
function getElementBounds(elm) {
|
|
19233
|
+
let cx;
|
|
19234
|
+
let cy;
|
|
19235
|
+
let w;
|
|
19236
|
+
let h;
|
|
19237
|
+
if (elm.type === "schematic_component") {
|
|
19238
|
+
cx = elm.center?.x;
|
|
19239
|
+
cy = elm.center?.y;
|
|
19240
|
+
w = elm.size?.width;
|
|
19241
|
+
h = elm.size?.height;
|
|
19242
|
+
} else if (elm.type === "schematic_text") {
|
|
19243
|
+
cx = elm.position?.x;
|
|
19244
|
+
cy = elm.position?.y;
|
|
19245
|
+
w = (elm.text?.length ?? 0) * 0.1;
|
|
19246
|
+
h = 0.2;
|
|
19247
|
+
} else {
|
|
19248
|
+
return null;
|
|
19249
|
+
}
|
|
19250
|
+
if (typeof cx === "number" && typeof cy === "number" && typeof w === "number" && typeof h === "number") {
|
|
19251
|
+
return {
|
|
19252
|
+
minX: cx - w / 2,
|
|
19253
|
+
maxX: cx + w / 2,
|
|
19254
|
+
minY: cy - h / 2,
|
|
19255
|
+
maxY: cy + h / 2
|
|
19256
|
+
};
|
|
19257
|
+
}
|
|
19258
|
+
return null;
|
|
19259
|
+
}
|
|
19260
|
+
function getOverlapArea(a, b) {
|
|
19261
|
+
if (!doBoundsOverlap2(a, b)) return 0;
|
|
19262
|
+
const overlapWidth = Math.min(a.maxX, b.maxX) - Math.max(a.minX, b.minX);
|
|
19263
|
+
const overlapHeight = Math.min(a.maxY, b.maxY) - Math.max(a.minY, b.minY);
|
|
19264
|
+
return overlapWidth * overlapHeight;
|
|
19265
|
+
}
|
|
19266
|
+
function selectBestLabelAlignment({
|
|
19267
|
+
probePosition,
|
|
19268
|
+
labelText,
|
|
19269
|
+
schematicElements,
|
|
19270
|
+
defaultAlignment = "top_right"
|
|
19271
|
+
}) {
|
|
19272
|
+
const alignmentOptions = [
|
|
19273
|
+
"top_right",
|
|
19274
|
+
"top_left",
|
|
19275
|
+
"bottom_right",
|
|
19276
|
+
"bottom_left",
|
|
19277
|
+
"top_center",
|
|
19278
|
+
"bottom_center",
|
|
19279
|
+
"center_right",
|
|
19280
|
+
"center_left"
|
|
19281
|
+
];
|
|
19282
|
+
const orderedAlignments = [
|
|
19283
|
+
defaultAlignment,
|
|
19284
|
+
...alignmentOptions.filter((a) => a !== defaultAlignment)
|
|
19285
|
+
];
|
|
19286
|
+
let bestAlignment = defaultAlignment;
|
|
19287
|
+
let minOverlapArea = Infinity;
|
|
19288
|
+
for (const alignment of orderedAlignments) {
|
|
19289
|
+
const labelBounds = getLabelBounds(probePosition, labelText, alignment);
|
|
19290
|
+
let totalOverlapArea = 0;
|
|
19291
|
+
for (const element of schematicElements) {
|
|
19292
|
+
const elementBounds = getElementBounds(element);
|
|
19293
|
+
if (elementBounds) {
|
|
19294
|
+
totalOverlapArea += getOverlapArea(labelBounds, elementBounds);
|
|
19295
|
+
}
|
|
19296
|
+
}
|
|
19297
|
+
if (totalOverlapArea === 0) {
|
|
19298
|
+
return alignment;
|
|
19299
|
+
}
|
|
19300
|
+
if (totalOverlapArea < minOverlapArea) {
|
|
19301
|
+
minOverlapArea = totalOverlapArea;
|
|
19302
|
+
bestAlignment = alignment;
|
|
19303
|
+
}
|
|
19304
|
+
}
|
|
19305
|
+
return bestAlignment;
|
|
19306
|
+
}
|
|
19307
|
+
|
|
19308
|
+
// lib/components/primitive-components/VoltageProbe.ts
|
|
19188
19309
|
var VoltageProbe = class extends PrimitiveComponent2 {
|
|
19189
19310
|
simulation_voltage_probe_id = null;
|
|
19190
19311
|
schematic_voltage_probe_id = null;
|
|
@@ -19309,12 +19430,22 @@ var VoltageProbe = class extends PrimitiveComponent2 {
|
|
|
19309
19430
|
return;
|
|
19310
19431
|
}
|
|
19311
19432
|
const probeName = this.finalProbeName;
|
|
19433
|
+
const labelAlignment = selectBestLabelAlignment({
|
|
19434
|
+
probePosition: position,
|
|
19435
|
+
labelText: probeName,
|
|
19436
|
+
schematicElements: [
|
|
19437
|
+
...db.schematic_component.list(),
|
|
19438
|
+
...db.schematic_text.list()
|
|
19439
|
+
],
|
|
19440
|
+
defaultAlignment: "top_right"
|
|
19441
|
+
});
|
|
19312
19442
|
const schematic_voltage_probe = db.schematic_voltage_probe.insert({
|
|
19313
19443
|
name: probeName,
|
|
19314
19444
|
position,
|
|
19315
19445
|
schematic_trace_id: targetTraceId,
|
|
19316
19446
|
subcircuit_id: subcircuit.subcircuit_id || void 0,
|
|
19317
|
-
color: this.color ?? void 0
|
|
19447
|
+
color: this.color ?? void 0,
|
|
19448
|
+
label_alignment: labelAlignment
|
|
19318
19449
|
});
|
|
19319
19450
|
this.schematic_voltage_probe_id = schematic_voltage_probe.schematic_voltage_probe_id;
|
|
19320
19451
|
}
|
|
@@ -19329,7 +19460,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
19329
19460
|
var package_default = {
|
|
19330
19461
|
name: "@tscircuit/core",
|
|
19331
19462
|
type: "module",
|
|
19332
|
-
version: "0.0.
|
|
19463
|
+
version: "0.0.923",
|
|
19333
19464
|
types: "dist/index.d.ts",
|
|
19334
19465
|
main: "dist/index.js",
|
|
19335
19466
|
module: "dist/index.js",
|
|
@@ -19393,7 +19524,7 @@ var package_default = {
|
|
|
19393
19524
|
"circuit-json-to-gltf": "^0.0.31",
|
|
19394
19525
|
"circuit-json-to-simple-3d": "^0.0.9",
|
|
19395
19526
|
"circuit-json-to-spice": "^0.0.30",
|
|
19396
|
-
"circuit-to-svg": "^0.0.
|
|
19527
|
+
"circuit-to-svg": "^0.0.294",
|
|
19397
19528
|
concurrently: "^9.1.2",
|
|
19398
19529
|
"connectivity-map": "^1.0.0",
|
|
19399
19530
|
debug: "^4.3.6",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.924",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"circuit-json-to-gltf": "^0.0.31",
|
|
66
66
|
"circuit-json-to-simple-3d": "^0.0.9",
|
|
67
67
|
"circuit-json-to-spice": "^0.0.30",
|
|
68
|
-
"circuit-to-svg": "^0.0.
|
|
68
|
+
"circuit-to-svg": "^0.0.294",
|
|
69
69
|
"concurrently": "^9.1.2",
|
|
70
70
|
"connectivity-map": "^1.0.0",
|
|
71
71
|
"debug": "^4.3.6",
|