示例#1
0
 def setup_dxy():
     xy1 = geom.XY(4, 5)
     xy2 = geom.XY(7, 9)
     dxy1 = geom.DXY(3, 4)
     dxy2a = geom.DXY(55, 66)
     dxy2b = geom.DXY(55, 66)
     return xy1, xy2, dxy1, dxy2a, dxy2b
示例#2
0
 def test_contains_points_unitgrid(self):
     rect_pt_a = geom.XY(10, -2)
     rect_pt_b = geom.XY(-2, 1)
     rect_pt_c = geom.XY(0.5, 11)
     rect = geom.Rectangle_in_2D(rect_pt_a, rect_pt_b, rect_pt_c)
     with pytest.raises(TypeError):
         _ = rect.contains_points_unitgrid(-3, 15.5, -3, 12)
     with pytest.raises(ValueError):
         _ = rect.contains_points_unitgrid(11, 8, -3, 12)
         _ = rect.contains_points_unitgrid(-3, 15, 12, 3)
     result_grid = rect.contains_points_unitgrid(-3,
                                                 15,
                                                 -3,
                                                 12,
                                                 include_edges=True)
     assert result_grid.shape == (16, 19)
     assert result_grid.dtype == np.bool
     assert result_grid.sum() == 132
     assert result_grid[0, :].sum() == 0
     assert result_grid[14:, :].sum() == 0
     assert result_grid[:, 0].sum() == 0
     assert result_grid[:, 16:].sum() == 0
     assert result_grid[4, :].sum() == 13
     assert result_grid[:, 3].sum() == 9
     result_grid2 = rect.contains_points_unitgrid(-3,
                                                  15,
                                                  -3,
                                                  12,
                                                  include_edges=False)
     assert result_grid2.shape == (16, 19)
     assert result_grid2.dtype == np.bool
     assert result_grid2.sum() == 124
示例#3
0
 def test_contains_points(self, setup_circle_in_2d):
     circle = setup_circle_in_2d
     points = (geom.XY(0, 6), geom.XY(-1, 6), geom.XY(8.9, 6),
               geom.XY(9.1, 6), geom.XY(100, 100))
     assert circle.contains_points(
         points, include_edges=True) == [True, True, True, False, False]
     assert circle.contains_points(
         points, include_edges=False) == [True, False, True, False, False]
示例#4
0
 def test_constructor(self, setup_rectangle_in_2d):
     rect = setup_rectangle_in_2d
     assert (rect.a, rect.b, rect.c) == (geom.XY(5, 0), geom.XY(0, 2),
                                         geom.XY(1, 4.5))
     assert rect.ab == geom.DXY(-5, 2)
     assert rect.bc == geom.DXY(1, 2.5)
     bad_pt_c = geom.XY(1, 4.49)
     with pytest.raises(ValueError):
         _ = geom.Rectangle_in_2D(rect.a, rect.b, bad_pt_c)
示例#5
0
 def test_contains_points_unitgrid(self):
     circle_origin = geom.XY(6, 5)
     circle_radius = 7
     circle = geom.Circle_in_2D(circle_origin, circle_radius)
     with pytest.raises(TypeError):
         _ = circle.contains_points_unitgrid(-3, 15.5, -3, 12)
     with pytest.raises(ValueError):
         _ = circle.contains_points_unitgrid(11, 8, -3, 12)
         _ = circle.contains_points_unitgrid(-3, 15, 12, 3)
     result_grid = circle.contains_points_unitgrid(-3,
                                                   15,
                                                   -3,
                                                   12,
                                                   include_edges=True)
     assert result_grid.shape == (16, 19)
     assert result_grid.dtype == np.bool
     assert result_grid.sum() == 149
     assert result_grid[0, :].sum() == 0
     assert result_grid[15, :].sum() == 1
     assert result_grid[:, :2].sum() == 0
     assert result_grid[:, 17:].sum() == 0
     assert result_grid[4, :].sum() == 11
     assert result_grid[:, 9].sum() == 15
     result_grid2 = circle.contains_points_unitgrid(-3,
                                                    15,
                                                    -3,
                                                    12,
                                                    include_edges=False)
     assert result_grid2.shape == (16, 19)
     assert result_grid2.dtype == np.bool
     assert result_grid2.sum() == 145
