circuit-to-canvas 0.0.36 → 0.0.37

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 CHANGED
@@ -1766,78 +1766,76 @@ function drawDimensionLine(params) {
1766
1766
  x: anchor.x + extensionDirection.x * extensionLength,
1767
1767
  y: anchor.y + extensionDirection.y * extensionLength
1768
1768
  };
1769
- const halfWidth2 = strokeWidth / 2;
1769
+ const halfWidth = strokeWidth / 2;
1770
1770
  const extPerpendicular = {
1771
1771
  x: -extensionDirection.y,
1772
1772
  y: extensionDirection.x
1773
1773
  };
1774
1774
  return [
1775
1775
  {
1776
- x: anchor.x + extPerpendicular.x * halfWidth2,
1777
- y: anchor.y + extPerpendicular.y * halfWidth2
1776
+ x: anchor.x + extPerpendicular.x * halfWidth,
1777
+ y: anchor.y + extPerpendicular.y * halfWidth
1778
1778
  },
1779
1779
  {
1780
- x: anchor.x - extPerpendicular.x * halfWidth2,
1781
- y: anchor.y - extPerpendicular.y * halfWidth2
1780
+ x: anchor.x - extPerpendicular.x * halfWidth,
1781
+ y: anchor.y - extPerpendicular.y * halfWidth
1782
1782
  },
1783
1783
  {
1784
- x: endPoint.x - extPerpendicular.x * halfWidth2,
1785
- y: endPoint.y - extPerpendicular.y * halfWidth2
1784
+ x: endPoint.x - extPerpendicular.x * halfWidth,
1785
+ y: endPoint.y - extPerpendicular.y * halfWidth
1786
1786
  },
1787
1787
  {
1788
- x: endPoint.x + extPerpendicular.x * halfWidth2,
1789
- y: endPoint.y + extPerpendicular.y * halfWidth2
1788
+ x: endPoint.x + extPerpendicular.x * halfWidth,
1789
+ y: endPoint.y + extPerpendicular.y * halfWidth
1790
1790
  }
1791
1791
  ];
1792
1792
  };
