Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2061.test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expanding test coverage for designer and math
35 changes: 34 additions & 1 deletion tests/integration/test_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
SharedTopologyType,
SurfaceType,
)
from ansys.geometry.core.designer.body import CollisionType, FillStyle
from ansys.geometry.core.designer.body import CollisionType, FillStyle, MasterBody
from ansys.geometry.core.designer.face import FaceLoopType
from ansys.geometry.core.designer.part import MasterComponent, Part
from ansys.geometry.core.errors import GeometryExitedError
from ansys.geometry.core.materials import Material, MaterialProperty, MaterialPropertyType
from ansys.geometry.core.math import (
Expand Down Expand Up @@ -76,6 +77,38 @@
from .conftest import FILES_DIR


def test_design_selection(modeler: Modeler):
"""Test to validate the designer selection for edges and __repr__ method."""
sketch = Sketch()
sketch.box(Point2D([0, 0]), 10, 10)
design = modeler.create_design("Box")
body = design.extrude_sketch("Box", sketch, Quantity(2, UNITS.m))
ns_edge = design.create_named_selection("The Edges", body.edges[0:2])
assert ns_edge.edges[0].start == Point3D([-5, -5, 2])
assert ns_edge.edges[0].end == Point3D([5, -5, 2])
assert ns_edge.edges[1].start == Point3D([-5, -5, 0])
assert ns_edge.edges[1].end == Point3D([-5, -5, 2])
assert ns_edge.__repr__()[0:54] == "ansys.geometry.core.designer.selection.NamedSelection "


def test_design_part(modeler: Modeler):
"""Test to validate the designer part id, name, and setter for components and bodies."""
body1 = MasterBody(id="body1", name="First Only Body", grpc_client=modeler.client)
body2 = MasterBody(id="body2", name="Second Body in Component", grpc_client=modeler.client)
bodies = [body1]
part = Part(id="IDPart", name="NamePart", components=[], bodies=bodies)
masterpart = MasterComponent(id="PartMaster", name="Part Master", part=part)
assert masterpart.id == "PartMaster"
assert masterpart.name == "Part Master"
assert masterpart.__repr__()[0:50] == "MasterComponent(id=PartMaster, name=Part Master, t"
assert part.id == "IDPart"
assert part.name == "NamePart"
part.components = [body2]
assert part.components[0].name == "Second Body in Component"
part.bodies = body1
assert part.bodies.name == "First Only Body"


def test_design_extrusion_and_material_assignment(modeler: Modeler):
"""Test to validate the extrusion of a simple circle as a cylinder and the
assignment of materials to it.
Expand Down
83 changes: 81 additions & 2 deletions tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,39 @@
Vector3D,
get_two_circle_intersections,
)
from ansys.geometry.core.math.misc import intersect_interval
from ansys.geometry.core.misc import UNITS

DOUBLE_EPS = np.finfo(float).eps


def test_intersect_interval():
first_interval_min = 10
first_interval_max = 1
second_interval_min = 5
second_interval_max = 2

intersect, intersection_min, intersection_max = intersect_interval(
first_interval_min, second_interval_min, first_interval_max, second_interval_max
)
assert intersect is False
assert intersection_min == 0
assert intersection_max == 0

# 132
first_interval_min = 10
first_interval_max = 15
second_interval_min = 5
second_interval_max = 20

intersect, intersection_min, intersection_max = intersect_interval(
first_interval_min, second_interval_min, first_interval_max, second_interval_max
)
assert intersect is True
assert intersection_min == 10
assert intersection_max == 15


def test_point():
"""Simple test to create ``Point2D`` and ``Point3D``."""
# Test the default Point3D
Expand Down Expand Up @@ -392,6 +420,11 @@ def test_vector3d():
assert UNITVECTOR3D_X.is_opposite(Vector3D([-1, 0, 0]))
assert not UNITVECTOR3D_X.is_opposite(UNITVECTOR3D_X)

# Testing it fails for zero 2D vectors
vector1 = Vector3D([0, 0, 0])
vector2 = Vector3D([0, 0, 0])
assert vector1.is_parallel_to(vector2) is False


def test_vector2d():
"""Simple test to create ``Vector2D``."""
Expand Down Expand Up @@ -478,6 +511,11 @@ def test_vector2d():
assert UNITVECTOR2D_X.is_opposite(Vector2D([-1, 0]))
assert not UNITVECTOR2D_X.is_opposite(UNITVECTOR2D_X)

# Testing it fails for zero 2D vectors
vector1 = Vector2D([0, 0])
vector2 = Vector2D([0, 0])
assert vector1.is_parallel_to(vector2) is False


def test_unitvector3d():
"""Simple test to create a ``UnitVector3D``."""
Expand Down Expand Up @@ -646,6 +684,12 @@ def test_rotate_vector():
# Assert that the result matches the expected vector
assert np.allclose(result_vector, expected_vector)

# Testing that the vector cannot be zero
vector1 = Vector3D([0, 0, 0])
vector2 = Vector3D([0, 0, 0])
with pytest.raises(Exception, match="Invalid vector operation: rotation axis cannot be zero."):
vector1.rotate_vector(vector2, np.pi)


def test_matrix():
"""Simple test to create a ``Matrix``."""
Expand Down Expand Up @@ -679,6 +723,18 @@ def test_matrix():
with pytest.raises(ValueError, match="Matrix should only be a 2D array."):
Matrix([None, None, None, None, None])

# 221 checking if the 2nd row is part of identify matrix
matrix = Matrix44([[1, 0, 0, 5], [1, 1, 0, 3], [0, 0, 1, 2], [0, 0, 0, 1]])
assert matrix.is_translation() is False

# 227 checking if the 3rd row is part of identify matrix
matrix = Matrix44([[1, 0, 0, 5], [0, 1, 0, 3], [0, 0, 0.5, 2], [0, 0, 0, 1]])
assert matrix.is_translation() is False

# 229 - not sure if this needed since it should be covered in 227
matrix = Matrix44([[1, 0, 0, 5], [0, 1, 0, 3], [0, 0, 0.8, 2], [0, 0, 0, 1]])
assert matrix.is_translation() is False


def test_matrix_errors():
"""Testing multiple ``Matrix`` errors."""
Expand Down Expand Up @@ -706,6 +762,15 @@ def test_matrix_errors():
):
m_1 * m_2

# Error if x and y vectors are not orthongonal for rotation
matrix = Matrix44([[1, 0, 0, 5], [1, 0, 0, 3], [0, 0, 1, 2], [0, 0, 0, 1]])
with pytest.raises(ValueError, match="The provided direction vectors are not orthogonal."):
matrix.create_rotation(Vector3D([1, 0, 0]), Vector3D([1, 0, 0]))

# Error if x and z and y and z are not orthongonal for rotation
with pytest.raises(ValueError, match="The provided direction vectors are not orthogonal."):
matrix.create_rotation(Vector3D([1, 0, 0]), Vector3D([0, 1, 0]), Vector3D([1, 1, 0]))


def test_matrix_33():
"""Simple test to create a ``Matrix33``."""
Expand Down Expand Up @@ -1335,9 +1400,13 @@ def test_bounding_box2d_no_intersection():
box1 = BoundingBox2D(0, 1, 0, 1)
box2 = BoundingBox2D(2, 3, 0, 1)

# Get intersection and check
# Get intersection for x and check
intersection = BoundingBox2D.intersect_bboxes(box1, box2)
assert intersection is None
# Get intersection for y and check
boxfirst = BoundingBox2D(0, 5, 0, 5)
boxsecond = BoundingBox2D(3, 8, 6, 8)
assert BoundingBox2D.intersect_bboxes(boxfirst, boxsecond) is None


def test_bounding_box_evaluates_bounds_comparisons():
Expand Down Expand Up @@ -1373,6 +1442,16 @@ def test_bounding_box_no_intersection():
box1 = BoundingBox(Point3D([0, 0, 0]), Point3D([1, 1, 0]))
box2 = BoundingBox(Point3D([2, 0, 0]), Point3D([3, 1, 0]))

# Get intersection and check
# Get intersection for x and check
intersection = BoundingBox.intersect_bboxes(box1, box2)
assert intersection is None

# Get intersection for y and check
firstboxbounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 1, 1]), Point3D([0, 0, 0]))
secondboxbounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4]))
assert BoundingBox.intersect_bboxes(firstboxbounding, secondboxbounding) is None

# Get intersection for z and check
firstboxbounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 2, 1]), Point3D([0, 0, 0]))
secondboxbounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4]))
assert BoundingBox.intersect_bboxes(firstboxbounding, secondboxbounding) is None
Loading