Skip to content

Commit

Permalink
Merge pull request #4 from tichise/fix
Browse files Browse the repository at this point in the history
Fixed variable names, radian and angle are reversed
  • Loading branch information
tichise authored Sep 22, 2020
2 parents bb423bb + 970bfc2 commit ef10637
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion OMJoystick.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'OMJoystick'
s.version = '0.6.0'
s.version = '0.6.1'
s.swift_versions = '5.0'
s.license = 'MIT'
s.summary = 'This is the Joystick UI library for SwiftUI.'
Expand Down
18 changes: 9 additions & 9 deletions Sources/CGPoint+Joystick.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ import UIKit

extension CGPoint {

func pointOnCircle(radius: CGFloat, angle: CGFloat) -> CGPoint {
let x = self.x + radius * cos(angle)
let y = self.y + radius * sin(angle)
func getPointOnCircle(radius: CGFloat, radian: CGFloat) -> CGPoint {
let x = self.x + radius * cos(radian)
let y = self.y + radius * sin(radian)

return CGPoint(x: x, y: y)
}

func angleToPoint(pointOnCircle: CGPoint) -> CGFloat {
func getRadian(pointOnCircle: CGPoint) -> CGFloat {

let originX = pointOnCircle.x - self.x
let originY = pointOnCircle.y - self.y
var radians = atan2(originY, originX)
var radian = atan2(originY, originX)

while radians < 0 {
radians += CGFloat(2 * Double.pi)
while radian < 0 {
radian += CGFloat(2 * Double.pi)
}

return radians
return radian
}

func distanceToPoint(otherPoint: CGPoint) -> CGFloat {
func getDistance(otherPoint: CGPoint) -> CGFloat {
return sqrt(pow((otherPoint.x - x), 2) + pow((otherPoint.y - y), 2))
}
}
6 changes: 3 additions & 3 deletions Sources/OMJoyStick.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public struct OMJoystick: View {
// minimumDistanceが1以上だとタッチイベントを一切拾わない
DragGesture(minimumDistance: 0)
.onChanged{ value in
let distance = self.org.distanceToPoint(otherPoint: value.location)
let distance = self.org.getDistance(otherPoint: value.location)

let smallRingLimitCenter: CGFloat = self.bigRingRadius - self.smallRingRadius

Expand All @@ -173,9 +173,9 @@ public struct OMJoystick: View {

} else {
// 円の範囲外の場合は
let angle = self.org.angleToPoint(pointOnCircle: value.location)
let radian = self.org.getRadian(pointOnCircle: value.location)

let pointOnCircle = self.org.pointOnCircle(radius: smallRingLimitCenter, angle: angle)
let pointOnCircle = self.org.getPointOnCircle(radius: smallRingLimitCenter, radian: radian)

self.locationX = pointOnCircle.x
self.locationY = pointOnCircle.y
Expand Down

0 comments on commit ef10637

Please sign in to comment.