Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Commit

Permalink
Check for duplicate lines
Browse files Browse the repository at this point in the history
Related #278
  • Loading branch information
cpresser committed Jan 25, 2019
1 parent 6511674 commit 212de8f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pcb/rules/F5_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ def check(self):

self.checkIntersections()

self.overlaps = []
self.overlaps.extend(getLinesOverlap(self.f_silk))
self.overlaps.extend(getLinesOverlap(self.b_silk))

# Display message if silkscreen has overlapping lines
if len(self.overlaps) > 0:
self.error("Silkscreen lines should not overlap.")
self.errorExtra("The following lines do overlap at least one other line")
for bad in self.overlaps:
self.errorExtra(graphItemString(bad, layer=True, width=False))

# Display message if bad silkscreen width was found
if self.bad_width:
self.error("Some silkscreen lines have incorrect width: Allowed "
Expand Down Expand Up @@ -250,6 +261,7 @@ def check(self):
# Return True if any of the checks returned an error
return any([len(self.bad_width) > 0,
len(self.intersections) > 0,
len(self.overlaps) > 0,
self.refDesError
])

Expand Down
13 changes: 13 additions & 0 deletions pcb/rules/F5_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ def check(self):
self.incorrect_width = self.checkIncorrectWidth()
self.missing_second_ref = self.checkSecondRef()

self.line_overlaps = []
self.line_overlaps.extend(getLinesOverlap(self.f_fabrication_lines))
self.line_overlaps.extend(getLinesOverlap(self.b_fabrication_lines))

# Display message if silkscreen has overlapping lines
if len(self.line_overlaps) > 0:
self.error("Fab lines should not overlap.")
self.errorExtra("The following lines do overlap at least one other line")
for bad in self.line_overlaps:
self.errorExtra(graphItemString(bad, layer=True, width=False))


if self.multiple_second_ref:
self.error("Mutliple RefDes markers found with text '%R'")

Expand All @@ -216,6 +228,7 @@ def check(self):
self.missing_lines,
self.incorrect_width,
self.missing_second_ref,
self.line_overlaps,
])

def fix(self):
Expand Down
50 changes: 50 additions & 0 deletions pcb/rules/rule.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import math
import string
import sys, os

Expand Down Expand Up @@ -36,6 +37,55 @@ def getEndPoint(graph):
else:
return None

def getLinesOverlap(lines):
# from https://stackoverflow.com/questions/328107/how-can-you-determine-a-point-is-between-two-other-points-on-a-line-segment
def distance(a,b):
return math.sqrt((a['x'] - b['x'])**2 + (a['y'] - b['y'])**2)

def is_between(a,b,c):
ac = distance(a,c)
cb = distance(c,b)
ab = distance(a,b)
d = ac + cb - ab
return d < 0.0001

overlap = []
directions = {}
# sort lines by colinearity
for line in lines:
start = getStartPoint(line)
end = getEndPoint(line)

if not start or not end:
# not sure if that can happen?
continue

dx = start['x'] - end['x']
dy = start['y'] - end['y']
line['l'] = distance(start, end)
if dx == 0:
d = 'h'
elif dy == 0:
d = 'v'
else:
d = round(dx/dy, 3)

if not d in directions:
directions[d] = []
directions[d].append(line)

for d, lines in directions.items():
for line in lines:
for line2 in lines:
if line == line2:
continue
#if is_between(line['start'], line['end'], line2['start']) or is_between(line['start'], line['end'], line2['end']):
if is_between(line['start'], line['end'], line2['start']):
if not line in overlap:
overlap.append(line)

return overlap

# Display string for a graph item
# Line / Arc / Circle
def graphItemString(graph, layer=False, width=False):
Expand Down

0 comments on commit 212de8f

Please sign in to comment.