Skip to content

Commit f943ce1

Browse files
Add dots on wires (fixes #5)
1 parent 8f37f7c commit f943ce1

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

schemascii/utils.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,23 @@ def polylinegon(points: list[complex], is_polygon: bool = False, **options):
121121
for x in points)
122122
if is_polygon:
123123
return XML.polygon(points=pts, fill=c)
124-
return XML.polyline(points=pts, fill="transparent", stroke__width=w, stroke=c)
124+
return XML.polyline(
125+
points=pts, fill="transparent", stroke__width=w, stroke=c)
126+
127+
128+
def find_dots(points: list[tuple[complex, complex]]) -> list[complex]:
129+
"Finds all the points where there are 3 or more connecting wires."
130+
seen = {}
131+
for p1, p2 in points:
132+
if p1 not in seen:
133+
seen[p1] = 1
134+
else:
135+
seen[p1] += 1
136+
if p2 not in seen:
137+
seen[p2] = 1
138+
else:
139+
seen[p2] += 1
140+
return [pt for pt, count in seen.items() if count > 2]
125141

126142

127143
def bunch_o_lines(points: list[tuple[complex, complex]], **options):
@@ -131,11 +147,11 @@ def bunch_o_lines(points: list[tuple[complex, complex]], **options):
131147
w = options["stroke_width"]
132148
c = options["stroke"]
133149
for p1, p2 in points:
134-
out += XML.line(
135-
x1=p1.real * scale,
136-
y1=p1.imag * scale,
137-
x2=p2.real * scale,
138-
y2=p2.imag * scale,
150+
out += XML.polyline(
151+
points=f"{p1.real * scale},"
152+
f"{p1.imag * scale} "
153+
f"{p2.real * scale},"
154+
f"{p2.imag * scale}",
139155
stroke=c,
140156
stroke__width=w)
141157
return out

schemascii/wires.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from cmath import phase, rect
22
from math import pi
33
from .grid import Grid
4-
from .utils import iterate_line, merge_colinear, XML
4+
from .utils import iterate_line, merge_colinear, XML, find_dots
55

66
# cSpell:ignore dydx
77

@@ -115,6 +115,7 @@ def next_wire(grid: Grid, **options) -> str | None:
115115
blank_wire(grid, p1, p2)
116116
if p1 == p2:
117117
raise RuntimeError("0-length wire")
118+
dots = find_dots(line_pieces)
118119
return XML.g(
119120
*(
120121
XML.line(
@@ -123,10 +124,16 @@ def next_wire(grid: Grid, **options) -> str | None:
123124
x2=p2.real * scale,
124125
y2=p2.imag * scale,
125126
stroke__width=stroke_width,
126-
stroke=color,
127-
)
128-
for p1, p2 in line_pieces
129-
),
127+
stroke=color)
128+
for p1, p2 in line_pieces),
129+
*(
130+
XML.circle(
131+
cx=pt.real * scale,
132+
cy=pt.imag * scale,
133+
r=2 * stroke_width,
134+
stroke="none",
135+
fill=color)
136+
for pt in dots),
130137
class_="wire")
131138

132139

schemascii_example.css

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ svg.schemascii .wire line {
1111
transition-duration: 0.2s;
1212
}
1313

14+
svg.schemascii .wire circle {
15+
fill: var(--sch-color, blue);
16+
transition-duration: 0.2s;
17+
}
18+
1419
svg.schemascii :is(.wire, .component):hover {
1520
--sch-color: lime;
1621
}

0 commit comments

Comments
 (0)