def test_threeByThree(self):
     points = [(x,y) for x in range(2,9,3) for y in range(2,9,3)]
     v = Voronoi(width=10, height=10)
     self.perturb(points)
     v.process(points)
     for e in v.edges:
         print (e) 
 def test_threeVertical(self):
     points = [(10,x) for x in range(2,9,3) ]
     
     v = Voronoi(width=20, height=20)
     v.process(points)
     for e in v.points:
         print (e, e.polygon)
Exemple #3
0
    def test_threeVertical(self):
        points = [(10, x) for x in range(2, 9, 3)]

        v = Voronoi(width=20, height=20)
        v.process(points)
        for e in v.points:
            print(e, e.polygon)
Exemple #4
0
 def test_threeByThree(self):
     points = [(x, y) for x in range(2, 9, 3) for y in range(2, 9, 3)]
     v = Voronoi(width=10, height=10)
     self.perturb(points)
     v.process(points)
     for e in v.edges:
         print(e)
Exemple #5
0
 def test_another(self):
     p1 = (11, 26)
     p2 = (28, 15)
     p3 = (22, 41)
     v = Voronoi(width=50, height=50)
     v.process([p1, p2, p3])
     for e in v.edges:
         print(e)
Exemple #6
0
 def test_slightlyOff(self):
     p1 = (6, 6)
     p2 = (6, 8)
     p3 = (6.1, 4)
     v = Voronoi(width=10, height=10)
     v.process([p1, p2, p3])
     for e in v.edges:
         print(e)
 def test_slightlyOff(self):
     p1 = (6, 6)
     p2 = (6, 8)
     p3 = (6.1, 4)
     v = Voronoi(width=10, height=10)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)    
Exemple #8
0
 def test_fortune(self):
     p1 = (2, 6)
     p2 = (7, 5)
     p3 = (4, 2)
     v = Voronoi(width=10, height=10)
     v.process([p1, p2, p3])
     for e in v.edges:
         print(e)
 def test_another(self):
     p1 = (11, 26)
     p2 = (28, 15)
     p3 = (22, 41) 
     v = Voronoi(width=50, height=50)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)
 def test_fortune(self):
     p1 = (2,6)
     p2 = (7,5)
     p3 = (4,2)
     v = Voronoi(width=10, height=10)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)
Exemple #11
0
    def test_multipleFirstSweepLine(self):
        p1 = (150, 200)
        p2 = (250, 200)
        p3 = (200, 150)

        v = Voronoi(width=300, height=300)
        v.process([p1, p2, p3])
        for e in v.edges:
            print(e)
 def test_missing(self):
     
     p1 = (110.0, 229.0)
     p2 = (187.0, 231.0)
     p3 = (150.0, 107.0)
     v = Voronoi(width=400, height=400)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)   
Exemple #13
0
    def test_missing(self):

        p1 = (110.0, 229.0)
        p2 = (187.0, 231.0)
        p3 = (150.0, 107.0)
        v = Voronoi(width=400, height=400)
        v.process([p1, p2, p3])
        for e in v.edges:
            print(e)
 def test_badCase(self):
     p1 = (14, 20)
     p2 = (19, 15)
     p3 = (5, 12)   
        
     v = Voronoi(width=40, height=40)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)
 def test_multipleFirstSweepLine(self):
     p1 = (150,200)
     p2 = (250,200)
     p3 = (200,150)
     
     v = Voronoi(width=300, height=300)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)
Exemple #16
0
    def test_badCase(self):
        p1 = (14, 20)
        p2 = (19, 15)
        p3 = (5, 12)

        v = Voronoi(width=40, height=40)
        v.process([p1, p2, p3])
        for e in v.edges:
            print(e)
Exemple #17
0
    def test_crossover(self):
        p1 = (138, 243)
        p2 = (180, 184)
        p3 = (113, 115)
        p4 = (245, 112)

        v = Voronoi(width=400, height=400)
        v.process([p1, p2, p3, p4])
        for e in v.edges:
            print(e)
 def test_crossover(self):
     p1 = (138, 243)
     p2 = (180, 184)
     p3 = (113, 115)
     p4 = (245, 112)
     
     v = Voronoi(width=400, height=400)
     v.process([p1,p2,p3,p4])
     for e in v.edges:
         print (e)       
 def test_twoInitialVerticalBisection(self):
     p1 = (3,3)
     p2 = (8,3)
     e1 = [Point((5.5,10)),Point((5.5,0))]
     
     edges = [e1]
     
     v = Voronoi(10, 10)
     v.process([p1,p2])
     for e in v.edges:
         self.valid([e.start, e.end], edges)
 def test_whenPointAtCircumcircle(self):
     p1 = (2,5)
     p2 = (6,5)
     p3 = (4,3)
     
     # This is challenging and not yet solved.
     
     v = Voronoi(10,10)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)
