Skip to content

Commit ba21a38

Browse files
syscordanpre-commit-ci[bot]pyansys-ci-botRyanJWardRobPasMue
authored
test: expanding test coverage for sketch (#2047)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: rward <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 4a3dda3 commit ba21a38

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

doc/changelog.d/2047.test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Expanding test coverage for sketch

src/ansys/geometry/core/sketch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from ansys.geometry.core.sketch.edge import SketchEdge
2828
from ansys.geometry.core.sketch.ellipse import SketchEllipse
2929
from ansys.geometry.core.sketch.face import SketchFace
30-
from ansys.geometry.core.sketch.gears import DummyGear
30+
from ansys.geometry.core.sketch.gears import DummyGear, SpurGear
3131
from ansys.geometry.core.sketch.polygon import Polygon
3232
from ansys.geometry.core.sketch.segment import SketchSegment
3333
from ansys.geometry.core.sketch.sketch import Sketch

tests/test_sketch.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,123 @@
4141
Polygon,
4242
Sketch,
4343
SketchCircle,
44+
SketchEdge,
4445
SketchEllipse,
4546
SketchSegment,
4647
Slot,
48+
SpurGear,
49+
Triangle,
4750
)
4851

4952
from .conftest import are_graphics_available
5053

5154
DOUBLE_EPS = np.finfo(float).eps
5255

5356

57+
def test_sketch_sketch():
58+
"""Test the sketch sketch tag functionality"""
59+
sketch = Sketch()
60+
sketch.segment(Point2D([-4, 5], unit=UNITS.m), Point2D([4, 5], unit=UNITS.m))
61+
sketch.tag = "SketchTag"
62+
assert sketch.tag == "SketchTag"
63+
64+
65+
def test_sketch_segment():
66+
"""Test the sketch segment unit conversion for end point, not equal,
67+
and plane change functionality"""
68+
start_point = Point2D([0, 0], unit=UNITS.meter)
69+
end_point = Point2D([5, 5], unit=UNITS.kilometer)
70+
segment1 = SketchSegment(start_point, end_point)
71+
assert segment1.end == Point2D([5000, 5000])
72+
segment2 = SketchSegment(start_point, end_point)
73+
assert segment1.__ne__(segment2) is False
74+
segment2 = SketchSegment(end_point, start_point)
75+
assert segment1.__ne__(segment2) is True
76+
new_plane = Plane(
77+
origin=Point3D([0, 0, 5]), direction_x=Vector3D([1, 0, 0]), direction_y=Vector3D([0, 0, 1])
78+
)
79+
segment1.plane_change(new_plane)
80+
assert segment1.direction == UnitVector3D([0.70710678, 0.0, 0.70710678])
81+
82+
83+
@pytest.mark.skipif(
84+
not are_graphics_available(), reason="Skipping due to graphics requirements missing"
85+
)
86+
def test_sketch_gears():
87+
"""Test the sketch gears addendum, dedendum, and visualization polydate functionality"""
88+
origin = Point2D([0, 1], unit=UNITS.meter)
89+
module = 40
90+
pressure_angle = Quantity(20, UNITS.deg)
91+
n_teeth = 22
92+
gearspur = SpurGear(origin, module, pressure_angle, n_teeth)
93+
assert gearspur.addendum == 40.0
94+
assert gearspur.dedendum == 50.0
95+
gearspurpoly = gearspur.visualization_polydata
96+
assert gearspurpoly.center == pytest.approx(
97+
([0.0, 1.0000000298023224, 0.0]),
98+
rel=1e-7,
99+
abs=1e-8,
100+
)
101+
assert gearspurpoly.bounds == pytest.approx(
102+
[-0.4852221608161926, 0.4852221608161926, 0.5148882269859314, 1.4851118326187134, 0.0, 0.0],
103+
rel=1e-7,
104+
abs=1e-8,
105+
)
106+
assert gearspurpoly.n_cells == 704
107+
assert gearspurpoly.n_points == 70405
108+
assert gearspurpoly.n_open_edges == 0.0
109+
110+
111+
def test_sketch_circle_plane_change():
112+
"""Test the sketch circle change plane functionality"""
113+
center = Point2D([5, 10], UNITS.m)
114+
radius = 3 * UNITS.m
115+
circle = SketchCircle(center, radius)
116+
new_plane = Plane(
117+
origin=Point3D([0, 0, 5]), direction_x=Vector3D([1, 0, 0]), direction_y=Vector3D([0, 0, 1])
118+
)
119+
circle.plane_change(new_plane)
120+
assert circle.dir_x == Vector3D([1, 0, 0])
121+
assert circle.dir_y == Vector3D([0, 0, 1])
122+
assert circle.dir_z == Vector3D([0, -1, 0])
123+
124+
125+
def test_sketch_face():
126+
"""Test the sketch face perimeter and change plane functionality"""
127+
sketch = Sketch()
128+
per = Triangle(Point2D([10, 10]), Point2D([2, 1]), Point2D([10, -10])).perimeter
129+
assert abs((per - 45.64306508752774 * UNITS.m).m) <= 5e-14
130+
sketch.triangle(Point2D([10, 10]), Point2D([2, 1]), Point2D([10, -10]), tag="Triangle")
131+
132+
new_plane = Plane(
133+
origin=Point3D([0, 0, 5]), direction_x=Vector3D([1, 0, 0]), direction_y=Vector3D([0, 0, 1])
134+
)
135+
sketch.faces[0].plane_change(new_plane)
136+
137+
138+
def test_sketch_edge():
139+
"""Test the sketch edge functionality"""
140+
sketch = SketchEdge()
141+
with pytest.raises(
142+
NotImplementedError, match="Each edge must provide the start point definition."
143+
):
144+
sketch.start()
145+
with pytest.raises(
146+
NotImplementedError, match="Each edge must provide the end point definition."
147+
):
148+
sketch.end()
149+
with pytest.raises(NotImplementedError, match="Each edge must provide the length definition."):
150+
sketch.length()
151+
with pytest.raises(
152+
NotImplementedError, match="Each edge must provide the polydata definition."
153+
):
154+
sketch.visualization_polydata()
155+
plane = Plane(
156+
origin=Point3D([0, 0, 0]), direction_x=Vector3D([1, 2, -1]), direction_y=Vector3D([1, 0, 1])
157+
)
158+
sketch.plane_change(plane)
159+
160+
54161
def test_errors_sketch_segment():
55162
"""Check errors when handling a ``SketchSegment``."""
56163
with pytest.raises(BeartypeCallHintParamViolation):

0 commit comments

Comments
 (0)