Skip to content

fix: edge start and end were not being mapped correctly #1816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2025
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/1816.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
edge start and end were not being mapped correctly
18 changes: 14 additions & 4 deletions src/ansys/geometry/core/designer/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ def shape(self) -> TrimmedCurve:
geometry = grpc_curve_to_curve(response)

response = self._edges_stub.GetStartAndEndPoints(self._grpc_id)
start = Point3D([response.start.x, response.start.y, response.start.z])
end = Point3D([response.end.x, response.end.y, response.end.z])
start = Point3D(
[response.start.x, response.start.y, response.start.z],
unit=DEFAULT_UNITS.SERVER_LENGTH,
)
end = Point3D(
[response.end.x, response.end.y, response.end.z], unit=DEFAULT_UNITS.SERVER_LENGTH
)

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

@property
@protect_grpc
Expand All @@ -205,4 +213,6 @@ def end(self) -> Point3D:
# Only for versions earlier than 24.2.0 (before the introduction of the shape property)
self._grpc_client.log.debug("Requesting edge end point from server.")
response = self._edges_stub.GetStartAndEndPoints(self._grpc_id)
return Point3D([response.end.x, response.end.y, response.end.z])
return Point3D(
[response.end.x, response.end.y, response.end.z], unit=DEFAULT_UNITS.SERVER_LENGTH
)
4 changes: 2 additions & 2 deletions src/ansys/geometry/core/designer/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ def create_isoparametric_curves(
trimmed_curves = []
for c in curves:
geometry = grpc_curve_to_curve(c.curve)
start = Point3D([c.start.x, c.start.y, c.start.z])
end = Point3D([c.end.x, c.end.y, c.end.z])
start = Point3D([c.start.x, c.start.y, c.start.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
end = Point3D([c.end.x, c.end.y, c.end.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
interval = Interval(c.interval_start, c.interval_end)
length = Quantity(c.length, DEFAULT_UNITS.SERVER_LENGTH)

Expand Down
6 changes: 5 additions & 1 deletion src/ansys/geometry/core/shapes/curves/trimmed_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ansys.geometry.core.connection.conversions import trimmed_curve_to_grpc_trimmed_curve
from ansys.geometry.core.errors import protect_grpc
from ansys.geometry.core.math.point import Point3D
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
from ansys.geometry.core.shapes.curves.curve import Curve
from ansys.geometry.core.shapes.curves.curve_evaluation import CurveEvaluation
from ansys.geometry.core.shapes.parameterization import Interval
Expand Down Expand Up @@ -148,7 +149,10 @@ def intersect_curve(self, other: "TrimmedCurve") -> list[Point3D]:
)
if res.intersect is False:
return []
return [Point3D([point.x, point.y, point.z]) for point in res.points]
return [
Point3D([point.x, point.y, point.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
for point in res.points
]

def __repr__(self) -> str:
"""Represent the trimmed curve as a string."""
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,39 @@ def test_issue_1807_translate_sketch_non_default_units():
finally:
# Reset the default units to meters
DEFAULT_UNITS.LENGTH = UNITS.meter


def test_issue_1813_edge_start_end_non_default_units(modeler: Modeler):
"""Test that creating an edge with non-default units is handled properly.

Notes
-----
Apparently there are some issues on the start and end locations when
using non-default units. This test is to verify that the issue has been
resolved.

For more info see
https://github.com/ansys/pyansys-geometry/issues/1813
"""
try:
# Create initial design and set default units to millimeters
design = modeler.create_design("MillimetersEdgeIssue")
DEFAULT_UNITS.LENGTH = UNITS.mm

# Sketch and extrude box
box = design.extrude_sketch("box", Sketch().box(Point2D([0.5, 0.5]), 1, 1), 1)

# Perform some assertions like...
# 1) The edge lengths should be 1 mm
for face in box.faces:
for edge in face.edges:
assert np.isclose(edge.length, 1 * UNITS.mm)
length_vec = edge.start - edge.end
assert np.isclose(np.linalg.norm(length_vec) * length_vec.base_unit, 1 * UNITS.mm)

# 2) Verify the box volume
assert np.isclose(box.volume, 1 * UNITS.mm * UNITS.mm * UNITS.mm)

finally:
# Reset the default units to meters
DEFAULT_UNITS.LENGTH = UNITS.meter
Loading