Exemple #21
0
    def test_whenPointAtCircumcircle(self):
        p1 = (2, 5)
        p2 = (6, 5)
        p3 = (4, 3)

        # This is challenging and not yet solved.

        v = Voronoi(10, 10)
        v.process([p1, p2, p3])
        for e in v.edges:
            print(e)
Exemple #22
0
    def test_twoInitialVerticalBisection(self):
        p1 = (3, 3)
        p2 = (8, 3)
        e1 = [Point((5.5, 10)), Point((5.5, 0))]

        edges = [e1]

        v = Voronoi(10, 10)
        v.process([p1, p2])
        for e in v.edges:
            self.valid([e.start, e.end], edges)
 def test_twoInitial(self):
     p1 = (8,4)
     p2 = (10,0)
     
     e1 = [Point((0,-2.5)),Point((20,7.5))]
     edges = [e1]
     
     v = Voronoi(20,20)
     v.process([p1,p2])
     for e in v.edges:
         self.valid([e.start, e.end], edges)
Exemple #24
0
    def test_twoInitial(self):
        p1 = (8, 4)
        p2 = (10, 0)

        e1 = [Point((0, -2.5)), Point((20, 7.5))]
        edges = [e1]

        v = Voronoi(20, 20)
        v.process([p1, p2])
        for e in v.edges:
            self.valid([e.start, e.end], edges)
 def test_threeHorizontal(self):
     points = [(x,5) for x in range(2,9,3) ]
     
     e1 = [Point((3.5,10)),Point((3.5,0))]
     e2 = [Point((6.5,10)),Point((6.5,0))]
     
     edges = [e1,e2]
     
     v = Voronoi(width=10, height=10)
     v.process(points)
     for e in v.edges:
         self.valid([e.start, e.end], edges)   
Exemple #26
0
    def test_threeHorizontal(self):
        points = [(x, 5) for x in range(2, 9, 3)]

        e1 = [Point((3.5, 10)), Point((3.5, 0))]
        e2 = [Point((6.5, 10)), Point((6.5, 0))]

        edges = [e1, e2]

        v = Voronoi(width=10, height=10)
        v.process(points)
        for e in v.edges:
            self.valid([e.start, e.end], edges)
Exemple #27
0
    def test_threeIsoceles(self):
        points = [(5, 2), (11, 2), (8, 4)]

        e1 = [Point((8.0, 0.75)), Point((0, 12.75))]
        e2 = [Point((15, 11.25)), Point((8.0, 0.75))]
        e3 = [Point((8.0, 0.75)), Point((8.0, 0.0))]

        edges = [e1, e2, e3]

        v = Voronoi(width=15, height=15)
        v.process(points)
        for e in v.edges:
            self.valid([e.start, e.end], edges)
 def test_threeIsoceles(self):
     points = [(5,2), (11,2), (8,4) ]
     
     e1 = [Point((8.0,0.75)),Point((0,12.75))]
     e2 = [Point((15,11.25)),Point((8.0,0.75))]
     e3 = [Point((8.0,0.75)),Point((8.0,0.0))]
     
     edges = [e1,e2,e3]
     
     v = Voronoi(width=15, height=15)
     v.process(points)
     for e in v.edges:
         self.valid([e.start, e.end], edges)    
Exemple #29
0
    def test_threeIsocelesTilted(self):
        points = [(5, 2), (5, 8), (9, 5)]

        e1 = [Point((9.625, 10)), Point((5.875, 5.0))]
        e2 = [Point((5.875, 5.0)), Point((0, 5.0))]
        e3 = [Point((5.875, 5.0)), Point((9.625, 0))]

        edges = [e1, e2, e3]

        v = Voronoi(width=10, height=10)
        v.process(points)
        for e in v.edges:
            self.valid([e.start, e.end], edges)
 def test_threeIsocelesTilted(self):
     points = [(5,2), (5,8), (9,5) ]
     
     e1 = [Point((9.625,10)),Point((5.875,5.0))]
     e2 = [Point((5.875,5.0)),Point((0,5.0))]
     e3 = [Point((5.875,5.0)),Point((9.625,0))]
     
     edges = [e1,e2,e3]
     
     v = Voronoi(width=10, height=10)
     v.process(points)
     for e in v.edges:
         self.valid([e.start, e.end], edges)   
