@tscircuit/schematic-trace-solver 0.0.61 → 0.0.63
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.d.ts +71 -5
- package/dist/index.js +421 -16
- package/lib/solvers/AvailableNetOrientationSolver/AvailableNetOrientationSolver.ts +16 -0
- package/lib/solvers/NetLabelNetLabelCollisionSolver/NetLabelNetLabelCollisionSolver.ts +449 -0
- package/lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver.ts +24 -0
- package/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/SingleNetLabelPlacementSolver.ts +7 -1
- package/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/geometry.ts +9 -4
- package/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/solvePortOnlyPin.ts +3 -0
- package/lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts +15 -0
- package/lib/solvers/TraceAnchoredNetLabelOverlapSolver/candidates.ts +19 -0
- package/lib/types/InputProblem.ts +1 -0
- package/package.json +1 -1
- package/site/examples/example39.page.tsx +4 -0
- package/site/examples/example40.page.tsx +4 -0
- package/site/examples/example41.page.tsx +4 -0
- package/tests/assets/example39.json +71 -0
- package/tests/assets/example40.json +157 -0
- package/tests/assets/example41.json +82 -0
- package/tests/examples/__snapshots__/example39.snap.svg +107 -0
- package/tests/examples/__snapshots__/example40.snap.svg +231 -0
- package/tests/examples/__snapshots__/example41.snap.svg +119 -0
- package/tests/examples/example39.test.ts +12 -0
- package/tests/examples/example40.test.ts +12 -0
- package/tests/examples/example41.test.ts +12 -0
|
@@ -30,6 +30,7 @@ export const generateCandidatesAlongTrace = (params: {
|
|
|
30
30
|
getTraceVertexDistances(traceLocation.trace),
|
|
31
31
|
)
|
|
32
32
|
const netLabelWidth = getNetLabelWidth(inputProblem, label)
|
|
33
|
+
const netLabelHeight = getNetLabelHeight(inputProblem, label)
|
|
33
34
|
const candidates: LabelCandidate[] = []
|
|
34
35
|
const seenCandidateKeys = new Set<string>()
|
|
35
36
|
|
|
@@ -55,6 +56,7 @@ export const generateCandidatesAlongTrace = (params: {
|
|
|
55
56
|
point,
|
|
56
57
|
orientation,
|
|
57
58
|
netLabelWidth,
|
|
59
|
+
netLabelHeight,
|
|
58
60
|
traceLocation,
|
|
59
61
|
pathDistance,
|
|
60
62
|
label,
|
|
@@ -109,6 +111,7 @@ const createCandidate = (params: {
|
|
|
109
111
|
point: Point
|
|
110
112
|
orientation: FacingDirection
|
|
111
113
|
netLabelWidth: number
|
|
114
|
+
netLabelHeight?: number
|
|
112
115
|
traceLocation: TraceLocation
|
|
113
116
|
pathDistance: number
|
|
114
117
|
label: NetLabelPlacement
|
|
@@ -117,6 +120,7 @@ const createCandidate = (params: {
|
|
|
117
120
|
point,
|
|
118
121
|
orientation,
|
|
119
122
|
netLabelWidth,
|
|
123
|
+
netLabelHeight,
|
|
120
124
|
traceLocation,
|
|
121
125
|
pathDistance,
|
|
122
126
|
label,
|
|
@@ -124,6 +128,7 @@ const createCandidate = (params: {
|
|
|
124
128
|
const { width, height } = getDimsForOrientation({
|
|
125
129
|
orientation,
|
|
126
130
|
netLabelWidth,
|
|
131
|
+
netLabelHeight,
|
|
127
132
|
})
|
|
128
133
|
|
|
129
134
|
return {
|
|
@@ -360,6 +365,20 @@ const getNetLabelWidth = (
|
|
|
360
365
|
return label.width
|
|
361
366
|
}
|
|
362
367
|
|
|
368
|
+
const getNetLabelHeight = (
|
|
369
|
+
inputProblem: InputProblem,
|
|
370
|
+
label: NetLabelPlacement,
|
|
371
|
+
): number | undefined => {
|
|
372
|
+
const ncHeightByNetId = inputProblem.netConnections.find(
|
|
373
|
+
(connection) => connection.netId === label.netId,
|
|
374
|
+
)?.netLabelHeight
|
|
375
|
+
if (ncHeightByNetId !== undefined) return ncHeightByNetId
|
|
376
|
+
|
|
377
|
+
return inputProblem.netConnections.find((nc) =>
|
|
378
|
+
nc.pinIds.some((pid) => label.pinIds.includes(pid)),
|
|
379
|
+
)?.netLabelHeight
|
|
380
|
+
}
|
|
381
|
+
|
|
363
382
|
const roundDistance = (distance: number) => Number(distance.toFixed(6))
|
|
364
383
|
|
|
365
384
|
const dedupeOrientations = (orientations: FacingDirection[]) => [
|
package/package.json
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"chips": [
|
|
3
|
+
{
|
|
4
|
+
"chipId": "schematic_component_0",
|
|
5
|
+
"center": {
|
|
6
|
+
"x": -6.5,
|
|
7
|
+
"y": -0.33
|
|
8
|
+
},
|
|
9
|
+
"width": 1.5,
|
|
10
|
+
"height": 0.8,
|
|
11
|
+
"pins": [
|
|
12
|
+
{
|
|
13
|
+
"pinId": "U3.24",
|
|
14
|
+
"x": -7.65,
|
|
15
|
+
"y": -0.22999999999999998
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"pinId": "U3.25",
|
|
19
|
+
"x": -7.65,
|
|
20
|
+
"y": -0.43000000000000016
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"sectionId": "rp2040"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"chipId": "schematic_component_4",
|
|
27
|
+
"center": {
|
|
28
|
+
"x": -9.5,
|
|
29
|
+
"y": -0.4299999999999997
|
|
30
|
+
},
|
|
31
|
+
"width": 1.1,
|
|
32
|
+
"height": 0.388910699999999,
|
|
33
|
+
"pins": [
|
|
34
|
+
{
|
|
35
|
+
"pinId": "R5.1",
|
|
36
|
+
"x": -10.049999999999999,
|
|
37
|
+
"y": -0.4299999999999997
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"pinId": "R5.2",
|
|
41
|
+
"x": -8.95,
|
|
42
|
+
"y": -0.4299999999999997
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"sectionId": "rp2040"
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"directConnections": [
|
|
49
|
+
{
|
|
50
|
+
"pinIds": ["U3.25", "R5.2"],
|
|
51
|
+
"netId": ".U3 > .pin25 to .R5 > .pin2"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"netConnections": [
|
|
55
|
+
{
|
|
56
|
+
"netId": "SWCLK",
|
|
57
|
+
"pinIds": ["U3.24"],
|
|
58
|
+
"netLabelWidth": 0.72
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"netId": "SWD",
|
|
62
|
+
"pinIds": ["U3.25", "R5.2"],
|
|
63
|
+
"netLabelWidth": 0.48
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"availableNetLabelOrientations": {
|
|
67
|
+
"SWCLK": ["x-", "x+"],
|
|
68
|
+
"SWD": ["x-", "x+"]
|
|
69
|
+
},
|
|
70
|
+
"maxMspPairDistance": 2.4
|
|
71
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
{
|
|
2
|
+
"chips": [
|
|
3
|
+
{
|
|
4
|
+
"chipId": "J2",
|
|
5
|
+
"center": {
|
|
6
|
+
"x": 0,
|
|
7
|
+
"y": 0
|
|
8
|
+
},
|
|
9
|
+
"width": 0.65,
|
|
10
|
+
"height": 1.8,
|
|
11
|
+
"pins": [
|
|
12
|
+
{
|
|
13
|
+
"pinId": "J2.1",
|
|
14
|
+
"x": 0.325,
|
|
15
|
+
"y": 0.8
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"pinId": "J2.2",
|
|
19
|
+
"x": 0.325,
|
|
20
|
+
"y": 0.6
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"pinId": "J2.3",
|
|
24
|
+
"x": 0.325,
|
|
25
|
+
"y": 0.4
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"pinId": "J2.4",
|
|
29
|
+
"x": 0.325,
|
|
30
|
+
"y": 0.2
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"pinId": "J2.5",
|
|
34
|
+
"x": 0.325,
|
|
35
|
+
"y": 0
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"pinId": "J2.6",
|
|
39
|
+
"x": 0.325,
|
|
40
|
+
"y": -0.2
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"pinId": "J2.7",
|
|
44
|
+
"x": 0.325,
|
|
45
|
+
"y": -0.4
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"pinId": "J2.8",
|
|
49
|
+
"x": 0.325,
|
|
50
|
+
"y": -0.6
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"pinId": "J2.9",
|
|
54
|
+
"x": 0.325,
|
|
55
|
+
"y": -0.8
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"chipId": "U1",
|
|
61
|
+
"center": {
|
|
62
|
+
"x": 4,
|
|
63
|
+
"y": 0.4
|
|
64
|
+
},
|
|
65
|
+
"width": 1,
|
|
66
|
+
"height": 2,
|
|
67
|
+
"pins": [
|
|
68
|
+
{
|
|
69
|
+
"pinId": "U1.1",
|
|
70
|
+
"x": 3.5,
|
|
71
|
+
"y": 1.2
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"pinId": "U1.2",
|
|
75
|
+
"x": 3.5,
|
|
76
|
+
"y": 0.8
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"pinId": "U1.3",
|
|
80
|
+
"x": 3.5,
|
|
81
|
+
"y": 0.4
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"pinId": "U1.4",
|
|
85
|
+
"x": 3.5,
|
|
86
|
+
"y": 0
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"pinId": "U1.5",
|
|
90
|
+
"x": 3.5,
|
|
91
|
+
"y": -0.4
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"pinId": "U1.6",
|
|
95
|
+
"x": 4.5,
|
|
96
|
+
"y": 1
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"pinId": "U1.7",
|
|
100
|
+
"x": 4.5,
|
|
101
|
+
"y": 0.6
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"pinId": "U1.8",
|
|
105
|
+
"x": 4.5,
|
|
106
|
+
"y": 0.2
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"pinId": "U1.9",
|
|
110
|
+
"x": 4.5,
|
|
111
|
+
"y": -0.2
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"directConnections": [
|
|
117
|
+
{
|
|
118
|
+
"pinIds": ["J2.1", "U1.1"],
|
|
119
|
+
"netId": "J2.pin1 to U1.pin1"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"pinIds": ["J2.2", "U1.2"],
|
|
123
|
+
"netId": "J2.pin2 to U1.pin2"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"pinIds": ["J2.3", "U1.3"],
|
|
127
|
+
"netId": "J2.pin3 to U1.pin3"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"pinIds": ["J2.4", "U1.4"],
|
|
131
|
+
"netId": "J2.pin4 to U1.pin4"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"pinIds": ["J2.5", "U1.5"],
|
|
135
|
+
"netId": "J2.pin5 to U1.pin5"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"pinIds": ["J2.6", "U1.6"],
|
|
139
|
+
"netId": "J2.pin6 to U1.pin6"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"pinIds": ["J2.7", "U1.7"],
|
|
143
|
+
"netId": "J2.pin7 to U1.pin7"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"pinIds": ["J2.8", "U1.8"],
|
|
147
|
+
"netId": "J2.pin8 to U1.pin8"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"pinIds": ["J2.9", "U1.9"],
|
|
151
|
+
"netId": "J2.pin9 to U1.pin9"
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
"netConnections": [],
|
|
155
|
+
"availableNetLabelOrientations": {},
|
|
156
|
+
"maxMspPairDistance": 5
|
|
157
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"chips": [
|
|
3
|
+
{
|
|
4
|
+
"chipId": "schematic_component_0",
|
|
5
|
+
"center": {
|
|
6
|
+
"x": -6.5,
|
|
7
|
+
"y": -0.33
|
|
8
|
+
},
|
|
9
|
+
"width": 1.5,
|
|
10
|
+
"height": 1.5,
|
|
11
|
+
"pins": [
|
|
12
|
+
{
|
|
13
|
+
"pinId": "U3.24",
|
|
14
|
+
"x": -7.65,
|
|
15
|
+
"y": -0.22999999999999998
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"pinId": "U3.25",
|
|
19
|
+
"x": -7.65,
|
|
20
|
+
"y": -0.43000000000000016
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"pinId": "U3.26",
|
|
24
|
+
"x": -7.65,
|
|
25
|
+
"y": -0.63000000000000016
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"sectionId": "rp2040"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"chipId": "schematic_component_4",
|
|
32
|
+
"center": {
|
|
33
|
+
"x": -9.5,
|
|
34
|
+
"y": -0.4299999999999997
|
|
35
|
+
},
|
|
36
|
+
"width": 1.1,
|
|
37
|
+
"height": 0.388910699999999,
|
|
38
|
+
"pins": [
|
|
39
|
+
{
|
|
40
|
+
"pinId": "R5.1",
|
|
41
|
+
"x": -10.049999999999999,
|
|
42
|
+
"y": -0.4299999999999997
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"pinId": "R5.2",
|
|
46
|
+
"x": -8.95,
|
|
47
|
+
"y": -0.4299999999999997
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"sectionId": "rp2040"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"directConnections": [
|
|
54
|
+
{
|
|
55
|
+
"pinIds": ["U3.25", "R5.2"],
|
|
56
|
+
"netId": ".U3 > .pin25 to .R5 > .pin2"
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"netConnections": [
|
|
60
|
+
{
|
|
61
|
+
"netId": "SWCLK",
|
|
62
|
+
"pinIds": ["U3.24"],
|
|
63
|
+
"netLabelWidth": 0.72
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"netId": "SWD",
|
|
67
|
+
"pinIds": ["U3.25", "R5.2"],
|
|
68
|
+
"netLabelWidth": 0.48,
|
|
69
|
+
"netLabelHeight": 0.48
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"netId": "CLK",
|
|
73
|
+
"pinIds": ["U3.26"],
|
|
74
|
+
"netLabelWidth": 0.72
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
"availableNetLabelOrientations": {
|
|
78
|
+
"SWCLK": ["x-", "x+"],
|
|
79
|
+
"SWD": ["x-", "x+"]
|
|
80
|
+
},
|
|
81
|
+
"maxMspPairDistance": 2.4
|
|
82
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<svg width="640" height="640" viewBox="0 0 640 640" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<rect width="100%" height="100%" fill="white" />
|
|
3
|
+
<g>
|
|
4
|
+
<circle data-type="point" data-label="U3.24
|
|
5
|
+
x-" data-x="-7.65" data-y="-0.22999999999999998" cx="325.9574468085108" cy="297.3557446808511" r="3" fill="hsl(74, 100%, 50%, 0.8)" />
|
|
6
|
+
</g>
|
|
7
|
+
<g>
|
|
8
|
+
<circle data-type="point" data-label="U3.25
|
|
9
|
+
x-" data-x="-7.65" data-y="-0.43000000000000016" cx="325.9574468085108" cy="321.18553191489366" r="3" fill="hsl(75, 100%, 50%, 0.8)" />
|
|
10
|
+
</g>
|
|
11
|
+
<g>
|
|
12
|
+
<circle data-type="point" data-label="R5.1
|
|
13
|
+
x-" data-x="-10.05" data-y="-0.4299999999999997" cx="40.00000000000023" cy="321.1855319148936" r="3" fill="hsl(110, 100%, 50%, 0.8)" />
|
|
14
|
+
</g>
|
|
15
|
+
<g>
|
|
16
|
+
<circle data-type="point" data-label="R5.2
|
|
17
|
+
x+" data-x="-8.95" data-y="-0.4299999999999997" cx="171.06382978723423" cy="321.1855319148936" r="3" fill="hsl(111, 100%, 50%, 0.8)" />
|
|
18
|
+
</g>
|
|
19
|
+
<g>
|
|
20
|
+
<circle data-type="point" data-label="anchorPoint
|
|
21
|
+
orientation: x-" data-x="-7.65" data-y="-0.22999999999999998" cx="325.9574468085108" cy="297.3557446808511" r="3" fill="hsl(40, 100%, 50%, 0.9)" />
|
|
22
|
+
</g>
|
|
23
|
+
<g>
|
|
24
|
+
<circle data-type="point" data-label="anchorPoint
|
|
25
|
+
orientation: y-" data-x="-7.8500000000000005" data-y="-0.4300000000000001" cx="302.1276595744682" cy="321.18553191489366" r="3" fill="hsl(40, 100%, 50%, 0.9)" />
|
|
26
|
+
</g>
|
|
27
|
+
<g>
|
|
28
|
+
<polyline data-points="-7.65,-0.43000000000000016 -8.95,-0.4299999999999997" data-type="line" data-label="" points="325.9574468085108,321.18553191489366 171.06382978723423,321.1855319148936" fill="none" stroke="hsl(80, 100%, 50%, 0.8)" stroke-width="1" />
|
|
29
|
+
</g>
|
|
30
|
+
<g>
|
|
31
|
+
<polyline data-points="-7.65,-0.43000000000000016 -8.95,-0.4299999999999997" data-type="line" data-label="" points="325.9574468085108,321.18553191489366 171.06382978723423,321.1855319148936" fill="none" stroke="hsl(88, 100%, 50%, 0.8)" stroke-width="1" stroke-dasharray="4 2" />
|
|
32
|
+
</g>
|
|
33
|
+
<g>
|
|
34
|
+
<polyline data-points="-7.65,-0.43000000000000016 -8.95,-0.4299999999999997" data-type="line" data-label="" points="325.9574468085108,321.18553191489366 171.06382978723423,321.1855319148936" fill="none" stroke="purple" stroke-width="1" />
|
|
35
|
+
</g>
|
|
36
|
+
<g>
|
|
37
|
+
<rect data-type="rect" data-label="schematic_component_0" data-x="-6.5" data-y="-0.33" x="325.9574468085108" y="261.61106382978727" width="274.04255319148933" height="95.31914893617017" fill="hsl(24, 100%, 50%, 0.8)" stroke="black" stroke-width="0.008392857142857145" />
|
|
38
|
+
</g>
|
|
39
|
+
<g>
|
|
40
|
+
<rect data-type="rect" data-label="schematic_component_4" data-x="-9.5" data-y="-0.4299999999999997" x="40.00000000000023" y="298.0163838297873" width="131.063829787234" height="46.33829617021263" fill="hsl(24, 100%, 50%, 0.8)" stroke="black" stroke-width="0.008392857142857145" />
|
|
41
|
+
</g>
|
|
42
|
+
<g>
|
|
43
|
+
<rect data-type="rect" data-label="netId: SWCLK
|
|
44
|
+
globalConnNetId: connectivity_net1" data-x="-8.011" data-y="-0.22999999999999998" x="240.0510638297876" y="285.4408510638298" width="85.78723404255311" height="23.829787234042556" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.008392857142857145" />
|
|
45
|
+
</g>
|
|
46
|
+
<g>
|
|
47
|
+
<rect data-type="rect" data-label="netId: SWD
|
|
48
|
+
globalConnNetId: connectivity_net0" data-x="-7.8500000000000005" data-y="-0.6701000000000001" x="290.212765957447" y="321.1974468085107" width="23.829787234042442" height="57.19148936170211" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.008392857142857145" />
|
|
49
|
+
</g>
|
|
50
|
+
<g id="crosshair" style="display: none">
|
|
51
|
+
<line id="crosshair-h" y1="0" y2="640" stroke="#666" stroke-width="0.5" />
|
|
52
|
+
<line id="crosshair-v" x1="0" x2="640" stroke="#666" stroke-width="0.5" /><text id="coordinates" font-family="monospace" font-size="12" fill="#666"></text>
|
|
53
|
+
</g>
|
|
54
|
+
<script>
|
|
55
|
+
<![CDATA[
|
|
56
|
+
document.currentScript.parentElement.addEventListener('mousemove', (e) => {
|
|
57
|
+
const svg = e.currentTarget;
|
|
58
|
+
const rect = svg.getBoundingClientRect();
|
|
59
|
+
const x = e.clientX - rect.left;
|
|
60
|
+
const y = e.clientY - rect.top;
|
|
61
|
+
const crosshair = svg.getElementById('crosshair');
|
|
62
|
+
const h = svg.getElementById('crosshair-h');
|
|
63
|
+
const v = svg.getElementById('crosshair-v');
|
|
64
|
+
const coords = svg.getElementById('coordinates');
|
|
65
|
+
|
|
66
|
+
crosshair.style.display = 'block';
|
|
67
|
+
h.setAttribute('x1', '0');
|
|
68
|
+
h.setAttribute('x2', '640');
|
|
69
|
+
h.setAttribute('y1', y);
|
|
70
|
+
h.setAttribute('y2', y);
|
|
71
|
+
v.setAttribute('x1', x);
|
|
72
|
+
v.setAttribute('x2', x);
|
|
73
|
+
v.setAttribute('y1', '0');
|
|
74
|
+
v.setAttribute('y2', '640');
|
|
75
|
+
|
|
76
|
+
// Calculate real coordinates using inverse transformation
|
|
77
|
+
const matrix = {
|
|
78
|
+
"a": 119.14893617021274,
|
|
79
|
+
"c": 0,
|
|
80
|
+
"e": 1237.4468085106382,
|
|
81
|
+
"b": 0,
|
|
82
|
+
"d": -119.14893617021274,
|
|
83
|
+
"f": 269.95148936170216
|
|
84
|
+
};
|
|
85
|
+
// Manually invert and apply the affine transform
|
|
86
|
+
// Since we only use translate and scale, we can directly compute:
|
|
87
|
+
// x' = (x - tx) / sx
|
|
88
|
+
// y' = (y - ty) / sy
|
|
89
|
+
const sx = matrix.a;
|
|
90
|
+
const sy = matrix.d;
|
|
91
|
+
const tx = matrix.e;
|
|
92
|
+
const ty = matrix.f;
|
|
93
|
+
const realPoint = {
|
|
94
|
+
x: (x - tx) / sx,
|
|
95
|
+
y: (y - ty) / sy // Flip y back since we used negative scale
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
coords.textContent = `(${realPoint.x.toFixed(2)}, ${realPoint.y.toFixed(2)})`;
|
|
99
|
+
coords.setAttribute('x', (x + 5).toString());
|
|
100
|
+
coords.setAttribute('y', (y - 5).toString());
|
|
101
|
+
});
|
|
102
|
+
document.currentScript.parentElement.addEventListener('mouseleave', () => {
|
|
103
|
+
document.currentScript.parentElement.getElementById('crosshair').style.display = 'none';
|
|
104
|
+
});
|
|
105
|
+
]]>
|
|
106
|
+
</script>
|
|
107
|
+
</svg>
|