本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)