Exemple #31
0
    def test_edgeExplanation(self):
        #p1 = (83, 181)
        #p2 = (108, 181)
        #p3 = (380, 308)
        p1 = (4, 6)
        p2 = (2, 4)
        p3 = (6, 4)
        p4 = (3, 1)
        p5 = (5, 1)

        v = Voronoi(width=8, height=8)
        v.process([p1, p2, p3, p4, p5])
        for e in v.edges:
            print(e)
 def test_edgeExplanation(self):
     #p1 = (83, 181)
     #p2 = (108, 181)
     #p3 = (380, 308)
     p1 = (4,6)
     p2 = (2,4)
     p3 = (6,4) 
     p4 = (3,1)    
     p5 = (5,1)
        
     v = Voronoi(width=8, height=8)
     v.process([p1,p2,p3,p4,p5])
     for e in v.edges:
         print (e)
Exemple #33
0
    def test_threeSameY(self):
        p1 = (50, 200)
        p2 = (100, 200)
        p3 = (150, 200)

        e1 = [Point((75, 300)), Point((75, 0))]
        e2 = [Point((125, 300)), Point((125, 0))]

        edges = [e1, e2]
        v = Voronoi(300, 300)
        v.process([p1, p2, p3])

        for e in v.edges:
            self.valid([e.start, e.end], edges)
 def test_threeSameY(self):
     p1 = (50,200)
     p2 = (100,200)
     p3 = (150,200)
     
     e1 = [Point((75,300)),Point((75,0))]
     e2 = [Point((125,300)),Point((125,0))]
     
     edges = [e1,e2]
     v = Voronoi(300,300)
     v.process([p1,p2,p3])
      
     for e in v.edges:
         self.valid([e.start, e.end], edges)
Exemple #35
0
    def test_threeL(self):
        p1 = (2, 5)
        p2 = (2, 2)
        p3 = (5, 2)

        e1 = [Point((0, 3.5)), Point((3.5, 3.5))]
        e2 = [Point((3.5, 3.5)), Point((3.5, 0))]
        e3 = [Point((3.5, 3.5)), Point((10, 10.0))]

        edges = [e1, e2, e3]

        v = Voronoi(10, 10)
        v.process([p1, p2, p3])
        self.assertEquals(3, len(v.edges))
        for e in v.edges:
            self.valid([e.start, e.end], edges)
 def test_collinearOtherParallel(self):
     p1 = (2,7)
     p2 = (4,5)
     p3 = (6,3)
     p4 = (8,1)
     
     e1 = [Point((0,3)),Point((17,20))]
     e2 = [Point((0,-1)),Point((20,19))]
     e3 = [Point((0,-5)),Point((20,15))]
     
     edges = [e1,e2,e3]
     v = Voronoi(width=20, height=20)
     v.process([p1,p2,p3,p4])
     
     for e in v.edges:
         self.valid([e.start, e.end], edges)
Exemple #37
0
    def test_collinearOtherParallel(self):
        p1 = (2, 7)
        p2 = (4, 5)
        p3 = (6, 3)
        p4 = (8, 1)

        e1 = [Point((0, 3)), Point((17, 20))]
        e2 = [Point((0, -1)), Point((20, 19))]
        e3 = [Point((0, -5)), Point((20, 15))]

        edges = [e1, e2, e3]
        v = Voronoi(width=20, height=20)
        v.process([p1, p2, p3, p4])

        for e in v.edges:
            self.valid([e.start, e.end], edges)
 def test_threeL(self):
     p1 = (2,5)
     p2 = (2,2)
     p3 = (5,2) 
     
     e1 = [Point((0,3.5)), Point((3.5,3.5))]
     e2 = [Point((3.5,3.5)), Point((3.5,0))]
     e3 = [Point((3.5,3.5)), Point((10,10.0))]
     
     edges = [e1,e2,e3]
     
     v = Voronoi(10,10)
     v.process([p1,p2,p3])
     self.assertEquals (3, len(v.edges))
     for e in v.edges:
         self.valid([e.start, e.end], edges)
 def test_threeOneParallelOneIntersect(self):
     p1 = (3,3)
     p2 = (5,3)
     p3 = (8,2)
     
     # outside bounding box area
     e1 = [Point((4,10)),Point((4,-5.0))]
     e2 = [Point((4,-5.0)),Point((9,10))]
     e3 = [Point((4,-5.0)),Point((0,-25))]     ## This one is completely outside and can't be fixed.
     
     edges = [e1,e2,e3]
     
     v = Voronoi(10, 10)
     v.process([p1,p2,p3])
     for e in v.edges:
         self.valid([e.start, e.end], edges)
 def test_firstCircleEvent(self):
     p1 = (6,3)
     p2 = (8,4)
     p3 = (5,1)
     
     e1 = [Point((0,4.75)),Point((8.5,0.5))]
     e2 = [Point((0,17.5)),Point((8.5,0.5))]
     e3 = [Point((8.5,0.5)),Point((9,0))]
     e4 = [Point((6,5.5)), Point((8.5,0.5))]
     e5 = [Point((5, 2.25)), Point((8.5, 0.5))]
     
     edges = [e1,e2,e3,e4,e5]
     v = Voronoi(width=10, height=10)
     v.process([p1,p2,p3])
     
     for e in v.edges:
         self.valid([e.start, e.end], edges)
