Skip to content

Commit 7039876

Browse files
fix: translating sketch issues when using a custom default unit (#1808)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent b827101 commit 7039876

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

.github/workflows/ci_cd.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ jobs:
310310
if: github.ref != 'refs/heads/blitz'
311311
run: |
312312
git fetch origin blitz
313-
git diff --name-only origin/blitz doc/source/ | grep -q .
314-
# Set the output variable to true if modifications are made to the docs folder
315-
echo "build_docs=$(test $? -eq 0 && echo true || echo false)" >> $GITHUB_ENV
313+
if [ -n "$(git diff --name-only origin/blitz doc/source/)" ]; then
314+
echo "build_docs=true" >> $GITHUB_ENV
315+
else
316+
echo "build_docs=false" >> $GITHUB_ENV
317+
fi
316318
317319
- name: Always run on the blitz branch
318320
if: github.ref == 'refs/heads/blitz'

doc/changelog.d/1808.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
translating sketch issues when using a custom default unit

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from ansys.geometry.core.math.constants import ZERO_POINT2D
3030
from ansys.geometry.core.math.plane import Plane
31-
from ansys.geometry.core.math.point import Point2D
31+
from ansys.geometry.core.math.point import Point2D, Point3D
3232
from ansys.geometry.core.math.vector import UnitVector3D, Vector2D, Vector3D
3333
from ansys.geometry.core.misc.checks import graphics_required
3434
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle, Distance
@@ -121,16 +121,24 @@ def translate_sketch_plane(self, translation: Vector3D) -> "Sketch":
121121
Parameters
122122
----------
123123
translation : Vector3D
124-
Vector defining the translation. Meters is the expected unit.
124+
Vector defining the translation. Default units are the expected
125+
units, otherwise it will be inconsistent.
125126
126127
Returns
127128
-------
128129
Sketch
129130
Revised sketch state ready for further sketch actions.
130131
"""
131-
self.plane = Plane(
132-
self.plane.origin + translation, self.plane.direction_x, self.plane.direction_y
132+
new_origin = Point3D(
133+
[
134+
self.plane.origin.x.m_as(DEFAULT_UNITS.LENGTH) + translation.x,
135+
self.plane.origin.y.m_as(DEFAULT_UNITS.LENGTH) + translation.y,
136+
self.plane.origin.z.m_as(DEFAULT_UNITS.LENGTH) + translation.z,
137+
]
133138
)
139+
# Set the same unit system as the plane origin
140+
new_origin.unit = self.plane.origin.unit
141+
self.plane = Plane(new_origin, self.plane.direction_x, self.plane.direction_y)
134142
return self
135143

136144
@check_input_types

tests/integration/test_issues.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
Point2D,
3434
Point3D,
3535
)
36+
from ansys.geometry.core.math.vector import UnitVector3D
3637
from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Angle, Distance
3738
from ansys.geometry.core.modeler import Modeler
3839
from ansys.geometry.core.sketch import Sketch
@@ -260,3 +261,31 @@ def test_issue_1724_intersect_failures(modeler: Modeler):
260261

261262
# Verify that the volume of the cylinder is the same (the intersect is the same as the cylinder)
262263
assert np.isclose(design.bodies[0].volume.m, np.pi * radius**2 * (wz - 0.1))
264+
265+
266+
def test_issue_1807_translate_sketch_non_default_units():
267+
"""Test that translating a sketch with non-default units is handled properly.
268+
269+
For more info see
270+
https://github.com/ansys/pyansys-geometry/issues/1807
271+
"""
272+
try:
273+
# Set the default units to mm
274+
DEFAULT_UNITS.LENGTH = UNITS.mm
275+
276+
# Draw a box sketch
277+
sketch = Sketch()
278+
sketch.box(Point2D([0, 0]), 10, 10)
279+
280+
# Verify the sketch plane origin
281+
assert sketch.plane.origin == Point3D([0, 0, 0])
282+
283+
# Translate the sketch
284+
sketch.translate_sketch_plane_by_distance(UnitVector3D([0, 0, 1]), Distance(10, UNITS.mm))
285+
286+
# Verify the new sketch plane origin
287+
assert sketch.plane.origin == Point3D([0, 0, 10], unit=UNITS.mm)
288+
289+
finally:
290+
# Reset the default units to meters
291+
DEFAULT_UNITS.LENGTH = UNITS.meter

0 commit comments

Comments
 (0)