Skip to content

Commit

Permalink
transistors are done!
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoncoder047 authored Mar 6, 2023
1 parent e3a80df commit 67b1c43
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
Binary file added dist/schemascii-0.2.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/schemascii-0.2.1.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion format.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ For simple components, this is usually just a value rating, but *without* the un
Examples:

* `C33:2.2u` -- "2.2 µF"
* `Q1001:pnp:TIP102` -- "pnp" or "npn" to determine what kind of transistor, just the part number; printed verbatim
* `Q1001:pnp:TIP102` -- "pnp", "npn", "pfet", or "nfet" to determine what kind of transistor, plus the part number; printed verbatim
* `L51:0.33` -- this is rewritten to "330 mH" so that it has no decimal point.
* `F3:1500m` -- rewritten: "1.5 A"
* `D7:1N4001` -- again, part number
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "schemascii"
version = "0.2.0"
version = "0.2.1"
description = "Render ASCII-art schematics to SVG"
readme = "README.md"
authors = [{ name = "dragoncoder047", email = "[email protected]" }]
Expand Down
2 changes: 1 addition & 1 deletion schemascii/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .utils import XML
from .errors import *

__version__ = "0.2.0"
__version__ = "0.2.1"


def render(filename: str, text: str = None, **options) -> str:
Expand Down
20 changes: 19 additions & 1 deletion schemascii/components_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
sort_counterclockwise, light_arrows, sort_for_flags, is_clockwise)
from .errors import TerminalsError, BOMError, UnsupportedComponentError

# pylint: disable=unbalanced-tuple-unpacking

RENDERERS = {}


Expand Down Expand Up @@ -311,7 +313,22 @@ def transistor(
else:
ae, se, ctl = sort_for_flags(terminals, box, "e", "c", "b")
ap, sp = ae.pt, se.pt
mid = (ap + sp) / 2 # TODO: slide this to line up with middle
diff = sp - ap
try:
slope = diff.imag / diff.real
except ZeroDivisionError:
mid = complex(ap.real, ctl.pt.imag)
else:
try:
diff.real / diff.imag
except ZeroDivisionError:
mid = complex(ctl.pt.real, ap.imag)
else:
# From wolfram alpha "solve m*(x-x1)+y1=(-1/m)*(x-x2)+y2 for x"
# x = (m^2 x1 - m y1 + m y2 + x2)/(m^2 + 1)
mid_x = (slope ** 2 * ap.real - slope * ap.imag + slope *
ctl.pt.imag + ctl.pt.real) / (slope ** 2 + 1)
mid = complex(mid_x, slope * (mid_x - ap.real) + ap.imag)
theta = phase(ap - sp)
backwards = 1 if is_clockwise([ae, se, ctl]) else -1
thetaquarter = theta + (backwards * pi / 2)
Expand Down Expand Up @@ -343,6 +360,7 @@ def transistor(
(mid + rect(1, theta) + rect(1, thetaquarter),
mid - rect(1, theta) + rect(1, thetaquarter)),
])
out_lines.append((mid + rect(1, thetaquarter), ctl.pt))
text_pt = make_text_point(ap, sp, **options)
return (id_text(box, bom_data, [ae, se], None, text_pt, **options)
+ bunch_o_lines(out_lines, **options))
Expand Down
6 changes: 4 additions & 2 deletions schemascii/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,14 @@ def find_dots(points: list[tuple[complex, complex]]) -> list[complex]:


def bunch_o_lines(points: list[tuple[complex, complex]], **options):
"Return a <line> for each pair of points."
"Return a <polyline> for each pair of points."
out = ''
scale = options['scale']
w = options["stroke_width"]
c = options["stroke"]
for p1, p2 in points:
if abs(p1 - p2) == 0:
continue
out += XML.polyline(
points=f"{p1.real * scale},"
f"{p1.imag * scale} "
Expand Down Expand Up @@ -243,7 +245,7 @@ def make_plus(
def arrow_points(p1: complex, p2: complex) -> list[tuple[complex, complex]]:
"Return points to make an arrow from p1 pointing to p2."
angle = phase(p2 - p1)
tick_len = min(0.25, abs(p2 - p1))
tick_len = min(0.5, abs(p2 - p1))
return [
(p2, p1),
(p2, p2 - rect(tick_len, angle + pi/5)),
Expand Down
17 changes: 17 additions & 0 deletions test_data/test1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,21 @@
-------eQ4c-----
b Q4:npn:TIP103
*------

--------*
e
.~~~~~.
: :
-------b: Q9 : Q9:pnp:7476
: :
: :
: :
.~~~~~.
c
|
|




!padding=30!

0 comments on commit 67b1c43

Please sign in to comment.