From f74f2a0c42132d27856c6b024c36d9511ba2ee6b Mon Sep 17 00:00:00 2001 From: Carsten Presser Date: Thu, 12 Nov 2020 19:34:18 +0100 Subject: [PATCH] Schlib: add rounding to mm/mil conversion The new kicad_sym format uses millimeters instead of mils. That required some conversion in the check-scripts since symbols live on a 100mil grid. Unfortunately floating-point math has some rounding issues which are addressed in this commit. Resolves: #349 --- schlib/kicad_sym.py | 2 +- schlib/rules/rule.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/schlib/kicad_sym.py b/schlib/kicad_sym.py index ad8ab31a..c29799d2 100644 --- a/schlib/kicad_sym.py +++ b/schlib/kicad_sym.py @@ -122,7 +122,7 @@ def as_json(self): def compare_pos(s, x, y): if 'posx' in s.__dict__ and 'posy' in s.__dict__: - return s.posx == x and s.posy == y + return round(s.posx, 6) == round(x, 6) and round(s.posy, 6) == round(y, 6) return False @classmethod diff --git a/schlib/rules/rule.py b/schlib/rules/rule.py index df4caa44..ca8b605f 100644 --- a/schlib/rules/rule.py +++ b/schlib/rules/rule.py @@ -11,7 +11,7 @@ from rulebase import * def mil_to_mm(mil): - return mil * 0.0254 + return round(mil * 0.0254, 6) def mm_to_mil(mm): return round(mm / 0.0254)