Skip to content

Commit 4218849

Browse files
authored
Merge pull request #15 from spacenation/compiler-complexity-error-fix
Compiler complexity error fix
2 parents 66864cd + 691ff77 commit 4218849

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

Sources/Shapes/RoundedStarPolygons/RoundedStarPolygon.swift

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,43 @@ extension Path {
4545
var usableConvexRadius: CGFloat = .zero
4646
var usableConcaveRadius: CGFloat = .zero
4747

48+
func getPoint(from centerPoint: CGPoint, angle: Double, hypotenuse: Double) -> CGPoint {
49+
CGPoint(
50+
x: centerPoint.x + CGFloat(cos(angle) * hypotenuse),
51+
y: centerPoint.y + CGFloat(sin(angle) * hypotenuse)
52+
)
53+
}
54+
55+
func getViaPoint(from centerPoint: CGPoint, angle: Double, hypotenuse: Double, smoothness: CGFloat) -> CGPoint {
56+
CGPoint(
57+
x: centerPoint.x + CGFloat(cos(angle) * hypotenuse * smoothness),
58+
y: centerPoint.y + CGFloat(sin(angle) * hypotenuse * smoothness)
59+
)
60+
}
61+
62+
func getLastPoint(from centerPoint: CGPoint, angle: Double, hypotenuse: Double, smoothness: CGFloat) -> CGPoint {
63+
CGPoint(
64+
x: centerPoint.x + CGFloat(cos(angle) * hypotenuse * smoothness),
65+
y: centerPoint.y + CGFloat(sin(angle) * hypotenuse * smoothness)
66+
)
67+
}
68+
4869
return Path { path in
49-
(0..<points).forEach { index in
50-
let angle = ((Double(index * 2) * (360.0 / Double(sides))) - 90) * Double.pi / 180
70+
for index in 0 ..< points {
71+
let angle: Double = ((Double(index * 2) * (360.0 / Double(sides))) - 90) * Double.pi / 180
5172

52-
let point = CGPoint(
53-
x: centerPoint.x + CGFloat(cos(angle) * hypotenuse),
54-
y: centerPoint.y + CGFloat(sin(angle) * hypotenuse)
55-
)
73+
let point: CGPoint = getPoint(from: centerPoint, angle: angle, hypotenuse: hypotenuse)
5674

57-
let viaAngle = ((Double(index * 2 + 1) * (360.0 / Double(sides))) - 90) * Double.pi / 180
75+
let viaAngle: Double = ((Double(index * 2 + 1) * (360.0 / Double(sides))) - 90) * Double.pi / 180
5876

59-
let viaPoint = CGPoint(
60-
x: centerPoint.x + CGFloat(cos(viaAngle) * hypotenuse * smoothness),
61-
y: centerPoint.y + CGFloat(sin(viaAngle) * hypotenuse * smoothness)
62-
)
77+
let viaPoint: CGPoint = getViaPoint(from: centerPoint, angle: viaAngle, hypotenuse: hypotenuse, smoothness: smoothness)
6378

64-
let sideLength = sqrt((point.x - viaPoint.x) * (point.x - viaPoint.x) + (point.y - viaPoint.y) * (point.y - viaPoint.y))
65-
let inradius = sideLength / (2 * tan(.pi / CGFloat(points * 2)))
79+
let px: CGFloat = point.x - viaPoint.x
80+
let py: CGFloat = point.y - viaPoint.y
81+
82+
let sideLength: CGFloat = sqrt(px * px + py * py)
83+
84+
let inradius: CGFloat = sideLength / (2 * tan(.pi / CGFloat(points * 2)))
6685

6786
if usableConvexRadius == 0 {
6887
usableConvexRadius = min(convexRadius, inradius)
@@ -72,19 +91,16 @@ extension Path {
7291
usableConcaveRadius = min(concaveRadius, inradius - convexRadius)
7392
}
7493

75-
let nextAngle = ((Double(index * 2 + 2) * (360.0 / Double(sides))) - 90) * Double.pi / 180
94+
let nextAngle: Double = ((Double(index * 2 + 2) * (360.0 / Double(sides))) - 90) * Double.pi / 180
7695

7796
let nextPoint = CGPoint(
7897
x: centerPoint.x + CGFloat(cos(nextAngle) * hypotenuse),
7998
y: centerPoint.y + CGFloat(sin(nextAngle) * hypotenuse)
8099
)
81100

82-
let lastAngle = ((Double(index * 2 + 3) * (360.0 / Double(sides))) - 90) * Double.pi / 180
101+
let lastAngle: Double = ((Double(index * 2 + 3) * (360.0 / Double(sides))) - 90) * Double.pi / 180
83102

84-
let lastPoint = CGPoint(
85-
x: centerPoint.x + CGFloat(cos(lastAngle) * hypotenuse * smoothness),
86-
y: centerPoint.y + CGFloat(sin(lastAngle) * hypotenuse * smoothness)
87-
)
103+
let lastPoint: CGPoint = getLastPoint(from: centerPoint, angle: lastAngle, hypotenuse: hypotenuse, smoothness: smoothness)
88104

89105
path.addCircularCornerRadiusArc(from: point, via: viaPoint, to: nextPoint, radius: -usableConcaveRadius, clockwise: true)
90106

0 commit comments

Comments
 (0)