Changeset 8424:e19bb5aaad3a in orange


Ignore:
Timestamp:
07/23/11 14:32:56 (3 years ago)
Author:
matejd <matejd@…>
Branch:
default
Convert:
2a4399dae98cd526aeb0d8cd37975d1cc4ca2cf5
Message:

owplot3d: polygon selection now closes when intersecting

Location:
orange/OrangeWidgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Prototypes/OWScatterPlot3D.py

    r8421 r8424  
    33 
    44from OWWidget import * 
    5 from owplot3d import * 
     5from plot.owplot3d import * 
    66 
    77import orange 
  • orange/OrangeWidgets/plot/owplot3d.py

    r8422 r8424  
    247247            return True 
    248248        else: 
     249            if self.check_intersections(): 
     250                return True 
    249251            self.vertices.append(self.current_vertex) 
    250252            return False 
     253 
     254    def check_intersections(self): 
     255        if len(self.vertices) < 3: 
     256            return False 
     257 
     258        current_line = QLineF(self.current_vertex[0], self.current_vertex[1], 
     259                              self.vertices[-1][0], self.vertices[-1][1]) 
     260        intersection = QPointF() 
     261        v1 = self.vertices[0] 
     262        for i, v2 in enumerate(self.vertices[1:-1]): 
     263            line = QLineF(v1[0], v1[1], 
     264                          v2[0], v2[1]) 
     265            if current_line.intersect(line, intersection) == QLineF.BoundedIntersection: 
     266                self.current_vertex = [intersection.x(), intersection.y()] 
     267                self.vertices = [self.current_vertex] + self.vertices[i+1:] 
     268                self.vertices.append(self.current_vertex) 
     269                self.polygon = QPolygon([QPoint(x, y) for (x, y) in self.vertices]) 
     270                return True 
     271            v1 = v2 
     272        return False 
    251273 
    252274    def contains(self, x, y): 
Note: See TracChangeset for help on using the changeset viewer.