Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panel optimize #169

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions pcbdraw/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from copy import deepcopy
import decimal
import json
import math
Expand Down Expand Up @@ -135,15 +136,19 @@ def flip(self) -> None:
def matrix(data: List[List[Numeric]]) -> Matrix:
return np.array(data, dtype=np.float32)

def pseudo_distance(a: Point, b: Point) -> Numeric:
return (a[0] - b[0])**2 + (a[1] - b[1])**2
# def distance(a: Point, b: Point) -> Numeric:
# return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
Comment on lines +139 to +140
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of commenting out this function? At the moment, it is not used. However, it makes sense to have it ready to complement pseudo_distance. And if we want to get rid of it, we should delete it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented it because it isn't used, you can uncomment it when needed. Or just as a reference of what a real distance is.

I usually uncomment unused functions to avoid confusion (people might think this is used), misleading coverage results (code not covered just because is dead), avoid wasting resources, etc.


def distance(a: Point, b: Point) -> Numeric:
return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
def pseudo_distance(a: Point, b: Point) -> Numeric:
a0 = a[0] - b[0]
a1 = a[1] - b[1]
return a0*a0 + a1*a1

def get_closest(reference: Point, elems: List[Point]) -> int:
distances = [pseudo_distance(reference, x) for x in elems]
return int(np.argmin(distances))
try:
return elems.index(reference)
except ValueError:
return int(np.argmin([pseudo_distance(reference, x) for x in elems]))

def extract_arg(args: List[Any], index: int, default: Any=None) -> Any:
"""
Expand Down Expand Up @@ -694,17 +699,14 @@ def _process_outline(self, name: str, source_filename: str) -> None:

def _process_baselayer(self, name: str, source_filename: str) -> None:
clipPath = self._plotter.get_def_slot(tag_name="clipPath", id="cut-off")
clipPath.append(
get_board_polygon(
extract_svg_content(
read_svg_unique(source_filename, self._plotter.unique_prefix()))))
board_polygon = get_board_polygon(
extract_svg_content(
read_svg_unique(source_filename, self._plotter.unique_prefix())))
clipPath.append(board_polygon)

layer = etree.SubElement(self._container, "g", id="substrate-"+name,
style="fill:{0}; stroke:{0};".format(self._plotter.get_style(name)))
layer.append(
get_board_polygon(
extract_svg_content(
read_svg_unique(source_filename, self._plotter.unique_prefix()))))
layer.append(deepcopy(board_polygon))
for element in extract_svg_content(read_svg_unique(source_filename, self._plotter.unique_prefix())):
# Forbidden colors = workaround - KiCAD plots vias white
# See https://gitlab.com/kicad/code/kicad/-/issues/10491
Expand Down
Loading