Show
Ignore:
Timestamp:
02/12/07 00:35:23 (2 years ago)
Author:
fdb
Message:

Small fixes, but bezier.insert_point is still incorrect.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • nodebox/trunk/src/DrawingPrimitives.py

    r80 r82  
    7171    def __repr__(self): 
    7272        return "Point(x=%s, y=%s)" % (self.x, self.y) 
     73         
     74    def __eq__(self, other): 
     75        return self.x == other.x and self.y == other.y 
     76         
     77    def __ne__(self, other): 
     78        return not self.__eq__(other) 
    7379 
    7480class Grob(object): 
     
    268274        import bezier 
    269275        self.path = bezier.insert_point(self, t).path 
     276        self._segment_cache = None 
    270277 
    271278class PathElement(object): 
    272     cmd = None 
    273     x = 0 
    274     y = 0 
    275     ctrl1 = Point() 
    276     ctrl2 = Point() 
    277  
    278279    def __init__(self, cmd=None, pts=None): 
    279280        self.cmd = cmd 
     
    281282            assert len(pts) == 1 
    282283            self.x, self.y = pts[0] 
     284            self.ctrl1 = Point(pts[0]) 
     285            self.ctrl2 = Point(pts[0]) 
    283286        elif cmd == LINETO: 
    284287            assert len(pts) == 1 
    285288            self.x, self.y = pts[0] 
     289            self.ctrl1 = Point(pts[0]) 
     290            self.ctrl2 = Point(pts[0]) 
    286291        elif cmd == CURVETO: 
    287292            assert len(pts) == 3 
     
    291296        elif cmd == CLOSE: 
    292297            assert pts is None or len(pts) == 0 
     298            self.x = self.y = 0.0 
     299            self.ctrl1 = Point(0.0, 0.0) 
     300            self.ctrl2 = Point(0.0, 0.0) 
     301        else: 
     302            self.x = self.y = 0.0 
     303            self.ctrl1 = Point() 
     304            self.ctrl2 = Point() 
     305        #else: 
     306        #    raise NodeBoxError, "PathElement: unknown command %s" % cmd 
    293307 
    294308    def __repr__(self): 
     
    298312            return "PathElement(LINETO, ((%s, %s),))" % (self.x, self.y) 
    299313        elif self.cmd == CURVETO: 
    300             return "PathElement(LINETO, ((%s, %s), (%s, %s), (%s, %s))" % \ 
     314            return "PathElement(CURVETO, ((%s, %s), (%s, %s), (%s, %s))" % \ 
    301315                (self.ctrl1.x, self.ctrl1.y, self.ctrl2.x, self.ctrl2.y, self.x, self.y) 
    302316        elif self.cmd == CLOSE: 
    303317            return "PathElement(CLOSE)" 
     318             
     319    def __eq__(self, other): 
     320        if self.cmd != other.cmd: return False 
     321        return self.x == other.x and self.y == other.y \ 
     322            and self.ctrl1 == other.ctrl1 and self.ctrl2 == other.ctrl2 
     323         
     324    def __ne__(self, other): 
     325        return not self.__eq__(other) 
    304326 
    305327class Rect(BezierPath):