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
|
|
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 *
|
|
1777
|
-
y: anchor.y + extPerpendicular.y *
|
|
1776
|
+
x: anchor.x + extPerpendicular.x * halfWidth,
|
|
1777
|
+
y: anchor.y + extPerpendicular.y * halfWidth
|
|
1778
1778
|
},
|
|
1779
1779
|
{
|
|
1780
|
-
x: anchor.x - extPerpendicular.x *
|
|
1781
|
-
y: anchor.y - extPerpendicular.y *
|
|
1780
|
+
x: anchor.x - extPerpendicular.x * halfWidth,
|
|
1781
|
+
y: anchor.y - extPerpendicular.y * halfWidth
|
|
1782
1782
|
},
|
|
1783
1783
|
{
|
|
1784
|
-
x: endPoint.x - extPerpendicular.x *
|
|
1785
|
-
y: endPoint.y - extPerpendicular.y *
|
|
1784
|
+
x: endPoint.x - extPerpendicular.x * halfWidth,
|
|
1785
|
+
y: endPoint.y - extPerpendicular.y * halfWidth
|
|
1786
1786
|
},
|
|
1787
1787
|
{
|
|
1788
|
-
x: endPoint.x + extPerpendicular.x *
|
|
1789
|
-
y: endPoint.y + extPerpendicular.y *
|
|
1788
|
+
x: endPoint.x + extPerpendicular.x * halfWidth,
|
|
1789
|
+
y: endPoint.y + extPerpendicular.y * halfWidth
|
|
1790
1790
|
}
|
|
1791
1791
|
];
|
|
1792
1792
|
};
|
|
1793
|
-
|
|
1794
|
-
allPoints.push(
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
allPoints
|
|
1829
|
-
const
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
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
|
|
1874
|
+
const halfWidth = textWidth / 2;
|
|
1877
1875
|
const halfHeight = textHeight / 2;
|
|
1878
|
-
const maxExtension =
|
|
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
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
allPoints.push(
|
|
130
|
-
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
allPoints.push(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
Binary file
|