@tscircuit/core 0.0.695 → 0.0.696

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.
Files changed (2) hide show
  1. package/dist/index.js +79 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6387,11 +6387,69 @@ var shouldCheckPortForMissingTrace = (component, port) => {
6387
6387
  return true;
6388
6388
  };
6389
6389
 
6390
- // lib/components/base-components/NormalComponent/NormalComponent_doInitialSilkscreenOverlapAdjustment.ts
6391
- import { getBoundingBox } from "@tscircuit/math-utils";
6392
- function doBoundsIntersect(bounds1, bounds2) {
6393
- return !(bounds1.maxX <= bounds2.minX || bounds2.maxX <= bounds1.minX || bounds1.maxY <= bounds2.minY || bounds2.maxY <= bounds1.minY);
6390
+ // lib/components/base-components/NormalComponent/utils/getPcbTextBounds.ts
6391
+ function getPcbTextBounds(text) {
6392
+ const fontSize = text.font_size;
6393
+ const textWidth = text.text.length * fontSize * 0.6;
6394
+ const textHeight = fontSize;
6395
+ const anchorAlignment = text.anchor_alignment || "center";
6396
+ let centerX = text.anchor_position.x;
6397
+ let centerY = text.anchor_position.y;
6398
+ switch (anchorAlignment) {
6399
+ case "top_left":
6400
+ centerX = text.anchor_position.x + textWidth / 2;
6401
+ centerY = text.anchor_position.y + textHeight / 2;
6402
+ break;
6403
+ case "top_center":
6404
+ centerX = text.anchor_position.x;
6405
+ centerY = text.anchor_position.y + textHeight / 2;
6406
+ break;
6407
+ case "top_right":
6408
+ centerX = text.anchor_position.x - textWidth / 2;
6409
+ centerY = text.anchor_position.y + textHeight / 2;
6410
+ break;
6411
+ case "center_left":
6412
+ centerX = text.anchor_position.x + textWidth / 2;
6413
+ centerY = text.anchor_position.y;
6414
+ break;
6415
+ case "center":
6416
+ centerX = text.anchor_position.x;
6417
+ centerY = text.anchor_position.y;
6418
+ break;
6419
+ case "center_right":
6420
+ centerX = text.anchor_position.x - textWidth / 2;
6421
+ centerY = text.anchor_position.y;
6422
+ break;
6423
+ case "bottom_left":
6424
+ centerX = text.anchor_position.x + textWidth / 2;
6425
+ centerY = text.anchor_position.y - textHeight / 2;
6426
+ break;
6427
+ case "bottom_center":
6428
+ centerX = text.anchor_position.x;
6429
+ centerY = text.anchor_position.y - textHeight / 2;
6430
+ break;
6431
+ case "bottom_right":
6432
+ centerX = text.anchor_position.x - textWidth / 2;
6433
+ centerY = text.anchor_position.y - textHeight / 2;
6434
+ break;
6435
+ default:
6436
+ centerX = text.anchor_position.x;
6437
+ centerY = text.anchor_position.y;
6438
+ break;
6439
+ }
6440
+ return {
6441
+ x: centerX - textWidth / 2,
6442
+ y: centerY - textHeight / 2,
6443
+ width: textWidth,
6444
+ height: textHeight
6445
+ };
6394
6446
  }
6447
+
6448
+ // lib/components/base-components/NormalComponent/NormalComponent_doInitialSilkscreenOverlapAdjustment.ts
6449
+ import {
6450
+ getBoundingBox,
6451
+ doBoundsOverlap
6452
+ } from "@tscircuit/math-utils";
6395
6453
  function NormalComponent_doInitialSilkscreenOverlapAdjustment(component) {
6396
6454
  if (!component._adjustSilkscreenTextAutomatically) {
6397
6455
  return;
@@ -6421,33 +6479,34 @@ function NormalComponent_doInitialSilkscreenOverlapAdjustment(component) {
6421
6479
  });
6422
6480
  for (const silkscreenText of silkscreenTexts) {
6423
6481
  const currentPosition = silkscreenText.anchor_position;
6424
- const fontSize = silkscreenText.font_size;
6425
- const textWidth = silkscreenText.text.length * fontSize * 0.6;
6426
- const textHeight = fontSize;
6482
+ const textBounds = getPcbTextBounds(silkscreenText);
6427
6483
  const textBox = {
6428
- center: currentPosition,
6429
- width: textWidth,
6430
- height: textHeight
6484
+ center: {
6485
+ x: textBounds.x + textBounds.width / 2,
6486
+ y: textBounds.y + textBounds.height / 2
6487
+ },
6488
+ width: textBounds.width,
6489
+ height: textBounds.height
6431
6490
  };
6432
- const textBounds = getBoundingBox(textBox);
6433
- const hasIntersection = obstacleBounds.some(
6434
- (obstacle) => doBoundsIntersect(textBounds, obstacle)
6491
+ const textBoundsBox = getBoundingBox(textBox);
6492
+ const hasOverlap = obstacleBounds.some(
6493
+ (obstacle) => doBoundsOverlap(textBoundsBox, obstacle)
6435
6494
  );
6436
- if (!hasIntersection) {
6495
+ if (!hasOverlap) {
6437
6496
  continue;
6438
6497
  }
6439
6498
  const flippedX = 2 * componentCenter.x - currentPosition.x;
6440
6499
  const flippedY = 2 * componentCenter.y - currentPosition.y;
6441
6500
  const flippedTextBox = {
6442
6501
  center: { x: flippedX, y: flippedY },
6443
- width: textWidth,
6444
- height: textHeight
6502
+ width: textBounds.width,
6503
+ height: textBounds.height
6445
6504
  };
6446
6505
  const flippedTextBounds = getBoundingBox(flippedTextBox);
6447
- const flippedHasIntersection = obstacleBounds.some(
6448
- (obstacle) => doBoundsIntersect(flippedTextBounds, obstacle)
6506
+ const flippedHasOverlap = obstacleBounds.some(
6507
+ (obstacle) => doBoundsOverlap(flippedTextBounds, obstacle)
6449
6508
  );
6450
- if (!flippedHasIntersection) {
6509
+ if (!flippedHasOverlap) {
6451
6510
  db.pcb_silkscreen_text.update(silkscreenText.pcb_silkscreen_text_id, {
6452
6511
  anchor_position: {
6453
6512
  x: flippedX,
@@ -14237,7 +14296,7 @@ import { identity as identity6 } from "transformation-matrix";
14237
14296
  var package_default = {
14238
14297
  name: "@tscircuit/core",
14239
14298
  type: "module",
14240
- version: "0.0.694",
14299
+ version: "0.0.695",
14241
14300
  types: "dist/index.d.ts",
14242
14301
  main: "dist/index.js",
14243
14302
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.695",
4
+ "version": "0.0.696",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",