Beispiel #1
0
 def testKochSnowflakePath(self):
     # L'algoritmo di Malkman a volte restituisce un numero di punti diverso
     # dall'agoritmo Monotone chain e comunque in diverso ordine.
     for level in range(5):
         snowflake = snowflake_path(level)
         self.assertEqual(len(snowflake), 3*4**level+1)
         CHpath = convex_hull(snowflake)
         CHpoints = convex_hull(snowflake.points())
         for p in CHpath:
             self.assertTrue(inside_equal(p, CHpoints, True))
         for p in CHpoints:
             self.assertTrue(inside_equal(p, CHpath, True))
Beispiel #2
0
 def testPittedSquareByPath(self):
     square = Path([P(0,0), P(1,0), P(1,1), P(0,1), P(0,0)])
     pitted_square = Path([P(0,0), P(1,0), P(0.5,0.5), P(1,1), P(0,1), P(0,0)])
     CH = convex_hull(pitted_square)
     for p in square:
         self.assertTrue(p in CH)
     self.assertTrue(P(0.5,0.5) not in CH)
Beispiel #3
0
 def testRandomSetOfPoint(self):
     random.seed(123)
     rand = random.random
     npoints = 100
     scale_f = 20.0
     pts = []
     for n in range(npoints):
         pt = P(scale_f*(rand()-0.5), scale_f*(rand()-0.5))
         pts.append(pt)
     CH = convex_hull(pts)
     for p in pts:
         is_inside_with_overlap = inside_equal(p, CH, True)
         is_inside_strict = inside_equal(p, CH, False)
         self.assertTrue(is_inside_with_overlap)
         if is_inside_with_overlap and not is_inside_strict:
             self.assertTrue(p in CH)
Beispiel #4
0
 def testSquareByPath(self):
     pts = Path([P(0,0), P(1,0), P(1,1), P(0,1), P(0,0)])
     CH = convex_hull(pts)
     for p in pts:
         self.assertTrue(p in CH)
Beispiel #5
0
 def testSquareByPoints(self):
     pts = [P(0,0), P(1,0), P(1,1), P(0,1), P(0,0)]
     CH = convex_hull(pts)
     for p in pts:
         self.assertTrue(p in CH)
Beispiel #6
0
 def testEmptySetOfPoints(self):
     CH = convex_hull([])
     self.assertTrue(len(CH) == 0)
Beispiel #7
0
 def testOnePointbyPath(self):
     CH = convex_hull(Path([P(0,0)]))
     self.assertTrue(len(CH) == 1)
     self.assertTrue(CH[0] == P(0,0))
Beispiel #8
0
 def testThreePoint(self):
     pts = [P(0,0), P(1,1), P(1,0)]
     CH = convex_hull(pts)
     for p in pts:
         self.assertTrue(p in CH)
Beispiel #9
0
 def testTwoPointByPath(self):
     pts = Path([P(0,0), P(1,1)])
     CH = convex_hull(pts)
     for p in pts:
         self.assertTrue(p in CH)