summaryrefslogtreecommitdiff
path: root/gerber/primitives.py
diff options
context:
space:
mode:
authorGarret Fick <garret@ficksworkshop.com>2016-02-27 15:24:36 +0800
committerGarret Fick <garret@ficksworkshop.com>2016-02-27 15:24:36 +0800
commit29c0d82bf53907030d11df9eb09471b716a0be2e (patch)
treee172ad05e29c9f6a82c862badd0d2242dd567be1 /gerber/primitives.py
parent02dbc6a51e2ef417f2bd41d6159ba53cc736535d (diff)
downloadgerbonara-29c0d82bf53907030d11df9eb09471b716a0be2e.tar.gz
gerbonara-29c0d82bf53907030d11df9eb09471b716a0be2e.tar.bz2
gerbonara-29c0d82bf53907030d11df9eb09471b716a0be2e.zip
RS274X backend for rendering. Incompelte still
Diffstat (limited to 'gerber/primitives.py')
-rw-r--r--gerber/primitives.py46
1 files changed, 44 insertions, 2 deletions
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):
"""