1793
- const ext1 = getExtensionPoints(from);
1794
- allPoints.push(...ext1, ext1[0]);
1795
- const ext2 = getExtensionPoints(to);
1796
- allPoints.push(...ext2, ext2[0]);
1797
- const halfWidth = strokeWidth / 2;
1798
- const mainLine = [
1799
- {
1800
- x: fromBase.x + perpendicular.x * halfWidth,
1801
- y: fromBase.y + perpendicular.y * halfWidth
1802
- },
1803
- {
1804
- x: fromBase.x - perpendicular.x * halfWidth,
1805
- y: fromBase.y - perpendicular.y * halfWidth
1806
- },
1807
- {
1808
- x: toBase.x - perpendicular.x * halfWidth,
1809
- y: toBase.y - perpendicular.y * halfWidth
1810
- },
1811
- {
1812
- x: toBase.x + perpendicular.x * halfWidth,
1813
- y: toBase.y + perpendicular.y * halfWidth
1814
- }
1815
- ];
1816
- allPoints.push(...mainLine, mainLine[0]);
1817
- const arrow1 = [
1818
- fromOffset,
1819
- {
1820
- x: fromOffset.x + direction.x * arrowSize + perpendicular.x * (arrowSize / 2),
1821
- y: fromOffset.y + direction.y * arrowSize + perpendicular.y * (arrowSize / 2)
1822
- },
1823
- {
1824
- x: fromOffset.x + direction.x * arrowSize - perpendicular.x * (arrowSize / 2),
1825
- y: fromOffset.y + direction.y * arrowSize - perpendicular.y * (arrowSize / 2)
1826
- }
1827
- ];
1828
- allPoints.push(...arrow1, arrow1[0]);
1829
- const arrow2 = [
1830
- toOffset,
1831
- {
1832
- x: toOffset.x - direction.x * arrowSize + perpendicular.x * (arrowSize / 2),
1833
- y: toOffset.y - direction.y * arrowSize + perpendicular.y * (arrowSize / 2)
1834
- },
1835
- {
1836
- x: toOffset.x - direction.x * arrowSize - perpendicular.x * (arrowSize / 2),
1837
- y: toOffset.y - direction.y * arrowSize - perpendicular.y * (arrowSize / 2)
1838
- }
1839
- ];
1840
- allPoints.push(...arrow2, arrow2[0]);
1793
+ allPoints.push(fromOffset);
1794
+ allPoints.push({
1795
+ x: fromBase.x + perpendicular.x * (arrowSize / 2),
1796
+ y: fromBase.y + perpendicular.y * (arrowSize / 2)
1797
+ });
1798
+ allPoints.push({
1799
+ x: fromBase.x + perpendicular.x * (strokeWidth / 2),
1800
+ y: fromBase.y + perpendicular.y * (strokeWidth / 2)
1801
+ });
1802
+ allPoints.push({
1803
+ x: toBase.x + perpendicular.x * (strokeWidth / 2),
1804
+ y: toBase.y + perpendicular.y * (strokeWidth / 2)
1805
+ });
1806
+ allPoints.push({
1807
+ x: toBase.x + perpendicular.x * (arrowSize / 2),
1808
+ y: toBase.y + perpendicular.y * (arrowSize / 2)
1809
+ });
1810
+ allPoints.push(toOffset);
1811
+ allPoints.push({
1812
+ x: toBase.x - perpendicular.x * (arrowSize / 2),
1813
+ y: toBase.y - perpendicular.y * (arrowSize / 2)
1814
+ });
1815
+ allPoints.push({
1816
+ x: toBase.x - perpendicular.x * (strokeWidth / 2),
1817
+ y: toBase.y - perpendicular.y * (strokeWidth / 2)
1818
+ });
1819
+ allPoints.push({
1820
+ x: fromBase.x - perpendicular.x * (strokeWidth / 2),
1821
+ y: fromBase.y - perpendicular.y * (strokeWidth / 2)
1822
+ });
1823
+ allPoints.push({
1824
+ x: fromBase.x - perpendicular.x * (arrowSize / 2),
1825
+ y: fromBase.y - perpendicular.y * (arrowSize / 2)
1826
+ });
1827
+ allPoints.push(fromOffset);
1828
+ const startPoint = allPoints[0];
1829
+ const addTick = (anchor) => {
1830
+ const pts = getExtensionPoints(anchor);
1831
+ allPoints.push(startPoint);
1832
+ allPoints.push(pts[0]);
1833
+ allPoints.push(...pts);
1834
+ allPoints.push(pts[0]);
1835
+ allPoints.push(startPoint);
1836
+ };
1837
+ addTick(from);
1838
+ addTick(to);
1841
1839
  drawPolygon({
1842
1840
  ctx,
1843
1841
  points: allPoints,
@@ -1873,9 +1871,9 @@ function drawDimensionLine(params) {
1873
1871
  const rotationRad = textRotation * Math.PI / 180;
1874
1872
  const sinRot = Math.abs(Math.sin(rotationRad));
1875
1873
  const cosRot = Math.abs(Math.cos(rotationRad));
1876
- const halfWidth2 = textWidth / 2;
1874
+ const halfWidth = textWidth / 2;
1877
1875
  const halfHeight = textHeight / 2;
1878
- const maxExtension = halfWidth2 * sinRot + halfHeight * cosRot;
1876
+ const maxExtension = halfWidth * sinRot + halfHeight * cosRot;
1879
1877
  additionalOffset = maxExtension + fontSize * TEXT_INTERSECTION_PADDING_MULTIPLIER;
1880
1878
  }
1881
1879
  const textOffset = arrowSize * TEXT_OFFSET_MULTIPLIER + additionalOffset;
@@ -121,85 +121,80 @@ export function drawDimensionLine(params: DrawDimensionLineParams): void {
121
121
  ]
122
122
  }
123
123
 
124
- // Extension lines (ticks)
125
- const ext1 = getExtensionPoints(from)
126
- allPoints.push(...ext1, ext1[0]!)
127
-
128
- const ext2 = getExtensionPoints(to)
129
- allPoints.push(...ext2, ext2[0]!)
130
-
131
- // Main dimension line
132
- const halfWidth = strokeWidth / 2
133
- const mainLine = [
134
- {
135
- x: fromBase.x + perpendicular.x * halfWidth,
136
- y: fromBase.y + perpendicular.y * halfWidth,
137
- },
138
- {
139
- x: fromBase.x - perpendicular.x * halfWidth,
140
- y: fromBase.y - perpendicular.y * halfWidth,
141
- },
142
- {
143
- x: toBase.x - perpendicular.x * halfWidth,
144
- y: toBase.y - perpendicular.y * halfWidth,
145
- },
146
- {
147
- x: toBase.x + perpendicular.x * halfWidth,
148
- y: toBase.y + perpendicular.y * halfWidth,
149
- },
150
- ]
151
- allPoints.push(...mainLine, mainLine[0]!)
152
-
153
- // Arrows
154
- const arrow1 = [
155
- fromOffset,
156
- {
157
- x:
158
- fromOffset.x +
159
- direction.x * arrowSize +
160
- perpendicular.x * (arrowSize / 2),
161
- y:
162
- fromOffset.y +
163
- direction.y * arrowSize +
164
- perpendicular.y * (arrowSize / 2),
165
- },
166
- {
167
- x:
168
- fromOffset.x +
169
- direction.x * arrowSize -
170
- perpendicular.x * (arrowSize / 2),
171
- y:
172
- fromOffset.y +
173
- direction.y * arrowSize -
174
- perpendicular.y * (arrowSize / 2),
175
- },
176
- ]
177
- allPoints.push(...arrow1, arrow1[0]!)
178
-
179
- const arrow2 = [
180
- toOffset,
181
- {
182
- x:
183
- toOffset.x -
184
- direction.x * arrowSize +
185
- perpendicular.x * (arrowSize / 2),
186
- y:
187
- toOffset.y -
188
- direction.y * arrowSize +
189
- perpendicular.y * (arrowSize / 2),
190
- },
191
- {
192
- x:
193
- toOffset.x -
194
- direction.x * arrowSize -
195
- perpendicular.x * (arrowSize / 2),
196
- y:
197
- toOffset.y -
198
- direction.y * arrowSize -
199
- perpendicular.y * (arrowSize / 2),
200
- },
201
- ]
202
- allPoints.push(...arrow2, arrow2[0]!)
124
+ // Unified Perimeter Approach:
125
+ // Draw the main line and both arrows as a single continuous perimeter path.
126
+ // This eliminates self-intersections and winding issues.
127
+
128
+ // 1. Tip 1
129
+ allPoints.push(fromOffset)
130
+
131
+ // 2. Arrow 1 base corner 1
132
+ allPoints.push({
133
+ x: fromBase.x + perpendicular.x * (arrowSize / 2),
134
+ y: fromBase.y + perpendicular.y * (arrowSize / 2),
135
+ })
136
+
137
+ // 3. Main Line corner 1
138
+ allPoints.push({
139
+ x: fromBase.x + perpendicular.x * (strokeWidth / 2),
140
+ y: fromBase.y + perpendicular.y * (strokeWidth / 2),
141
+ })
142
+
143
+ // 4. Main Line corner 2 (at toBase)
144
+ allPoints.push({
145
+ x: toBase.x + perpendicular.x * (strokeWidth / 2),
146
+ y: toBase.y + perpendicular.y * (strokeWidth / 2),
147
+ })
148
+
149
+ // 5. Arrow 2 base corner 1
150
+ allPoints.push({
151
+ x: toBase.x + perpendicular.x * (arrowSize / 2),
152
+ y: toBase.y + perpendicular.y * (arrowSize / 2),
153
+ })
154
+
155
+ // 6. Tip 2
156
+ allPoints.push(toOffset)
157
+
158
+ // 7. Arrow 2 base corner 2
159
+ allPoints.push({
160
+ x: toBase.x - perpendicular.x * (arrowSize / 2),
161
+ y: toBase.y - perpendicular.y * (arrowSize / 2),
162
+ })
163
+
164
+ // 8. Main Line corner 3 (at toBase)
165
+ allPoints.push({
166
+ x: toBase.x - perpendicular.x * (strokeWidth / 2),
167
+ y: toBase.y - perpendicular.y * (strokeWidth / 2),
168
+ })
169
+
170
+ // 9. Main Line corner 4 (at fromBase)
171
+ allPoints.push({
172
+ x: fromBase.x - perpendicular.x * (strokeWidth / 2),
173
+ y: fromBase.y - perpendicular.y * (strokeWidth / 2),
174
+ })
175
+
176
+ // 10. Arrow 1 base corner 2
177
+ allPoints.push({
178
+ x: fromBase.x - perpendicular.x * (arrowSize / 2),
179
+ y: fromBase.y - perpendicular.y * (arrowSize / 2),
180
+ })
181
+
182
+ // 11. Back to Tip 1
183
+ allPoints.push(fromOffset)
184
+
185
+ // Bridge Ticks (Extension lines)
186
+ const startPoint = allPoints[0]!
187
+ const addTick = (anchor: { x: number; y: number }) => {
188
+ const pts = getExtensionPoints(anchor)
189
+ allPoints.push(startPoint)
190
+ allPoints.push(pts[0]!)
191
+ allPoints.push(...pts)
192
+ allPoints.push(pts[0]!)
193
+ allPoints.push(startPoint)
194
+ }
195
+
196
+ addTick(from)
197
+ addTick(to)
203
198
 
204
199
  drawPolygon({
205
200
  ctx,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-to-canvas",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.36",
4
+ "version": "0.0.37",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup-node ./lib/index.ts --format esm --dts",