Beispiel #1
0
class LineWrapper(object):
    """
    A wrapper around sympy's line class that uses the same interface as SimpleLine
    for easy switching
    """
    def __init__(self, **kwargs):
        if 'p1' in kwargs and 'p2' in kwargs:
            self._init_point_point(**kwargs)
        elif 'a' in kwargs and 'b' in kwargs and 'c' in kwargs:
            self._init_general(**kwargs)
        else:
            raise Exception('Line format not supported')

    def _init_general(self, **kwargs):
        self.a = kwargs['a']
        self.b = kwargs['b']
        self.c = kwargs['c']

    def _init_point_point(self, **kwargs):
        self.p1 = kwargs['p1']
        self.p2 = kwargs['p2']
        self.line = Line(Point(kwargs['p1'][0], kwargs['p1'][1]),
                         Point(kwargs['p2'][0], kwargs['p2'][1]))

    def intersect(self, other):
        pt = self.line.intersect(other.line)
        return map(float, list(set(pt))[0])