Exemple #41
0
    def test_threeOneParallelOneIntersect(self):
        p1 = (3, 3)
        p2 = (5, 3)
        p3 = (8, 2)

        # outside bounding box area
        e1 = [Point((4, 10)), Point((4, -5.0))]
        e2 = [Point((4, -5.0)), Point((9, 10))]
        e3 = [Point((4, -5.0)), Point(
            (0, -25))]  ## This one is completely outside and can't be fixed.

        edges = [e1, e2, e3]

        v = Voronoi(10, 10)
        v.process([p1, p2, p3])
        for e in v.edges:
            self.valid([e.start, e.end], edges)
Exemple #42
0
    def test_firstCircleEvent(self):
        p1 = (6, 3)
        p2 = (8, 4)
        p3 = (5, 1)

        e1 = [Point((0, 4.75)), Point((8.5, 0.5))]
        e2 = [Point((0, 17.5)), Point((8.5, 0.5))]
        e3 = [Point((8.5, 0.5)), Point((9, 0))]
        e4 = [Point((6, 5.5)), Point((8.5, 0.5))]
        e5 = [Point((5, 2.25)), Point((8.5, 0.5))]

        edges = [e1, e2, e3, e4, e5]
        v = Voronoi(width=10, height=10)
        v.process([p1, p2, p3])

        for e in v.edges:
            self.valid([e.start, e.end], edges)
Exemple #43
0
    def process(self, collection):
        """Now that Voronoi diagram is computed, act on it."""
        self.voronoi = Voronoi(400, 400)
        self.voronoi.process(collection)
        self.canvas.delete(tkinter.ALL)

        for fp in collection:
            self.canvas.create_rectangle(fp[X] - RectangleSize,
                                         self.toTk(fp[Y]) - RectangleSize,
                                         fp[X] + RectangleSize,
                                         self.toTk(fp[Y]) + RectangleSize,
                                         fill='Red')

        for edge in self.voronoi.edges:
            start = edge.start
            end = edge.end
            self.canvas.create_line(start.x, self.toTk(start.y), end.x,
                                    self.toTk(end.y))
Exemple #44
0
    def test_threeBasic(self):
        p1 = (6, 7)
        p2 = (2, 3)
        p3 = (8, 1)

        e1 = [Point((0, 9.0)), Point((5.5, 3.5))]
        e2 = [Point((5.5, 3.5)), Point((0, -13.0))]
        e3 = [Point((5.5, 3.5)), Point((10, 5.0))]

        edges = [e1, e2, e3]

        v = Voronoi(10, 10)
        v.process([p1, p2, p3])

        for e in v.edges:
            self.valid([e.start, e.end], edges)
        for p in v.points:
            print(p.polygon)
 def test_perfectCircle(self):
     #p1 = (83, 181)
     #p2 = (108, 181)
     #p3 = (380, 308)
     p1 = (4,6)
     p2 = (2,4)
     p3 = (6,4) 
        
     e1 = [Point((0,8)),Point((4,4))]
     e2 = [Point((4,4)),Point((4,0))]
     e3 = [Point((4,4)),Point((8,8))]
     
     edges = [e1,e2,e3]
     v = Voronoi(8,8)
     v.process([p1,p2,p3])
     
     for e in v.edges:
         self.valid([e.start, e.end], edges)
 def test_threeBasic(self):
     p1 = (6,7)
     p2 = (2,3)
     p3 = (8,1) 
     
     e1 = [Point((0,9.0)), Point((5.5,3.5))]
     e2 = [Point((5.5,3.5)), Point((0,-13.0))]
     e3 = [Point((5.5,3.5)), Point((10,5.0))]
     
     edges = [e1,e2,e3]
     
     v = Voronoi(10,10)
     v.process([p1,p2,p3])
     
     for e in v.edges:
         self.valid([e.start, e.end], edges)
     for p in v.points:
         print (p.polygon)
