1967 def SetPoints(self, points, merge_segments=True): |
1967 def SetPoints(self, points, merge_segments=True): |
1968 if len(points) > 1: |
1968 if len(points) > 1: |
1969 |
1969 |
1970 # filter duplicates, add corner to diagonals |
1970 # filter duplicates, add corner to diagonals |
1971 self.Points = [] |
1971 self.Points = [] |
1972 lx,ly = None,None |
1972 lx, ly = None, None |
1973 for x, y in points: |
1973 for x, y in points: |
1974 ex, ey = lx == x, ly == y |
1974 ex, ey = lx == x, ly == y |
1975 if ex and ey: |
1975 if ex and ey: |
1976 # duplicate |
1976 # duplicate |
1977 continue |
1977 continue |
1978 if (lx,ly) != (None,None) and not ex and not ey: |
1978 if (lx, ly) != (None, None) and not ex and not ey: |
1979 # diagonal |
1979 # diagonal |
1980 self.Points.append(wx.Point(lx, y)) |
1980 self.Points.append(wx.Point(lx, y)) |
1981 self.Points.append(wx.Point(x, y)) |
1981 self.Points.append(wx.Point(x, y)) |
1982 lx,ly = x,y |
1982 lx, ly = x, y |
1983 |
1983 |
1984 # Calculate the start and end directions |
1984 # Calculate the start and end directions |
1985 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1985 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1986 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1986 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1987 # Calculate the start and end points |
1987 # Calculate the start and end points |
1993 self.Points[-1] = self.EndPoint[0] |
1993 self.Points[-1] = self.EndPoint[0] |
1994 # Calculate the segments directions |
1994 # Calculate the segments directions |
1995 self.Segments = [] |
1995 self.Segments = [] |
1996 i = 0 |
1996 i = 0 |
1997 while True: |
1997 while True: |
1998 l = len(self.Points) |
1998 lp = len(self.Points) |
1999 if i > l - 2: |
1999 if i > lp - 2: |
2000 break |
2000 break |
2001 |
2001 |
2002 segment = vector(self.Points[i], self.Points[i + 1]) |
2002 segment = vector(self.Points[i], self.Points[i + 1]) |
2003 |
2003 |
2004 # merge segment if requested |
2004 # merge segment if requested |
2009 self.Segments.pop() |
2009 self.Segments.pop() |
2010 i -= 1 |
2010 i -= 1 |
2011 continue |
2011 continue |
2012 |
2012 |
2013 # remove corner when two segments are in opposite direction |
2013 # remove corner when two segments are in opposite direction |
2014 if i < l - 2: |
2014 if i < lp - 2: |
2015 next = vector(self.Points[i + 1], self.Points[i + 2]) |
2015 next = vector(self.Points[i + 1], self.Points[i + 2]) |
2016 if is_null_vector(add_vectors(segment, next)): |
2016 if is_null_vector(add_vectors(segment, next)): |
2017 self.Points.pop(i+1) |
2017 self.Points.pop(i+1) |
2018 continue |
2018 continue |
2019 |
2019 |