Skip to content

Commit 7defdf3

Browse files
test: Expand code coverage and fix a few things (#2039)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 9859054 commit 7defdf3

File tree

7 files changed

+358
-26
lines changed

7 files changed

+358
-26
lines changed

doc/changelog.d/2039.test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Expand code coverage and fix a few things

src/ansys/geometry/core/shapes/box_uv.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,14 @@ def get_center(self) -> ParamUV:
9393

9494
def is_negative(self, tolerance_u: Real, tolerance_v: Real) -> bool:
9595
"""Check whether the BoxUV is negative."""
96-
if self.is_empty():
97-
return False
9896
return self.interval_u.is_negative(tolerance_u) or self.interval_v.is_negative(tolerance_v)
9997

10098
def contains(self, param: ParamUV) -> bool:
10199
"""Check whether the BoxUV contains a given u and v pair parameter."""
102-
if self.is_empty():
103-
# Cannot check contains for an empty box uv.
104-
raise RuntimeError("Cannot check contains for an empty box uv.")
105100
return self.interval_u.contains(param.u) and self.interval_v.contains(param.v)
106101

107102
def inflate(self, delta_u: Real, delta_v: Real) -> "BoxUV":
108103
"""Enlarge the BoxUV u and v intervals by deltas."""
109-
if self.is_empty():
110-
# Cannot inflate an empty box uv.
111-
raise RuntimeError("Cannot inflate an empty box uv.")
112104
return BoxUV(self.interval_u.inflate(delta_u), self.interval_v.inflate(delta_v))
113105

114106
def get_corner(self, location: LocationUV) -> ParamUV:

src/ansys/geometry/core/shapes/parameterization.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class Interval:
150150
@check_input_types
151151
def __init__(self, start: Real, end: Real) -> None:
152152
"""Initialize ``Interval`` class."""
153-
if end < start:
153+
if end <= start:
154154
raise ValueError("Start value must be less than end value")
155155

156156
self._start = start
@@ -172,9 +172,6 @@ def __eq__(self, other: object):
172172
if not isinstance(other, Interval):
173173
# don't attempt to compare against unrelated types
174174
return NotImplemented
175-
if self.is_empty() or other.is_empty():
176-
return self.is_empty() and other.is_empty()
177-
178175
return Accuracy.equal_doubles(self.start, other.start) and Accuracy.equal_doubles(
179176
self.end, other.end
180177
)
@@ -270,10 +267,6 @@ def unite(first: "Interval", second: "Interval") -> "Interval":
270267
Interval
271268
Union of the two intervals.
272269
"""
273-
if first.is_empty():
274-
return second
275-
if second.is_empty():
276-
return first
277270
return Interval(min(first.start, second.start), max(first.end, second.end))
278271

279272
def self_unite(self, other: "Interval") -> None:
@@ -302,10 +295,8 @@ def intersect(first: "Interval", second: "Interval", tolerance: Real) -> "Interv
302295
Interval
303296
Intersection of the two intervals.
304297
"""
305-
if first.is_empty() or second.is_empty():
306-
return None # supposed to be empty
307-
intersection = Interval(max(first.start, second.start), min(first.end, second.send))
308-
if not intersection.is_negative(tolerance):
298+
intersection = Interval(max(first.start, second.start), min(first.end, second.end))
299+
if intersection.is_negative(tolerance) == 1:
309300
return intersection
310301
return None # supposed to be empty
311302

@@ -336,8 +327,6 @@ def contains_value(self, t: Real, accuracy: Real) -> bool:
336327
bool
337328
``True`` if the interval contains the value, ``False`` otherwise.
338329
"""
339-
if self.is_empty():
340-
return False
341330
negative_abs_accuracy = -abs(accuracy)
342331
if self.start > self.end:
343332
if self.start - t < negative_abs_accuracy:
@@ -368,9 +357,6 @@ def contains(self, t: Real) -> bool:
368357

369358
def inflate(self, delta: Real) -> "Interval":
370359
"""Enlarge the current interval by the given delta value."""
371-
if self.is_empty():
372-
# throw Error.InvalidMethodOnEmptyObjectException(GetType())
373-
raise Exception("Invalid Method On Empty Object Exception" + type(self).__name__)
374360
return Interval(self.start - delta, self.end + delta)
375361

376362
def __repr__(self) -> str:

tests/integration/test_design.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@
6161
Cone,
6262
Cylinder,
6363
Ellipse,
64-
Interval,
6564
Line,
6665
ParamUV,
6766
Sphere,
6867
Torus,
6968
)
7069
from ansys.geometry.core.shapes.box_uv import BoxUV
70+
from ansys.geometry.core.shapes.parameterization import (
71+
Interval,
72+
)
7173
from ansys.geometry.core.sketch import Sketch
7274

7375
from ..conftest import are_graphics_available

tests/integration/test_trimmed_geometry.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"""Tests trimmed geometry."""
2323

2424
import numpy as np
25+
from pint import Quantity
2526
import pytest
2627

2728
from ansys.api.geometry.v0.commands_pb2 import CreateSketchLineRequest
@@ -30,6 +31,7 @@
3031
from ansys.geometry.core.designer.face import SurfaceType
3132
from ansys.geometry.core.math import Point3D, UnitVector3D
3233
from ansys.geometry.core.math.point import Point2D
34+
from ansys.geometry.core.misc import UNITS
3335
from ansys.geometry.core.modeler import Modeler
3436
from ansys.geometry.core.shapes import Circle, Line
3537
from ansys.geometry.core.shapes.box_uv import LocationUV
@@ -304,3 +306,48 @@ def test_trimmed_curve_circle_rotate(hedgehog_design):
304306

305307
assert np.allclose(trimmed_curve.start, Point3D([0.01, 0.01, 0.02]))
306308
assert np.allclose(trimmed_curve.end, Point3D([0.01, 0.01, 0.04]))
309+
310+
311+
def test_trimmed_curve(modeler: Modeler):
312+
"""Test Trimmed Curve class"""
313+
design = modeler.create_design("trimmed_curve_edges")
314+
body = design.extrude_sketch("box", Sketch().box(Point2D([0, 0]), 1, 1), 1)
315+
with pytest.raises(ValueError):
316+
design.bodies[0].edges[0].shape.intersect_curve(design.bodies[0].edges[1].shape)
317+
# Retrieve edges and initialize TrimmedCurve objects with the gRPC client
318+
edge0 = TrimmedCurve(
319+
geometry=body.edges[0].shape.geometry,
320+
start=body.edges[0].shape.start,
321+
end=body.edges[0].shape.end,
322+
interval=body.edges[0].shape.interval,
323+
length=body.edges[0].shape.length,
324+
grpc_client=modeler.client, # Pass the gRPC client here
325+
)
326+
edge1 = TrimmedCurve(
327+
geometry=body.edges[1].shape.geometry,
328+
start=body.edges[1].shape.start,
329+
end=body.edges[1].shape.end,
330+
interval=body.edges[1].shape.interval,
331+
length=body.edges[1].shape.length,
332+
grpc_client=modeler.client, # Pass the gRPC client here
333+
)
334+
335+
edge2 = TrimmedCurve(
336+
geometry=body.edges[4].shape.geometry,
337+
start=body.edges[4].shape.start,
338+
end=body.edges[4].shape.end,
339+
interval=body.edges[4].shape.interval,
340+
length=body.edges[4].shape.length,
341+
grpc_client=modeler.client, # Pass the gRPC client here
342+
)
343+
344+
# Perform assertions and call intersect_curve
345+
assert (
346+
edge0.__repr__()
347+
== "TrimmedCurve(geometry: <class 'ansys.geometry.core.shapes.curves.line.Line'>, "
348+
"start: [-0.5 -0.5 1. ], end: [ 0.5 -0.5 1. ], "
349+
"interval: Interval(start=0.0, end=1.0), length: 1.0 meter)"
350+
)
351+
assert edge0.length == Quantity(1, UNITS.m)
352+
assert edge0.intersect_curve(edge1) == [Point3D([-0.5, -0.5, 1.0])]
353+
assert edge0.intersect_curve(edge2) == []

tests/test_parameterization.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,31 @@ def test_parameterization():
131131

132132
with pytest.raises(BeartypeCallHintParamViolation):
133133
Parameterization(ParamForm.CLOSED, ParamType.OTHER, [-1, 1])
134+
135+
136+
def test_param_uv_iter():
137+
"""Test the __iter__ method of ParamUV."""
138+
param = ParamUV(3.5, 7.2)
139+
u, v = param # Unpack using the __iter__ method
140+
assert u == 3.5
141+
assert v == 7.2
142+
143+
144+
def test_param_uv_repr():
145+
"""Test the __repr__ method of ParamUV."""
146+
param = ParamUV(3.5, 7.2)
147+
assert repr(param) == "ParamUV(u=3.5, v=7.2)"
148+
149+
150+
def test_parameterization_repr():
151+
"""Test the __repr__ method of the Parameterization class."""
152+
# Create a sample Parameterization object
153+
interval = Interval(0, 10)
154+
parameterization = Parameterization(ParamForm.CLOSED, ParamType.LINEAR, interval)
155+
# Expected string representation
156+
expected_repr = (
157+
"Parameterization(form=ParamForm.CLOSED, type=ParamType.LINEAR, "
158+
"interval=Interval(start=0, end=10))"
159+
)
160+
# Assert the __repr__ output matches the expected string
161+
assert repr(parameterization) == expected_repr

0 commit comments

Comments
 (0)