Skip to content

Commit 179686b

Browse files
fix: edge start and end were not being mapped correctly (#1816)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent f26f02c commit 179686b

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

doc/changelog.d/1816.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edge start and end were not being mapped correctly

src/ansys/geometry/core/designer/edge.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,13 @@ def shape(self) -> TrimmedCurve:
127127
geometry = grpc_curve_to_curve(response)
128128

129129
response = self._edges_stub.GetStartAndEndPoints(self._grpc_id)
130-
start = Point3D([response.start.x, response.start.y, response.start.z])
131-
end = Point3D([response.end.x, response.end.y, response.end.z])
130+
start = Point3D(
131+
[response.start.x, response.start.y, response.start.z],
132+
unit=DEFAULT_UNITS.SERVER_LENGTH,
133+
)
134+
end = Point3D(
135+
[response.end.x, response.end.y, response.end.z], unit=DEFAULT_UNITS.SERVER_LENGTH
136+
)
132137

133138
response = self._edges_stub.GetLength(self._grpc_id)
134139
length = Quantity(response.length, DEFAULT_UNITS.SERVER_LENGTH)
@@ -192,7 +197,10 @@ def start(self) -> Point3D:
192197
# Only for versions earlier than 24.2.0 (before the introduction of the shape property)
193198
self._grpc_client.log.debug("Requesting edge start point from server.")
194199
response = self._edges_stub.GetStartAndEndPoints(self._grpc_id)
195-
return Point3D([response.start.x, response.start.y, response.start.z])
200+
return Point3D(
201+
[response.start.x, response.start.y, response.start.z],
202+
unit=DEFAULT_UNITS.SERVER_LENGTH,
203+
)
196204

197205
@property
198206
@protect_grpc
@@ -205,4 +213,6 @@ def end(self) -> Point3D:
205213
# Only for versions earlier than 24.2.0 (before the introduction of the shape property)
206214
self._grpc_client.log.debug("Requesting edge end point from server.")
207215
response = self._edges_stub.GetStartAndEndPoints(self._grpc_id)
208-
return Point3D([response.end.x, response.end.y, response.end.z])
216+
return Point3D(
217+
[response.end.x, response.end.y, response.end.z], unit=DEFAULT_UNITS.SERVER_LENGTH
218+
)

src/ansys/geometry/core/designer/face.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ def create_isoparametric_curves(
548548
trimmed_curves = []
549549
for c in curves:
550550
geometry = grpc_curve_to_curve(c.curve)
551-
start = Point3D([c.start.x, c.start.y, c.start.z])
552-
end = Point3D([c.end.x, c.end.y, c.end.z])
551+
start = Point3D([c.start.x, c.start.y, c.start.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
552+
end = Point3D([c.end.x, c.end.y, c.end.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
553553
interval = Interval(c.interval_start, c.interval_end)
554554
length = Quantity(c.length, DEFAULT_UNITS.SERVER_LENGTH)
555555

src/ansys/geometry/core/shapes/curves/trimmed_curve.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from ansys.geometry.core.connection.conversions import trimmed_curve_to_grpc_trimmed_curve
3030
from ansys.geometry.core.errors import protect_grpc
3131
from ansys.geometry.core.math.point import Point3D
32+
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
3233
from ansys.geometry.core.shapes.curves.curve import Curve
3334
from ansys.geometry.core.shapes.curves.curve_evaluation import CurveEvaluation
3435
from ansys.geometry.core.shapes.parameterization import Interval
@@ -148,7 +149,10 @@ def intersect_curve(self, other: "TrimmedCurve") -> list[Point3D]:
148149
)
149150
if res.intersect is False:
150151
return []
151-
return [Point3D([point.x, point.y, point.z]) for point in res.points]
152+
return [
153+
Point3D([point.x, point.y, point.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
154+
for point in res.points
155+
]
152156

153157
def __repr__(self) -> str:
154158
"""Represent the trimmed curve as a string."""

tests/integration/test_issues.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,39 @@ def test_issue_1807_translate_sketch_non_default_units():
289289
finally:
290290
# Reset the default units to meters
291291
DEFAULT_UNITS.LENGTH = UNITS.meter
292+
293+
294+
def test_issue_1813_edge_start_end_non_default_units(modeler: Modeler):
295+
"""Test that creating an edge with non-default units is handled properly.
296+
297+
Notes
298+
-----
299+
Apparently there are some issues on the start and end locations when
300+
using non-default units. This test is to verify that the issue has been
301+
resolved.
302+
303+
For more info see
304+
https://github.com/ansys/pyansys-geometry/issues/1813
305+
"""
306+
try:
307+
# Create initial design and set default units to millimeters
308+
design = modeler.create_design("MillimetersEdgeIssue")
309+
DEFAULT_UNITS.LENGTH = UNITS.mm
310+
311+
# Sketch and extrude box
312+
box = design.extrude_sketch("box", Sketch().box(Point2D([0.5, 0.5]), 1, 1), 1)
313+
314+
# Perform some assertions like...
315+
# 1) The edge lengths should be 1 mm
316+
for face in box.faces:
317+
for edge in face.edges:
318+
assert np.isclose(edge.length, 1 * UNITS.mm)
319+
length_vec = edge.start - edge.end
320+
assert np.isclose(np.linalg.norm(length_vec) * length_vec.base_unit, 1 * UNITS.mm)
321+
322+
# 2) Verify the box volume
323+
assert np.isclose(box.volume, 1 * UNITS.mm * UNITS.mm * UNITS.mm)
324+
325+
finally:
326+
# Reset the default units to meters
327+
DEFAULT_UNITS.LENGTH = UNITS.meter

0 commit comments

Comments
 (0)