示例#6
0
 def test_constructor(self, setup_circle_in_2d):
     circle = setup_circle_in_2d
     assert circle.origin == geom.XY(4, 6)
     assert circle.radius == 5.0
     assert circle.x == 4.0
     assert circle.y == 6.0
     with pytest.raises(TypeError):
         _ = geom.Circle_in_2D(55, 5)
         _ = geom.Circle_in_2D((6, 7), 5)
示例#7
0
 def test_contains_point(self, setup_circle_in_2d):
     circle = setup_circle_in_2d
     assert circle.contains_point(geom.XY(0, 6), include_edges=True) is True
     assert circle.contains_point(geom.XY(-1, 6),
                                  include_edges=True) is True
     assert circle.contains_point(geom.XY(8.9, 6),
                                  include_edges=True) is True
     assert circle.contains_point(geom.XY(9.1, 6),
                                  include_edges=True) is False
     assert circle.contains_point(geom.XY(100, 100),
                                  include_edges=True) is False
     assert circle.contains_point(geom.XY(0, 6),
                                  include_edges=False) is True
     assert circle.contains_point(geom.XY(-1, 6),
                                  include_edges=False) is False
     assert circle.contains_point(geom.XY(8.9, 6),
                                  include_edges=False) is True
     assert circle.contains_point(geom.XY(9.1, 6),
                                  include_edges=False) is False
     assert circle.contains_point(geom.XY(100, 100),
                                  include_edges=False) is False
示例#8
0
 def setup_circle_in_2d():
     return geom.Circle_in_2D(xy_origin=geom.XY(4, 6), radius=5)
示例#9
0
 def test_contains_points(self, setup_rectangle_in_2d):
     rect = setup_rectangle_in_2d
     # Just inside and outside of rectangle:
     xy_array = (geom.XY(5.49, 1.25), geom.XY(5.51,
                                              1.25), geom.XY(3.5, 3.49),
                 geom.XY(3.5, 3.51), geom.XY(1, 4.49), geom.XY(1, 4.51),
                 geom.XY(3, 2.25), geom.XY(100, 100))
     contains = rect.contains_points(xy_array, include_edges=True)
     assert contains == 4 * [True, False]
     # Edges and vertices:
     xy_array = (geom.XY(0, 2), geom.XY(1, 4.5), geom.XY(5.5, 1.25))
     contains = rect.contains_points(xy_array, include_edges=True)
     assert contains == 3 * [True]
     contains = rect.contains_points(xy_array, include_edges=False)
     assert contains == 3 * [False]
示例#10
0
 def test_contains_point(self, setup_rectangle_in_2d):
     rect = setup_rectangle_in_2d
     assert rect.contains_point(geom.XY(5.49, 1.25)) is True
     assert rect.contains_point(geom.XY(5.51, 1.25)) is False
     assert rect.contains_point(geom.XY(3.5, 3.49)) is True
     assert rect.contains_point(geom.XY(3.5, 3.51)) is False
     assert rect.contains_point(geom.XY(1, 4.49)) is True
     assert rect.contains_point(geom.XY(1, 4.51)) is False
     assert rect.contains_point(geom.XY(3, 2.25)) is True
     assert rect.contains_point(geom.XY(100, 100)) is False
     pts_on_edge = [
         rect.a, rect.b, rect.c,
         geom.XY(2.5, 1),
         geom.XY(0.5, 3.25),
         geom.XY(3.5, 3.5),
         geom.XY(5.5, 1.25)
     ]
     assert all([
         rect.contains_point(pt, include_edges=True) for pt in pts_on_edge
     ])
     assert not any([
         rect.contains_point(pt, include_edges=False) for pt in pts_on_edge
     ])
示例#11
0
 def setup_rectangle_in_2d():
     rect_pt_a = geom.XY(5, 0)
     rect_pt_b = geom.XY(0, 2)
     rect_pt_c = geom.XY(1, 4.5)
     return geom.Rectangle_in_2D(rect_pt_a, rect_pt_b, rect_pt_c)
示例#12
0
 def setup_xy():
     xy1a = geom.XY(4, 5)
     xy1b = geom.XY(4, 5)
     xy2 = geom.XY(7, 9)
     dxy = geom.DXY(3, 4)
     return xy1a, xy1b, xy2, dxy