Skip to content

Commit

Permalink
Schlib: add rounding to mm/mil conversion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cpresser committed Nov 12, 2020
1 parent 31630e1 commit f74f2a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion schlib/kicad_sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion schlib/rules/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f74f2a0

Please sign in to comment.