Skip to content

Commit c43908e

Browse files
committed
Fix arc on WinUIBackend
1 parent 4b3bec1 commit c43908e

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

Examples/Sources/PathsExample/PathsApp.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ struct ArcShape: StyledShape {
1212
let strokeStyle: StrokeStyle? = StrokeStyle(width: 5.0)
1313

1414
func path(in bounds: Path.Rect) -> Path {
15-
let radius = min(bounds.width, bounds.height) / 2.0 - 2.5
16-
17-
return Path()
18-
.move(to: bounds.center + radius * SIMD2(x: cos(startAngle), y: sin(startAngle)))
15+
Path()
1916
.addArc(
2017
center: bounds.center,
21-
radius: radius,
18+
radius: min(bounds.width, bounds.height) / 2.0 - 2.5,
2219
startAngle: startAngle,
2320
endAngle: endAngle,
2421
clockwise: clockwise

Sources/SwiftCrossUI/Path.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,6 @@ public struct Path {
267267
}
268268

269269
/// Add an arc segment to the path.
270-
///
271-
/// The behavior is not defined if the starting point is not what is implied by `center`,
272-
/// `radius`, and `startAngle`. Some backends (such as UIKit) will add a line segment
273-
/// to connect the arc to the starting point, while others (such as WinUI) will move the
274-
/// arc in unintuitive ways. If this arc is the first segment of the current path, or
275-
/// the previous segment was a rectangle or circle, be sure to call ``move(to:)`` before
276-
/// this.
277270
/// - Parameters:
278271
/// - center: The location of the center of the circle.
279272
/// - radius: The radius of the circle.

Sources/WinUIBackend/WinUIBackend.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,10 @@ public final class WinUIBackend: AppBackend {
12931293
let endAngle,
12941294
let clockwise
12951295
):
1296+
let startPoint = Point(
1297+
x: Float(center.x + radius * cos(startAngle)),
1298+
y: Float(center.y + radius * sin(startAngle))
1299+
)
12961300
let endPoint = Point(
12971301
x: Float(center.x + radius * cos(endAngle)),
12981302
y: Float(center.y + radius * sin(endAngle))
@@ -1301,6 +1305,16 @@ public final class WinUIBackend: AppBackend {
13011305

13021306
let figure = requirePathFigure(geometry, lastPoint: lastPoint)
13031307

1308+
if startPoint != lastPoint {
1309+
if figure.segments.size > 0 {
1310+
let connector = LineSegment()
1311+
connector.point = startPoint
1312+
figure.segments.append(connector)
1313+
} else {
1314+
figure.startPoint = startPoint
1315+
}
1316+
}
1317+
13041318
let segment = ArcSegment()
13051319

13061320
if clockwise {

0 commit comments

Comments
 (0)