|
50 | 50 | Vector3D,
|
51 | 51 | get_two_circle_intersections,
|
52 | 52 | )
|
| 53 | +from ansys.geometry.core.math.misc import intersect_interval |
53 | 54 | from ansys.geometry.core.misc import UNITS
|
54 | 55 |
|
55 | 56 | DOUBLE_EPS = np.finfo(float).eps
|
56 | 57 |
|
57 | 58 |
|
| 59 | +def test_intersect_interval(): |
| 60 | + first_interval_min = 10 |
| 61 | + first_interval_max = 1 |
| 62 | + second_interval_min = 5 |
| 63 | + second_interval_max = 2 |
| 64 | + |
| 65 | + intersect, intersection_min, intersection_max = intersect_interval( |
| 66 | + first_interval_min, second_interval_min, first_interval_max, second_interval_max |
| 67 | + ) |
| 68 | + assert intersect is False |
| 69 | + assert intersection_min == 0 |
| 70 | + assert intersection_max == 0 |
| 71 | + |
| 72 | + # 132 |
| 73 | + first_interval_min = 10 |
| 74 | + first_interval_max = 15 |
| 75 | + second_interval_min = 5 |
| 76 | + second_interval_max = 20 |
| 77 | + |
| 78 | + intersect, intersection_min, intersection_max = intersect_interval( |
| 79 | + first_interval_min, second_interval_min, first_interval_max, second_interval_max |
| 80 | + ) |
| 81 | + assert intersect is True |
| 82 | + assert intersection_min == 10 |
| 83 | + assert intersection_max == 15 |
| 84 | + |
| 85 | + |
58 | 86 | def test_point():
|
59 | 87 | """Simple test to create ``Point2D`` and ``Point3D``."""
|
60 | 88 | # Test the default Point3D
|
@@ -392,6 +420,11 @@ def test_vector3d():
|
392 | 420 | assert UNITVECTOR3D_X.is_opposite(Vector3D([-1, 0, 0]))
|
393 | 421 | assert not UNITVECTOR3D_X.is_opposite(UNITVECTOR3D_X)
|
394 | 422 |
|
| 423 | + # Testing it fails for zero 2D vectors |
| 424 | + vector1 = Vector3D([0, 0, 0]) |
| 425 | + vector2 = Vector3D([0, 0, 0]) |
| 426 | + assert vector1.is_parallel_to(vector2) is False |
| 427 | + |
395 | 428 |
|
396 | 429 | def test_vector2d():
|
397 | 430 | """Simple test to create ``Vector2D``."""
|
@@ -478,6 +511,11 @@ def test_vector2d():
|
478 | 511 | assert UNITVECTOR2D_X.is_opposite(Vector2D([-1, 0]))
|
479 | 512 | assert not UNITVECTOR2D_X.is_opposite(UNITVECTOR2D_X)
|
480 | 513 |
|
| 514 | + # Testing it fails for zero 2D vectors |
| 515 | + vector1 = Vector2D([0, 0]) |
| 516 | + vector2 = Vector2D([0, 0]) |
| 517 | + assert vector1.is_parallel_to(vector2) is False |
| 518 | + |
481 | 519 |
|
482 | 520 | def test_unitvector3d():
|
483 | 521 | """Simple test to create a ``UnitVector3D``."""
|
@@ -646,6 +684,12 @@ def test_rotate_vector():
|
646 | 684 | # Assert that the result matches the expected vector
|
647 | 685 | assert np.allclose(result_vector, expected_vector)
|
648 | 686 |
|
| 687 | + # Testing that the vector cannot be zero |
| 688 | + vector1 = Vector3D([0, 0, 0]) |
| 689 | + vector2 = Vector3D([0, 0, 0]) |
| 690 | + with pytest.raises(Exception, match="Invalid vector operation: rotation axis cannot be zero."): |
| 691 | + vector1.rotate_vector(vector2, np.pi) |
| 692 | + |
649 | 693 |
|
650 | 694 | def test_matrix():
|
651 | 695 | """Simple test to create a ``Matrix``."""
|
@@ -679,6 +723,18 @@ def test_matrix():
|
679 | 723 | with pytest.raises(ValueError, match="Matrix should only be a 2D array."):
|
680 | 724 | Matrix([None, None, None, None, None])
|
681 | 725 |
|
| 726 | + # 221 checking if the 2nd row is part of identify matrix |
| 727 | + matrix = Matrix44([[1, 0, 0, 5], [1, 1, 0, 3], [0, 0, 1, 2], [0, 0, 0, 1]]) |
| 728 | + assert matrix.is_translation() is False |
| 729 | + |
| 730 | + # 227 checking if the 3rd row is part of identify matrix |
| 731 | + matrix = Matrix44([[1, 0, 0, 5], [0, 1, 0, 3], [0, 0, 0.5, 2], [0, 0, 0, 1]]) |
| 732 | + assert matrix.is_translation() is False |
| 733 | + |
| 734 | + # 229 - not sure if this needed since it should be covered in 227 |
| 735 | + matrix = Matrix44([[1, 0, 0, 5], [0, 1, 0, 3], [0, 0, 0.8, 2], [0, 0, 0, 1]]) |
| 736 | + assert matrix.is_translation() is False |
| 737 | + |
682 | 738 |
|
683 | 739 | def test_matrix_errors():
|
684 | 740 | """Testing multiple ``Matrix`` errors."""
|
@@ -706,6 +762,15 @@ def test_matrix_errors():
|
706 | 762 | ):
|
707 | 763 | m_1 * m_2
|
708 | 764 |
|
| 765 | + # Error if x and y vectors are not orthongonal for rotation |
| 766 | + matrix = Matrix44([[1, 0, 0, 5], [1, 0, 0, 3], [0, 0, 1, 2], [0, 0, 0, 1]]) |
| 767 | + with pytest.raises(ValueError, match="The provided direction vectors are not orthogonal."): |
| 768 | + matrix.create_rotation(Vector3D([1, 0, 0]), Vector3D([1, 0, 0])) |
| 769 | + |
| 770 | + # Error if x and z and y and z are not orthongonal for rotation |
| 771 | + with pytest.raises(ValueError, match="The provided direction vectors are not orthogonal."): |
| 772 | + matrix.create_rotation(Vector3D([1, 0, 0]), Vector3D([0, 1, 0]), Vector3D([1, 1, 0])) |
| 773 | + |
709 | 774 |
|
710 | 775 | def test_matrix_33():
|
711 | 776 | """Simple test to create a ``Matrix33``."""
|
@@ -1335,9 +1400,13 @@ def test_bounding_box2d_no_intersection():
|
1335 | 1400 | box1 = BoundingBox2D(0, 1, 0, 1)
|
1336 | 1401 | box2 = BoundingBox2D(2, 3, 0, 1)
|
1337 | 1402 |
|
1338 |
| - # Get intersection and check |
| 1403 | + # Get intersection for x and check |
1339 | 1404 | intersection = BoundingBox2D.intersect_bboxes(box1, box2)
|
1340 | 1405 | assert intersection is None
|
| 1406 | + # Get intersection for y and check |
| 1407 | + boxfirst = BoundingBox2D(0, 5, 0, 5) |
| 1408 | + boxsecond = BoundingBox2D(3, 8, 6, 8) |
| 1409 | + assert BoundingBox2D.intersect_bboxes(boxfirst, boxsecond) is None |
1341 | 1410 |
|
1342 | 1411 |
|
1343 | 1412 | def test_bounding_box_evaluates_bounds_comparisons():
|
@@ -1373,6 +1442,16 @@ def test_bounding_box_no_intersection():
|
1373 | 1442 | box1 = BoundingBox(Point3D([0, 0, 0]), Point3D([1, 1, 0]))
|
1374 | 1443 | box2 = BoundingBox(Point3D([2, 0, 0]), Point3D([3, 1, 0]))
|
1375 | 1444 |
|
1376 |
| - # Get intersection and check |
| 1445 | + # Get intersection for x and check |
1377 | 1446 | intersection = BoundingBox.intersect_bboxes(box1, box2)
|
1378 | 1447 | assert intersection is None
|
| 1448 | + |
| 1449 | + # Get intersection for y and check |
| 1450 | + firstboxbounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 1, 1]), Point3D([0, 0, 0])) |
| 1451 | + secondboxbounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4])) |
| 1452 | + assert BoundingBox.intersect_bboxes(firstboxbounding, secondboxbounding) is None |
| 1453 | + |
| 1454 | + # Get intersection for z and check |
| 1455 | + firstboxbounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 2, 1]), Point3D([0, 0, 0])) |
| 1456 | + secondboxbounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4])) |
| 1457 | + assert BoundingBox.intersect_bboxes(firstboxbounding, secondboxbounding) is None |
0 commit comments