Skip to content

Commit

Permalink
Merge pull request #23 from tichise/feature/error-bugfix
Browse files Browse the repository at this point in the history
Double.piを使ってビルドしたらエラーが出たので、直書きに修正する
  • Loading branch information
tichise authored Mar 5, 2024
2 parents a4fd6f2 + b197cfe commit d126e4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Sources/BigRing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion Sources/CGPoint+Joystick.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d126e4b

Please sign in to comment.