當前位置: 首頁>>代碼示例>>Python>>正文


Python Polygon.winding_number方法代碼示例

本文整理匯總了Python中polygon.Polygon.winding_number方法的典型用法代碼示例。如果您正苦於以下問題:Python Polygon.winding_number方法的具體用法?Python Polygon.winding_number怎麽用?Python Polygon.winding_number使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在polygon.Polygon的用法示例。


在下文中一共展示了Polygon.winding_number方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_various_points_in_square

# 需要導入模塊: from polygon import Polygon [as 別名]
# 或者: from polygon.Polygon import winding_number [as 別名]
    def test_various_points_in_square(self):
        square = Polygon(
            vertex_positions=[
                (1.0, -1.0),
                (1.0, 1.0),
                (-1.0, 1.0),
                (-1.0, -1.0),
            ]
        )
        test_points = []
        for x in range(-3, 4):
            for y in range(-3, 4):
                test_points.append((0.5*x, 0.5*y))

        for point in test_points:
            x, y = point
            if -1 < x < 1 and -1 < y < 1:
                # Point is inside.
                self.assertEqual(square.winding_number(point), 1)
            elif x < -1 or x > 1 or y < -1 or y > 1:
                # Point outside.
                self.assertEqual(square.winding_number(point), 0)
            else:
                with self.assertRaises(ValueError):
                    square.winding_number(point)
開發者ID:mdickinson,項目名稱:polyhedron,代碼行數:27,代碼來源:test_polygon.py

示例2: test_aitch

# 需要導入模塊: from polygon import Polygon [as 別名]
# 或者: from polygon.Polygon import winding_number [as 別名]
    def test_aitch(self):
        aitch = Polygon(
            vertex_positions=[
                (0, 0),
                (1, 0),
                (1, 1),
                (2, 1),
                (2, 0),
                (3, 0),
                (3, 3),
                (2, 3),
                (2, 2),
                (1, 2),
                (1, 3),
                (0, 3),
            ]
        )

        test_points = [
            (0.5*x, 0.5*y)
            for y in range(-1, 8)
            for x in range(-1, 8)
        ]

        # * for boundary, '.' for outside, 'o' for inside.
        template = """\
.........
.***.***.
.*o*.*o*.
.*o***o*.
.*ooooo*.
.*o***o*.
.*o*.*o*.
.***.***.
.........
"""
        expected = ''.join(template.strip().split())

        assert len(expected) == len(test_points)
        for point, point_type in zip(test_points, expected):
            if point_type == '.':
                self.assertEqual(aitch.winding_number(point), 0)
            elif point_type == 'o':
                self.assertEqual(aitch.winding_number(point), 1)
            else:
                with self.assertRaises(ValueError):
                    aitch.winding_number(point)
開發者ID:mdickinson,項目名稱:polyhedron,代碼行數:49,代碼來源:test_polygon.py

示例3: test_clockwise_square

# 需要導入模塊: from polygon import Polygon [as 別名]
# 或者: from polygon.Polygon import winding_number [as 別名]
 def test_clockwise_square(self):
     square = Polygon(
         vertex_positions=[
             (1.0, -1.0),
             (1.0, 1.0),
             (-1.0, 1.0),
             (-1.0, -1.0),
         ][::-1]
     )
     origin = (0.0, 0.0)
     self.assertEqual(square.winding_number(origin), -1)
     self.assertEqual(square.area(), -4.0)
開發者ID:mdickinson,項目名稱:polyhedron,代碼行數:14,代碼來源:test_polygon.py

示例4: test_double_square

# 需要導入模塊: from polygon import Polygon [as 別名]
# 或者: from polygon.Polygon import winding_number [as 別名]
 def test_double_square(self):
     square = Polygon(
         vertex_positions=[
             (1.0, -1.0),
             (1.0, 1.0),
             (-1.0, 1.0),
             (-1.0, -1.0),
         ] * 2
     )
     origin = (0.0, 0.0)
     self.assertEqual(square.winding_number(origin), 2)
     self.assertEqual(square.area(), 8.0)
開發者ID:mdickinson,項目名稱:polyhedron,代碼行數:14,代碼來源:test_polygon.py

示例5: test_simple_square

# 需要導入模塊: from polygon import Polygon [as 別名]
# 或者: from polygon.Polygon import winding_number [as 別名]
 def test_simple_square(self):
     square = Polygon(
         vertex_positions=[
             (1.0, -1.0),
             (1.0, 1.0),
             (-1.0, 1.0),
             (-1.0, -1.0),
         ]
     )
     origin = (0.0, 0.0)
     self.assertEqual(square.winding_number(origin), 1)
     self.assertEqual(square.area(), 4.0)
開發者ID:mdickinson,項目名稱:polyhedron,代碼行數:14,代碼來源:test_polygon.py

示例6: test_numpy_compatibility

# 需要導入模塊: from polygon import Polygon [as 別名]
# 或者: from polygon.Polygon import winding_number [as 別名]
 def test_numpy_compatibility(self):
     square = Polygon(
         vertex_positions=numpy.array(
             [
                 [1.0, -1.0],
                 [1.0, 1.0],
                 [-1.0, 1.0],
                 [-1.0, -1.0],
             ],
             dtype=numpy.float64,
         )
     )
     origin = numpy.array([0.0, 0.0], dtype=numpy.float64)
     self.assertEqual(square.winding_number(origin), 1)
     self.assertEqual(square.area(), 4.0)
開發者ID:mdickinson,項目名稱:polyhedron,代碼行數:17,代碼來源:test_polygon.py


注:本文中的polygon.Polygon.winding_number方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。