From 29c0d82bf53907030d11df9eb09471b716a0be2e Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sat, 27 Feb 2016 15:24:36 +0800 Subject: RS274X backend for rendering. Incompelte still --- gerber/primitives.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'gerber/primitives.py') diff --git a/gerber/primitives.py b/gerber/primitives.py index 84115a6..21efb55 100644 --- a/gerber/primitives.py +++ b/gerber/primitives.py @@ -17,8 +17,9 @@ import math from operator import add, sub -from .utils import validate_coordinates, inch, metric, rotate_point +from .utils import validate_coordinates, inch, metric, rotate_point, nearly_equal from jsonpickle.util import PRIMITIVES +from __builtin__ import False class Primitive(object): @@ -120,6 +121,9 @@ class Primitive(object): def __eq__(self, other): return self.__dict__ == other.__dict__ + + def to_statement(self): + pass class Line(Primitive): @@ -216,7 +220,16 @@ class Line(Primitive): def offset(self, x_offset=0, y_offset=0): self.start = tuple(map(add, self.start, (x_offset, y_offset))) self.end = tuple(map(add, self.end, (x_offset, y_offset))) + + def equivalent(self, other, offset): + + if not isinstance(other, Line): + return False + + equiv_start = tuple(map(add, other.start, offset)) + equiv_end = tuple(map(add, other.end, offset)) + return nearly_equal(self.start, equiv_start) and nearly_equal(self.end, equiv_end) class Arc(Primitive): """ @@ -736,7 +749,7 @@ class AMGroup(Primitive): elif prim: self.primitives.append(prim) self._position = None - self._to_convert = ['arimitives'] + self._to_convert = ['primitives'] @property def flashed(self): @@ -776,6 +789,21 @@ class AMGroup(Primitive): self._position = new_pos + def equivalent(self, other, offset): + ''' + Is this the macro group the same as the other, ignoring the position offset? + ''' + + if len(self.primitives) != len(other.primitives): + return False + + # We know they have the same number of primitives, so now check them all + for i in range(0, len(self.primitives)): + if not self.primitives[i].equivalent(other.primitives[i], offset): + return False + + # If we didn't find any differences, then they are the same + return True class Outline(Primitive): """ @@ -816,6 +844,20 @@ class Outline(Primitive): bounding_box = self.bounding_box() return bounding_box[1][1] - bounding_box[1][0] + def equivalent(self, other, offset): + ''' + Is this the outline the same as the other, ignoring the position offset? + ''' + + # Quick check if it even makes sense to compare them + if type(self) != type(other) or len(self.primitives) != len(other.primitives): + return False + + for i in range(0, len(self.primitives)): + if not self.primitives[i].equivalent(other.primitives[i], offset): + return False + + return True class Region(Primitive): """ -- cgit