From b197cfe39178d961764e8dc7ddbefd1db40eabf7 Mon Sep 17 00:00:00 2001 From: tichise <43707+tichise@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:21:28 +0900 Subject: [PATCH] =?UTF-8?q?Double.pi=E3=82=92=E4=BD=BF=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=83=93=E3=83=AB=E3=83=89=E3=81=97=E3=81=9F=E3=82=89=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=8C=E5=87=BA=E3=81=9F=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E3=80=81=E7=9B=B4=E6=9B=B8=E3=81=8D=E3=81=AB=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/BigRing.swift | 7 +++++-- Sources/CGPoint+Joystick.swift | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/BigRing.swift b/Sources/BigRing.swift index 8da6369..397efc8 100644 --- a/Sources/BigRing.swift +++ b/Sources/BigRing.swift @@ -19,6 +19,9 @@ struct BigRing: View { var bigRingDiameter: CGFloat + // 円周率を直接記述する + private let piValue: Double = 3.14159265358979 + var body: some View { ZStack { Circle().stroke(bigRingStrokeColor, lineWidth: 10) @@ -31,12 +34,12 @@ struct BigRing: View { let radius = min(bigRingDiameter, bigRingDiameter) / 2 let center = CGPoint(x: bigRingDiameter / 2, y: bigRingDiameter / 2) - let additionalAngle = Double.pi / 8 // 線の開始位置を調整 + let additionalAngle = piValue / 8 // 線の開始位置を調整 ForEach(0..<8) { i in Path { path in path.move(to: center) - let angle = CGFloat(i) * .pi / 4 + additionalAngle + let angle = CGFloat(i) * piValue / 4 + additionalAngle let endX = center.x + radius * cos(angle) let endY = center.y + radius * sin(angle) path.addLine(to: CGPoint(x: endX, y: endY)) diff --git a/Sources/CGPoint+Joystick.swift b/Sources/CGPoint+Joystick.swift index 5a62de9..c20ae27 100644 --- a/Sources/CGPoint+Joystick.swift +++ b/Sources/CGPoint+Joystick.swift @@ -20,12 +20,15 @@ extension CGPoint { /// Get radian from point on circle func getRadian(pointOnCircle: CGPoint) -> CGFloat { + // 円周率を直接記述する + let piValue: Double = 3.14159265358979 + let originX = pointOnCircle.x - self.x let originY = pointOnCircle.y - self.y var radian = atan2(originY, originX) while radian < 0 { - radian += CGFloat(2 * Double.pi) + radian += CGFloat(2 * piValue) } return radian