Esempio n. 1
0
    def test_point_on_shape(self):
        shape = Polygon([Point(0, 0), Point(0, 1), Point(1, 1), Point(1, 0)])

        self.assertTrue(shape.contains(Point(0.5, 0)))
        self.assertTrue(shape.contains(Point(0, 0.5)))
        self.assertTrue(shape.contains(Point(1, 0.5)))
        self.assertTrue(shape.contains(Point(0.5, 1)))
Esempio n. 2
0
    def test_contain_through_lines(self):
        shape = Polygon([Point(0, 0), Point(0, 1), Point(1, 1), Point(1, 0)])

        self.assertFalse(shape.contains(Point(-1, 0)))
        self.assertFalse(shape.contains(Point(0, -1)))
        self.assertFalse(shape.contains(Point(2, 0)))
        self.assertFalse(shape.contains(Point(0, 2)))
Esempio n. 3
0
    def test_contain_through_point(self):
        # when we cross through a vertex, it still only should count as one
        # boundary crossing for evenodd purposes.
        shape = Polygon([Point(-1, 0), Point(0, 1), Point(1, 0), Point(0, -1)])

        self.assertTrue(shape.contains(Point(0, 0)))
        self.assertTrue(shape.contains(Point(-0.5, 0)))
        self.assertTrue(shape.contains(Point(0, -0.5)))
        self.assertTrue(shape.contains(Point(0, 0.5)))
        self.assertTrue(shape.contains(Point(0.5, 0)))

        self.assertFalse(shape.contains(Point(2, 0)))
        self.assertFalse(shape.contains(Point(0, 2)))
        self.assertFalse(shape.contains(Point(0, -2)))
        self.assertFalse(shape.contains(Point(-2, 0)))
Esempio n. 4
0
    def test_star_contain(self):
        # taken from https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
        # we use the evenodd fill-rule so we don't have to calculate crossing
        # orientation.
        star = Polygon([
            Point(50, 0),
            Point(21, 90),
            Point(98, 35),
            Point(2, 35),
            Point(79, 90)
        ])

        self.assertFalse(star.contains(Point(50, 50)))