Skip to content

Commit eb8b206

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

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

doc/changelog.d/1816.fixed.md

+1
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

+11-3
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ def shape(self) -> TrimmedCurve:
128128
geometry = grpc_curve_to_curve(response)
129129

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

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

198206
@property
199207
@protect_grpc

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ def create_isoparametric_curves(
554554
trimmed_curves = []
555555
for c in curves:
556556
geometry = grpc_curve_to_curve(c.curve)
557-
start = Point3D([c.start.x, c.start.y, c.start.z])
558-
end = Point3D([c.end.x, c.end.y, c.end.z])
557+
start = Point3D([c.start.x, c.start.y, c.start.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
558+
end = Point3D([c.end.x, c.end.y, c.end.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
559559
interval = Interval(c.interval_start, c.interval_end)
560560
length = Quantity(c.length, DEFAULT_UNITS.SERVER_LENGTH)
561561

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

+5-1
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

+36
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)