Skip to content

Commit 5199a5f

Browse files
LanceX2214jonahrbRobPasMue
authored
remove some setter methods (#402)
Co-authored-by: jonahrb <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 0e6e388 commit 5199a5f

File tree

7 files changed

+33
-149
lines changed

7 files changed

+33
-149
lines changed

src/ansys/geometry/core/plotting/plotter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def init_plotter(self):
377377
pl = Plotter()
378378
return pl
379379

380-
def show_plotter(self, plotter, screenshot):
380+
def show_plotter(self, plotter: Plotter, screenshot: Optional[str] = None):
381381
"""Shows the plotter or starts Trame service.
382382
383383
Parameters

src/ansys/geometry/core/primitives/circle.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ def origin(self) -> Point3D:
5454
"""Origin of the circle."""
5555
return self._origin
5656

57-
@origin.setter
58-
@check_input_types
59-
def origin(self, origin: Point3D) -> None:
60-
"""Set the origin of the circle."""
61-
self._origin = origin
62-
6357
@property
6458
def radius(self) -> Quantity:
6559
"""Radius of the circle."""

src/ansys/geometry/core/primitives/ellipse.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ def origin(self) -> Point3D:
7676
"""Origin of the ellipse."""
7777
return self._origin
7878

79-
@origin.setter
80-
@check_input_types
81-
def origin(self, origin: Point3D) -> None:
82-
"""Set the origin of the ellipse."""
83-
self._origin = origin
84-
8579
@property
8680
def major_radius(self) -> Quantity:
8781
"""Major radius of the ellipse."""

src/ansys/geometry/core/primitives/line.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,11 @@ def origin(self) -> Point3D:
4040
"""Origin of the line."""
4141
return self._origin
4242

43-
@origin.setter
44-
@check_input_types
45-
def origin(self, origin: Point3D) -> None:
46-
"""Set the origin of the line."""
47-
self._origin = origin
48-
4943
@property
5044
def direction(self) -> UnitVector3D:
5145
"""Direction of the line."""
5246
return self._direction
5347

54-
@direction.setter
55-
@check_input_types
56-
def direction(self, direction: Union[np.ndarray, RealSequence, UnitVector3D, Vector3D]):
57-
"""Set the direction of the line."""
58-
self._direction = (
59-
UnitVector3D(direction) if not isinstance(direction, UnitVector3D) else direction
60-
)
61-
6248
def __eq__(self, other: object) -> bool:
6349
"""Equals operator for the ``Line`` class."""
6450
if isinstance(other, Line):

src/ansys/geometry/core/primitives/sphere.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ def origin(self) -> Point3D:
5555
"""Origin of the sphere."""
5656
return self._origin
5757

58-
@origin.setter
59-
@check_input_types
60-
def origin(self, origin: Point3D) -> None:
61-
"""Set the origin of the sphere."""
62-
self._origin = origin
63-
6458
@property
6559
def radius(self) -> Quantity:
6660
"""Radius of the sphere."""

src/ansys/geometry/core/primitives/torus.py

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Provides the ``Torus`` class."""
22

33
from beartype import beartype as check_input_types
4-
from beartype.typing import Optional, Union
4+
from beartype.typing import Union
55
import numpy as np
6-
from pint import Unit
6+
from pint import Quantity
77

88
from ansys.geometry.core.math import Point3D, UnitVector3D, Vector3D
9-
from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, check_pint_unit_compatibility
9+
from ansys.geometry.core.misc import Distance
1010
from ansys.geometry.core.typing import Real, RealSequence
1111

1212

@@ -22,12 +22,10 @@ class Torus:
2222
X-axis direction.
2323
direction_y : Union[~numpy.ndarray, RealSequence, UnitVector3D, Vector3D]
2424
Y-axis direction.
25-
major_radius : Real
25+
major_radius : Union[Quantity, Distance, Real]
2626
Major radius of the torus.
27-
minor_radius : Real
27+
minor_radius : Union[Quantity, Distance, Real]
2828
Minor radius of ``Torus``.
29-
unit : ~pint.Unit, optional
30-
Units for defining the radius and minor radius. By default, ``DEFAULT_UNITS.LENGTH``
3129
"""
3230

3331
@check_input_types
@@ -36,16 +34,11 @@ def __init__(
3634
origin: Union[np.ndarray, RealSequence, Point3D],
3735
direction_x: Union[np.ndarray, RealSequence, UnitVector3D, Vector3D],
3836
direction_y: Union[np.ndarray, RealSequence, UnitVector3D, Vector3D],
39-
major_radius: Real,
40-
minor_radius: Real,
41-
unit: Optional[Unit] = DEFAULT_UNITS.LENGTH,
37+
major_radius: Union[Quantity, Distance, Real],
38+
minor_radius: Union[Quantity, Distance, Real],
4239
):
4340
"""Constructor method for the ``Torus`` class."""
4441

45-
check_pint_unit_compatibility(unit, DEFAULT_UNITS.LENGTH)
46-
self._unit = unit
47-
_, self._base_unit = UNITS.get_base_units(unit)
48-
4942
self._origin = Point3D(origin) if not isinstance(origin, Point3D) else origin
5043
self._direction_x = (
5144
UnitVector3D(direction_x) if not isinstance(direction_x, UnitVector3D) else direction_x
@@ -55,57 +48,35 @@ def __init__(
5548
)
5649

5750
# Store values in base unit
58-
self._major_radius = UNITS.convert(major_radius, self._unit, self._base_unit)
59-
self._minor_radius = UNITS.convert(minor_radius, self._unit, self._base_unit)
51+
self._major_radius = (
52+
major_radius if isinstance(major_radius, Distance) else Distance(major_radius)
53+
)
54+
self._minor_radius = (
55+
minor_radius if isinstance(minor_radius, Distance) else Distance(minor_radius)
56+
)
6057

6158
@property
6259
def origin(self) -> Point3D:
6360
"""Origin of the torus."""
6461
return self._origin
6562

66-
@origin.setter
67-
@check_input_types
68-
def origin(self, origin: Point3D) -> None:
69-
self._origin = origin
70-
7163
@property
72-
def major_radius(self) -> Real:
64+
def major_radius(self) -> Quantity:
7365
"""Semi-major radius of the torus."""
74-
return UNITS.convert(self._major_radius, self._base_unit, self._unit)
75-
76-
@major_radius.setter
77-
@check_input_types
78-
def major_radius(self, major_radius: Real) -> None:
79-
self._major_radius = UNITS.convert(major_radius, self._unit, self._base_unit)
66+
return self._major_radius.value
8067

8168
@property
82-
def minor_radius(self) -> Real:
69+
def minor_radius(self) -> Quantity:
8370
"""Semi-minor radius of the torus."""
84-
return UNITS.convert(self._minor_radius, self._base_unit, self._unit)
85-
86-
@minor_radius.setter
87-
@check_input_types
88-
def minor_radius(self, minor_radius: Real) -> None:
89-
self._minor_radius = UNITS.convert(minor_radius, self._unit, self._base_unit)
90-
91-
@property
92-
def unit(self) -> Unit:
93-
"""Unit of the semi-major radius and semi-minor radius."""
94-
return self._unit
95-
96-
@unit.setter
97-
@check_input_types
98-
def unit(self, unit: Unit) -> None:
99-
check_pint_unit_compatibility(unit, DEFAULT_UNITS.LENGTH)
100-
self._unit = unit
71+
return self._minor_radius.value
10172

10273
@check_input_types
10374
def __eq__(self, other: object) -> bool:
10475
"""Equals operator for the ``Torus`` class."""
10576
return (
106-
self._origin == other.origin
107-
and self._major_radius == other.major_radius
108-
and self._minor_radius == other.minor_radius
77+
self._origin == other._origin
78+
and self._major_radius == other._major_radius
79+
and self._minor_radius == other._minor_radius
10980
and self._direction_x == other._direction_x
11081
and self._direction_y == other._direction_y
11182
)

tests/test_primitives.py

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
UnitVector3D,
1212
Vector3D,
1313
)
14-
from ansys.geometry.core.misc import UNITS, Accuracy, Distance
14+
from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Accuracy, Distance
1515
from ansys.geometry.core.primitives import (
1616
Circle,
1717
Cone,
@@ -160,21 +160,9 @@ def test_sphere():
160160
assert Accuracy.length_is_equal(s_1.surface_area.m, 1.25663706e5)
161161
assert Accuracy.length_is_equal(s_1.volume.m, 4.1887902e6)
162162

163-
s_1.origin = new_origin = Point3D([42, 88, 99])
164-
165-
assert s_1.origin.x == new_origin.x
166-
assert s_1.origin.y == new_origin.y
167-
assert s_1.origin.z == new_origin.z
168-
169-
s_2.origin = new_origin
170-
assert s_1 == s_2
171-
172163
with pytest.raises(BeartypeCallHintParamViolation):
173164
Sphere(origin, "A")
174165

175-
with pytest.raises(BeartypeCallHintParamViolation):
176-
s_1.origin = "A"
177-
178166

179167
def test_sphere_units():
180168
"""``Sphere`` units validation."""
@@ -401,40 +389,15 @@ def test_torus():
401389
assert t_1.origin.x == origin.x
402390
assert t_1.origin.y == origin.y
403391
assert t_1.origin.z == origin.z
404-
assert t_1.major_radius == major_radius
405-
assert t_1.minor_radius == minor_radius
406-
407-
t_1.major_radius = new_major_radius = 2000
408-
t_1.minor_radius = new_minor_radius = 1000
409-
410-
assert t_1.origin.x == origin.x
411-
assert t_1.origin.y == origin.y
412-
assert t_1.origin.z == origin.z
413-
assert t_1.major_radius == new_major_radius
414-
assert t_1.minor_radius == new_minor_radius
415-
416-
t_1.origin = new_origin = Point3D([42, 88, 99])
417-
assert t_1.origin.x == new_origin.x
418-
assert t_1.origin.y == new_origin.y
419-
assert t_1.origin.z == new_origin.z
420-
assert t_1.major_radius == new_major_radius
421-
assert t_1.minor_radius == new_minor_radius
392+
assert t_1.major_radius == major_radius * DEFAULT_UNITS.LENGTH
393+
assert t_1.minor_radius == minor_radius * DEFAULT_UNITS.LENGTH
422394

423395
with pytest.raises(BeartypeCallHintParamViolation):
424396
Torus(origin, UnitVector3D([12, 31, 99]), UnitVector3D([25, 39, 82]), "A", 200)
425397

426398
with pytest.raises(BeartypeCallHintParamViolation):
427399
Torus(origin, UnitVector3D([12, 31, 99]), UnitVector3D([25, 39, 82]), 100, "A")
428400

429-
with pytest.raises(BeartypeCallHintParamViolation):
430-
t_1.major_radius = "A"
431-
432-
with pytest.raises(BeartypeCallHintParamViolation):
433-
t_1.minor_radius = "A"
434-
435-
with pytest.raises(BeartypeCallHintParamViolation):
436-
t_1.origin = "A"
437-
438401
with pytest.raises(BeartypeCallHintParamViolation):
439402
Torus(origin, "A", UnitVector3D([25, 39, 82]), 100, 200)
440403

@@ -459,43 +422,25 @@ def test_torus_units():
459422
origin,
460423
UnitVector3D([12, 31, 99]),
461424
UnitVector3D([25, 39, 82]),
462-
major_radius,
463-
minor_radius,
464-
UNITS.celsius,
425+
Quantity(major_radius, UNITS.celsius),
426+
Quantity(minor_radius, UNITS.celsius),
465427
)
466428

467429
t_1 = Torus(
468430
origin,
469431
UnitVector3D([12, 31, 99]),
470432
UnitVector3D([25, 39, 82]),
471-
major_radius,
472-
minor_radius,
473-
unit,
433+
Quantity(major_radius, unit),
434+
Quantity(minor_radius, unit),
474435
)
475436

476-
# Verify rejection of invalid base unit type
477-
with pytest.raises(
478-
TypeError,
479-
match=r"The pint.Unit provided as an input should be a \[length\] quantity.",
480-
):
481-
t_1.unit = UNITS.celsius
482-
483437
# Check that the units are correctly in place
484-
assert t_1.unit == unit
438+
assert t_1.major_radius.u == unit
439+
assert t_1.minor_radius.u == unit
485440

486-
# Request for radius/height and ensure they are in mm
487-
assert t_1.major_radius == major_radius
488-
assert t_1.minor_radius == minor_radius
489-
490-
# Check that the actual values are in base units (i.e. DEFAULT_UNITS.LENGTH)
491-
assert t_1._major_radius == (t_1.major_radius * t_1.unit).to_base_units().magnitude
492-
assert t_1._minor_radius == (t_1.minor_radius * t_1.unit).to_base_units().magnitude
493-
494-
# Set unit to cm now... and check if the values changed
495-
t_1.unit = new_unit = UNITS.cm
496-
assert t_1.major_radius == UNITS.convert(major_radius, unit, new_unit)
497-
assert t_1.minor_radius == UNITS.convert(minor_radius, unit, new_unit)
498-
assert t_1.unit == new_unit
441+
# Request for radii and ensure they are in mm
442+
assert t_1.major_radius.m == major_radius
443+
assert t_1.minor_radius.m == minor_radius
499444

500445

501446
def test_circle():

0 commit comments

Comments
 (0)