Esempio n. 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
Esempio n. 2
0
 def test_dxy_properties(self, setup_dxy):
     _, _, dxy1, dxy2a, dxy2b = setup_dxy
     assert dxy1.length2 == 25
     assert dxy2a.length2 == 7381
     assert dxy1.length == 5
     assert dxy2a.length == pytest.approx(sqrt(7381), abs=0.000001)
     assert geom.DXY(5, 0).direction == 0
     assert geom.DXY(0, 5).direction == pytest.approx(pi / 2, abs=0.000001)
     assert geom.DXY(5, 5).direction == pytest.approx(pi / 4, abs=0.000001)
Esempio n. 3
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)
Esempio n. 4
0
 def test_dxy_angle_with(self, setup_dxy):
     xy1, _, dxy1, dxy2a, dxy2b = setup_dxy
     assert dxy1.angle_with(dxy1) == 0.0
     assert geom.DXY(5, 2).angle_with(geom.DXY(-2, 5)) == pytest.approx(
         pi / 2, abs=0.000001)
     assert geom.DXY(5, 2).angle_with(geom.DXY(2, -5)) == pytest.approx(
         (3 / 2) * pi, abs=0.000001)
     with pytest.raises(TypeError):
         _ = dxy1.angle_with((5, 5))
         _ = dxy1.angle_with(xy1)
         _ = dxy1.angle_with(5)
Esempio n. 5
0
 def test_dxy_subtract(self, setup_dxy):
     xy1, xy2, dxy1, dxy2a, dxy2b = setup_dxy
     assert dxy2a - dxy1 == geom.DXY(52, 62)
     assert isinstance(dxy2a - dxy1, geom.DXY)
     with pytest.raises(TypeError):
         _ = dxy1 - xy1
         _ = dxy2a - (5, 6)
         _ = dxy2a - 5
Esempio n. 6
0
 def test_dxy_add(self, setup_dxy):
     xy1, xy2, dxy1, dxy2a, dxy2b = setup_dxy
     assert dxy1 + dxy2a == geom.DXY(58, 70)
     assert isinstance(dxy1 + dxy2a, geom.DXY)
     assert dxy1 + xy1 == xy2
     with pytest.raises(TypeError):
         _ = dxy2a + (5, 6)
         _ = dxy2a + 5
Esempio n. 7
0
 def test_dxy_multiply_fns(self, setup_dxy):
     xy1, xy2, dxy1, dxy2a, dxy2b = setup_dxy
     assert dxy1 * 3.5 == 3.5 * dxy1 == geom.DXY(10.5, 14)
     assert isinstance(dxy1 * 3.5, geom.DXY)
     assert isinstance(3.5 * dxy1, geom.DXY)
     with pytest.raises(TypeError):
         _ = dxy1 * xy1
         _ = dxy1 * (5, 6)
Esempio n. 8
0
 def test_vector_to(self, setup_xy):
     xy1a, xy1b, xy2, dxy = setup_xy
     assert xy1a.vector_to(xy2) == dxy
     assert xy1a.vector_to(xy1b) == geom.DXY(0, 0)
     assert isinstance(xy1a.vector_to(xy2), geom.DXY)
     assert isinstance(xy1a.vector_to(xy1b), geom.DXY)
     with pytest.raises(TypeError):
         _ = xy1a.vector_to(dxy)
         _ = xy1a.vector_to((5, 6))
Esempio n. 9
0
 def test_dxy_division(self, setup_dxy):
     xy1, xy2, dxy1, dxy2a, dxy2b = setup_dxy
     assert dxy1 / 2 == geom.DXY(1.5, 2)
     assert isinstance(dxy1 / 2, geom.DXY)
     with pytest.raises(ZeroDivisionError):
         _ = dxy1 / 0.0
     with pytest.raises(TypeError):
         _ = dxy1 / dxy2a
         _ = dxy1 / xy1
         _ = dxy1 / (5, 6)
Esempio n. 10
0
 def test_dxy_bool(self):
     assert not geom.DXY(0, 0)
     assert geom.DXY(0, 5)
     assert geom.DXY(5, 0)
     assert geom.DXY(-2, 5)
Esempio n. 11
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