Exemple #47
0
    def test_perfectCircle(self):
        #p1 = (83, 181)
        #p2 = (108, 181)
        #p3 = (380, 308)
        p1 = (4, 6)
        p2 = (2, 4)
        p3 = (6, 4)

        e1 = [Point((0, 8)), Point((4, 4))]
        e2 = [Point((4, 4)), Point((4, 0))]
        e3 = [Point((4, 4)), Point((8, 8))]

        edges = [e1, e2, e3]
        v = Voronoi(8, 8)
        v.process([p1, p2, p3])

        for e in v.edges:
            self.valid([e.start, e.end], edges)
Exemple #48
0
    def test_good_bad(self):
        p1 = (205, 238)
        p2 = (156, 157)
        p3 = (255, 133)

        v = Voronoi(width=400, height=400)
        v.process([p1, p2, p3])
        for e in v.edges:
            print(e)

        print("----")
        p1 = (205, 238)
        p2 = (156, 157)
        p3 = (254, 133)  ## small change causes one more circle event

        v = Voronoi(width=400, height=400)
        v.process([p1, p2, p3])
        for e in v.edges:
            print(e)
 def test_good_bad(self):
     p1 = (205,238)
     p2 = (156,157 )
     p3 = (255,133)
        
     v = Voronoi(width=400, height=400)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)  
         
     print ("----")
     p1 = (205,238)
     p2 = (156,157 )
     p3 = (254,133)    ## small change causes one more circle event
        
     v = Voronoi(width=400, height=400)
     v.process([p1,p2,p3])
     for e in v.edges:
         print (e)               
 def test_singlePoint(self):
     p1 = (8,4)
     
     v = Voronoi(20,20)
     v.process([p1])
     self.assertEquals(0, len(v.edges))
Exemple #51
0
class VoronoiApp:
    def __init__(self):
        """App for creating KD tree dynamically and executing nearest neighbor queries."""

        # Points that we have added.
        self.points = []
        self.voronoi = None

        # set to true when you want to view a set of points that
        # were set not by user control.
        self.static = False

        self.master = tkinter.Tk()
        self.master.title('Voronoi Diagram Application')
        self.w = tkinter.Frame(self.master, width=410, height=410)
        self.canvas = tkinter.Canvas(self.w, width=400, height=400)

        self.paint()

        self.canvas.bind("<Button-1>", self.click)
        self.canvas.bind("<Motion>", self.moved)
        self.w.pack()

    def toCartesian(self, y):
        """Convert tkinter point into Cartesian."""
        return self.w.winfo_height() - y

    def toTk(self, y):
        """Convert Cartesian into tkinter point."""
        if y == maxValue: return 0
        tk_y = self.w.winfo_height()
        if y != minValue:
            tk_y -= y
        return tk_y

    def moved(self, event):
        """React to mouse move events."""
        if self.static:
            self.process(self.points)
            return

        # during movement, add points to track mouse
        p = (event.x, self.toCartesian(event.y))

        # Avoid duplicates for cleaner implementation
        if p not in self.points:
            fullPoints = self.points + [p]
            self.process(fullPoints)

    def click(self, event):
        """Add point to Voronoi collection."""
        if self.static:
            self.process(self.points)
            return

        p = (event.x, self.toCartesian(event.y))

        # Avoid duplicates for cleaner implementation
        if p not in self.points:
            self.points.append(p)
            self.process(self.points)

    def process(self, collection):
        """Now that Voronoi diagram is computed, act on it."""
        self.voronoi = Voronoi(400, 400)
        self.voronoi.process(collection)
        self.canvas.delete(tkinter.ALL)

        for fp in collection:
            self.canvas.create_rectangle(fp[X] - RectangleSize,
                                         self.toTk(fp[Y]) - RectangleSize,
                                         fp[X] + RectangleSize,
                                         self.toTk(fp[Y]) + RectangleSize,
                                         fill='Red')

        for edge in self.voronoi.edges:
            start = edge.start
            end = edge.end
            self.canvas.create_line(start.x, self.toTk(start.y), end.x,
                                    self.toTk(end.y))

    def prepare(self, event):
        """prepare to add points."""
        if self.label:
            self.label.destroy()
            self.label = None
            self.canvas.pack()

    def paint(self):
        """Paint KDTree by visiting all nodes, or show introductory message."""
        if self.voronoi:
            self.canvas.delete(tkinter.ALL)
        else:
            self.label = tkinter.Label(self.w,
                                       width=100,
                                       height=40,
                                       text="Click To Add Points")
            self.label.bind("<Button-1>", self.prepare)
            self.label.pack()
Exemple #52
0
    def test_singlePoint(self):
        p1 = (8, 4)

        v = Voronoi(20, 20)
        v.process([p1])
        self.assertEquals(0, len(v.edges))