Skip to content

Commit 4e7c2ea

Browse files
RobPasMuepyansys-ci-botPipKat
authored
fix: adapting Arc class constructor order to (start, end, center) (#1196)
Co-authored-by: pyansys-ci-bot <pyansys.github.bot@ansys.com> Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>
1 parent a8117bc commit 4e7c2ea

File tree

8 files changed

+44
-30
lines changed

8 files changed

+44
-30
lines changed

doc/changelog.d/1196.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: adapting ``Arc`` class constructor order to (start, end, center)

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class Arc(SketchEdge):
4040
4141
Parameters
4242
----------
43-
center : Point2D
44-
Center point of the arc.
4543
start : Point2D
4644
Starting point of the arc.
4745
end : Point2D
4846
Ending point of the arc.
47+
center : Point2D
48+
Center point of the arc.
4949
clockwise : bool, default: False
5050
Whether the arc spans the clockwise angle between the start and end points.
5151
When ``False`` (default), the arc spans the counter-clockwise angle. When
@@ -55,9 +55,9 @@ class Arc(SketchEdge):
5555
@check_input_types
5656
def __init__(
5757
self,
58-
center: Point2D,
5958
start: Point2D,
6059
end: Point2D,
60+
center: Point2D,
6161
clockwise: Optional[bool] = False,
6262
):
6363
"""Initialize the arc shape."""
@@ -78,7 +78,7 @@ def __init__(
7878
)
7979

8080
# Store the main three points of the arc
81-
self._center, self._start, self._end = center, start, end
81+
self._start, self._end, self._center = start, end, center
8282

8383
# Compute the vectors from the center to the start and end points
8484
to_start_vector = Vector2D.from_points(start, center)
@@ -107,6 +107,11 @@ def end(self) -> Point2D:
107107
"""Ending point of the arc line."""
108108
return self._end
109109

110+
@property
111+
def center(self) -> Point2D:
112+
"""Center point of the arc."""
113+
return self._center
114+
110115
@property
111116
def length(self) -> Quantity:
112117
"""Length of the arc."""
@@ -117,11 +122,6 @@ def radius(self) -> Quantity:
117122
"""Radius of the arc."""
118123
return self._radius
119124

120-
@property
121-
def center(self) -> Point2D:
122-
"""Center point of the arc."""
123-
return self._center
124-
125125
@property
126126
def angle(self) -> Quantity:
127127
"""Angle of the arc."""
@@ -341,4 +341,4 @@ def from_three_points(cls, start: Point2D, inter: Point2D, end: Point2D):
341341
is_clockwise = False if angle_s_i < angle_s_e else True
342342

343343
# Finally... you can create the arc
344-
return Arc(center=center, start=start, end=end, clockwise=is_clockwise)
344+
return Arc(start=start, end=end, center=center, clockwise=is_clockwise)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ def __init__(
142142
# Now, proceed to draw the arcs and segments
143143
# TODO: add plane to SketchSegment when available
144144
self._edges.append(
145-
Arc(center=origin, start=outer_arc_start + origin, end=outer_arc_end + origin)
145+
Arc(start=outer_arc_start + origin, end=outer_arc_end + origin, center=origin)
146146
)
147147
self._edges.append(
148148
SketchSegment(start=outer_arc_end + origin, end=inner_arc_start + origin)
149149
)
150150
self._edges.append(
151-
Arc(center=origin, start=inner_arc_start + origin, end=inner_arc_end + origin)
151+
Arc(start=inner_arc_start + origin, end=inner_arc_end + origin, center=origin)
152152
)
153153
self._edges.append(
154154
SketchSegment(start=inner_arc_end + origin, end=next_outer_arc_start + origin)
@@ -513,19 +513,19 @@ def _generate_arcs(
513513
# needed values from the preliminary arc
514514
arcs.append(
515515
Arc(
516-
center=preliminary_arc.center,
517516
start=points[idx],
518517
end=points[idx + 1],
518+
center=preliminary_arc.center,
519519
clockwise=preliminary_arc.is_clockwise,
520520
)
521521
)
522522

523523
# Once the loop has finished... extend the last arc
524524
arcs.append(
525525
Arc(
526-
center=preliminary_arc.center,
527526
start=points[-2],
528527
end=points[-1],
528+
center=preliminary_arc.center,
529529
clockwise=preliminary_arc.is_clockwise,
530530
)
531531
)
@@ -537,9 +537,9 @@ def _generate_arcs(
537537
# Just in case, let us only take the first and last elements of the given list
538538
arcs.append(
539539
Arc(
540-
center=self.origin,
541540
start=points[0],
542541
end=points[-1],
542+
center=self.origin,
543543
)
544544
)
545545

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def arc(
414414
Sketch
415415
Revised sketch state ready for further sketch actions.
416416
"""
417-
arc = Arc(center, start, end, clockwise)
417+
arc = Arc(start, end, center, clockwise)
418418
return self.edge(arc, tag)
419419

420420
@check_input_types
@@ -453,7 +453,7 @@ def arc_to_point(
453453
of the sketch, such as the end point of a previously added edge.
454454
"""
455455
start = self._single_point_context_reference()
456-
arc = Arc(center, start, end, clockwise)
456+
arc = Arc(start, end, center, clockwise)
457457
return self.edge(arc, tag)
458458

459459
def arc_from_three_points(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def __init__(
120120
)
121121

122122
# TODO: add plane to SketchSegment when available
123-
self._arc1 = Arc(self._arc_1_center, self._slot_corner_1, self._slot_corner_2)
123+
self._arc1 = Arc(self._slot_corner_1, self._slot_corner_2, self._arc_1_center)
124124
self._segment1 = SketchSegment(self._slot_corner_2, self._slot_corner_3)
125-
self._arc2 = Arc(self._arc_2_center, self._slot_corner_3, self._slot_corner_4)
125+
self._arc2 = Arc(self._slot_corner_3, self._slot_corner_4, self._arc_2_center)
126126
self._segment2 = SketchSegment(self._slot_corner_4, self._slot_corner_1)
127127

128128
self._edges.append(self._arc1)

tests/integration/test_plotter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def test_visualization_polydata():
563563
assert polygon.visualization_polydata.n_open_edges == 5
564564

565565
# Test for arc visualization polydata
566-
arc = Arc(Point2D([10, 0]), Point2D([10, 10]), Point2D([10, -10]))
566+
arc = Arc(Point2D([10, 10]), Point2D([10, -10]), Point2D([10, 0]))
567567
assert arc.visualization_polydata.center == ([5.0, 0.0, 0.0])
568568
assert arc.visualization_polydata.bounds == pytest.approx([0.0, 10.0, -10.0, 10.0, 0.0, 0.0])
569569
assert arc.visualization_polydata.n_faces == 2

tests/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ def test_arc_message_conversion():
209209
"""Test conversion between :class:`Arc <ansys.geometry.core.sketch.arc.Arc>` and
210210
expected gRPC message type."""
211211
arc = Arc(
212-
Point2D([500, 600], UNITS.mm),
213212
Point2D([100, 400], UNITS.mm),
214213
Point2D([900, 800], UNITS.mm),
214+
Point2D([500, 600], UNITS.mm),
215215
)
216216
grpc_arc_message = sketch_arc_to_grpc_arc(arc, Plane(Point3D([10, 100, 1000], UNITS.mm)))
217217

@@ -232,9 +232,9 @@ def test_arc_message_conversion():
232232
assert grpc_arc_message.axis.z == 1
233233

234234
arc2 = Arc(
235-
Point2D([600, 700], UNITS.mm),
236235
Point2D([200, 500], UNITS.mm),
237236
Point2D([1000, 900], UNITS.mm),
237+
Point2D([600, 700], UNITS.mm),
238238
True,
239239
)
240240
grpc_arc_message2 = sketch_arc_to_grpc_arc(arc2, Plane(Point3D([10, 100, 1000], UNITS.mm)))

tests/test_sketch.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -700,20 +700,20 @@ def test_arc():
700700
point_0_m5 = Point2D([0, -5])
701701

702702
with pytest.raises(ValueError, match="Start and end points must be different."):
703-
Arc(point_0_0, point_0_5, point_0_5)
703+
Arc(point_0_5, point_0_5, point_0_0)
704704

705705
with pytest.raises(ValueError, match="Center and start points must be different."):
706-
Arc(point_0_0, point_0_0, point_5_0)
706+
Arc(point_0_0, point_5_0, point_0_0)
707707

708708
with pytest.raises(ValueError, match="Center and end points must be different."):
709-
Arc(point_0_0, point_0_5, point_0_0)
709+
Arc(point_0_5, point_0_0, point_0_0)
710710

711711
with pytest.raises(ValueError, match="The start and end points of the arc are not"):
712-
Arc(point_0_0, point_0_5, point_6_0)
712+
Arc(point_0_5, point_6_0, point_0_0)
713713

714714
# Let's create a simple arc
715-
arc = Arc(point_0_0, point_0_5, point_5_0)
716-
arc_2 = Arc(point_0_0, point_0_5, point_5_0)
715+
arc = Arc(point_0_5, point_5_0, point_0_0)
716+
arc_2 = Arc(point_0_5, point_5_0, point_0_0)
717717
assert arc == arc_2
718718
assert not (arc != arc_2)
719719

@@ -734,7 +734,7 @@ def test_arc():
734734
# Validate the PyVista hack for generating the PolyData
735735
#
736736
# Needed : 180º arc, counterclockwise
737-
arc_180 = Arc(point_0_0, point_0_5, point_0_m5, clockwise=False)
737+
arc_180 = Arc(point_0_5, point_0_m5, point_0_0, clockwise=False)
738738
pd = arc_180.visualization_polydata
739739

740740
# Since the arc is counterclockwise, all X values should be <=0
@@ -744,7 +744,7 @@ def test_arc():
744744
# Validate the PyVista hack for generating the PolyData
745745
#
746746
# Needed : 180º arc, clockwise
747-
arc_180 = Arc(point_0_0, point_0_5, point_0_m5, clockwise=True)
747+
arc_180 = Arc(point_0_5, point_0_m5, point_0_0, clockwise=True)
748748
pd = arc_180.visualization_polydata
749749

750750
# Since the arc is clockwise, all X values should be >=0
@@ -792,3 +792,16 @@ def test_polydata_methods():
792792
assert len(pd) == 2
793793
assert len(pd_edges) == 1
794794
assert len(pd_faces) == 1
795+
796+
797+
def test_sketch_pyconus2024_voglster_issue1195():
798+
"""Test sketching unexpected behavior observed in PyConUS 2024 by @voglster."""
799+
800+
sketch = Sketch()
801+
p_start, p_end, p_center = Point2D([1, 0]), Point2D([-1, 0]), Point2D([0, 0])
802+
sketch.arc(p_start, p_end, p_center)
803+
804+
# Check that the arc is correctly defined
805+
assert sketch.edges[0].start == p_start
806+
assert sketch.edges[0].end == p_end
807+
assert sketch.edges[0].center == p_center

0 commit comments

Comments
 (0)