diff --git a/Sketch.py b/Sketch.py index ce5b57a..baad888 100644 --- a/Sketch.py +++ b/Sketch.py @@ -1,4 +1,7 @@ +from numpy import * +from openopt import SLE + class Sketch(object): def __init__(self): self.shapes = [] @@ -9,3 +12,28 @@ class Sketch(object): def __contains__(self, item): return self.shapes.__contains__(item) + + def solve(self): + shape_vars = {} + varid = 0 + equations = [] + for c in self.constraints: + equations += c.toEqu() + for e in equations: + coeffs = e[0] + for c in coeffs: + shape_var = c[1] + if not shape_var in shape_vars: + shape_vars[shape_var] = varid + varid += 1 + C = empty((len(equations), len(shape_vars))) + d = empty(len(equations)) + for i in range(len(equations)): + e = equations[i] + coeffs = e[0] + for c in coeffs: + var_index = shape_vars[coeffs[1]] + C[i][var_index] = coeffs[0] + d[i] = e[1] + s = SLE(C, d) + r = s.solve()