示例#1
0
    def testExterior(self):
        n = 100
        k = 1000
        poly = randomConvexPolygon(n, k=50)
        points = [poly.exteriorPoint() for i in range(k)]
        for point in points:
            self.assertTrue(not poly.contains(point))

        if self.ANIMATE:
            plot(poly)
            showPoints(points, style='ro')
示例#2
0
    def runLocator(self, regions):
        # Pre-process regions
        l = Locator(regions)

        if self.ANIMATE:
            show(regions)
            plot(l.boundary, style='g--')
            show(regions)

        # Ensure resulting DAG is acyclic
        self.assertTrue(l.dag.acyclic())

        n = 50
        # Ensure correctness
        for region in regions:
            # Test n random interior points per region
            for k in range(n):
                target = region.smartInteriorPoint()
                target_region = l.locate(target)
                self.assertEqual(region, target_region)
                self.assertTrue(target_region.contains(target))

            # Animate one interior point
            if self.ANIMATE:
                plot(l.regions)
                plot(target_region, style='ro-')
                showPoints(target, style='bo')

            # Test n random exterior points per region
            for k in range(n):
                target = region.exteriorPoint()
                target_region, is_valid = l.annotatedLocate(target)
                self.assertTrue(region != target_region)

                # Point may be outside all regions
                if not is_valid:
                    for region in regions:
                        self.assertTrue(not region.contains(target))

            # Animate one exterior point
            if self.ANIMATE and not is_valid and target_region:
                plot(l.regions)
                plot(target_region, style='ro--')
                showPoints(target, style='bx')