From 05eb8e0324175b0eb290e81db5764600699df086 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 28 Mar 2011 18:33:27 -0400 Subject: [PATCH] add XDistance and YDistance constraints --- XDistance.py | 20 ++++++++++++++++++++ YDistance.py | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 XDistance.py create mode 100644 YDistance.py diff --git a/XDistance.py b/XDistance.py new file mode 100644 index 0000000..a4afdc2 --- /dev/null +++ b/XDistance.py @@ -0,0 +1,20 @@ + +from Constraint import Constraint + +class Vertical(Constraint): + def __init__(self, shape1, pt1, shape2, pt2, dist): + self.shape1 = shape1 + self.pt1 = pt1 + self.shape2 = shape2 + self.pt2 = pt2 + self.dist + + def toEqu(self): + varrefs1 = self.shape1.toEqu(pt1)[0] + varrefs2 = self.shape2.toEqu(pt2)[0] + coeffs = [] + for i in range(len(varrefs1)): + coeffs.append((-1 * varrefs1[i], (self.shape1, i))) + for i in range(len(varrefs2)): + coeffs.append((1 * varrefs2[i], (self.shape2, i)) + return [(coeffs, self.dist)] diff --git a/YDistance.py b/YDistance.py new file mode 100644 index 0000000..78305e0 --- /dev/null +++ b/YDistance.py @@ -0,0 +1,20 @@ + +from Constraint import Constraint + +class Horizontal(Constraint): + def __init__(self, shape1, pt1, shape2, pt2, dist): + self.shape1 = shape1 + self.pt1 = pt1 + self.shape2 = shape2 + self.pt2 = pt2 + self.dist = dist + + def toEqu(self): + varrefs1 = self.shape1.toEqu(pt1)[1] + varrefs2 = self.shape2.toEqu(pt2)[1] + coeffs = [] + for i in range(len(varrefs1)): + coeffs.append((-1 * varrefs1[i], (self.shape1, i))) + for i in range(len(varrefs2)): + coeffs.append((1 * varrefs2[i], (self.shape2, i)) + return [(coeffs, self.dist)]