Skip to content

Commit 67b1c43

Browse files
transistors are done!
1 parent e3a80df commit 67b1c43

8 files changed

+43
-6
lines changed
44.6 KB
Binary file not shown.

dist/schemascii-0.2.1.tar.gz

54.7 KB
Binary file not shown.

format.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ For simple components, this is usually just a value rating, but *without* the un
5656
Examples:
5757

5858
* `C33:2.2u` -- "2.2 µF"
59-
* `Q1001:pnp:TIP102` -- "pnp" or "npn" to determine what kind of transistor, just the part number; printed verbatim
59+
* `Q1001:pnp:TIP102` -- "pnp", "npn", "pfet", or "nfet" to determine what kind of transistor, plus the part number; printed verbatim
6060
* `L51:0.33` -- this is rewritten to "330 mH" so that it has no decimal point.
6161
* `F3:1500m` -- rewritten: "1.5 A"
6262
* `D7:1N4001` -- again, part number

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "schemascii"
7-
version = "0.2.0"
7+
version = "0.2.1"
88
description = "Render ASCII-art schematics to SVG"
99
readme = "README.md"
1010
authors = [{ name = "dragoncoder047", email = "101021094+dragoncoder047@users.noreply.github.com" }]

schemascii/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .utils import XML
99
from .errors import *
1010

11-
__version__ = "0.2.0"
11+
__version__ = "0.2.1"
1212

1313

1414
def render(filename: str, text: str = None, **options) -> str:

schemascii/components_render.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
sort_counterclockwise, light_arrows, sort_for_flags, is_clockwise)
99
from .errors import TerminalsError, BOMError, UnsupportedComponentError
1010

11+
# pylint: disable=unbalanced-tuple-unpacking
12+
1113
RENDERERS = {}
1214

1315

@@ -311,7 +313,22 @@ def transistor(
311313
else:
312314
ae, se, ctl = sort_for_flags(terminals, box, "e", "c", "b")
313315
ap, sp = ae.pt, se.pt
314-
mid = (ap + sp) / 2 # TODO: slide this to line up with middle
316+
diff = sp - ap
317+
try:
318+
slope = diff.imag / diff.real
319+
except ZeroDivisionError:
320+
mid = complex(ap.real, ctl.pt.imag)
321+
else:
322+
try:
323+
diff.real / diff.imag
324+
except ZeroDivisionError:
325+
mid = complex(ctl.pt.real, ap.imag)
326+
else:
327+
# From wolfram alpha "solve m*(x-x1)+y1=(-1/m)*(x-x2)+y2 for x"
328+
# x = (m^2 x1 - m y1 + m y2 + x2)/(m^2 + 1)
329+
mid_x = (slope ** 2 * ap.real - slope * ap.imag + slope *
330+
ctl.pt.imag + ctl.pt.real) / (slope ** 2 + 1)
331+
mid = complex(mid_x, slope * (mid_x - ap.real) + ap.imag)
315332
theta = phase(ap - sp)
316333
backwards = 1 if is_clockwise([ae, se, ctl]) else -1
317334
thetaquarter = theta + (backwards * pi / 2)
@@ -343,6 +360,7 @@ def transistor(
343360
(mid + rect(1, theta) + rect(1, thetaquarter),
344361
mid - rect(1, theta) + rect(1, thetaquarter)),
345362
])
363+
out_lines.append((mid + rect(1, thetaquarter), ctl.pt))
346364
text_pt = make_text_point(ap, sp, **options)
347365
return (id_text(box, bom_data, [ae, se], None, text_pt, **options)
348366
+ bunch_o_lines(out_lines, **options))

schemascii/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ def find_dots(points: list[tuple[complex, complex]]) -> list[complex]:
157157

158158

159159
def bunch_o_lines(points: list[tuple[complex, complex]], **options):
160-
"Return a <line> for each pair of points."
160+
"Return a <polyline> for each pair of points."
161161
out = ''
162162
scale = options['scale']
163163
w = options["stroke_width"]
164164
c = options["stroke"]
165165
for p1, p2 in points:
166+
if abs(p1 - p2) == 0:
167+
continue
166168
out += XML.polyline(
167169
points=f"{p1.real * scale},"
168170
f"{p1.imag * scale} "
@@ -243,7 +245,7 @@ def make_plus(
243245
def arrow_points(p1: complex, p2: complex) -> list[tuple[complex, complex]]:
244246
"Return points to make an arrow from p1 pointing to p2."
245247
angle = phase(p2 - p1)
246-
tick_len = min(0.25, abs(p2 - p1))
248+
tick_len = min(0.5, abs(p2 - p1))
247249
return [
248250
(p2, p1),
249251
(p2, p2 - rect(tick_len, angle + pi/5)),

test_data/test1.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,21 @@
2929
-------eQ4c-----
3030
b Q4:npn:TIP103
3131
*------
32+
33+
--------*
34+
e
35+
.~~~~~.
36+
: :
37+
-------b: Q9 : Q9:pnp:7476
38+
: :
39+
: :
40+
: :
41+
.~~~~~.
42+
c
43+
|
44+
|
45+
46+
47+
48+
3249
!padding=30!

0 commit comments

Comments
 (0)