Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN error when touch point is the same as the centre of the circle. #1

Open
mikemonteith opened this issue Feb 4, 2015 · 1 comment

Comments

@mikemonteith
Copy link

If the user's drag coordinate is at the centre of the CircularSlider, a crash occurs because of a "divide by zero" issue.

@behrad-kzm
Copy link

in function moveHandle() :

    func moveHandle(lastPoint:CGPoint){       
       //Get the center
        let centerPoint:CGPoint  = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
        //Calculate the direction from a center point and a arbitrary position.
       //bug fix:
        var currentAngle:Double = AngleFromNorth(centerPoint, p2: lastPoint, flipped: false);
      if currentAngle.isNaN {
        currentAngle = 0
      }
        let angleInt = Int(floor(currentAngle))

        //Store the new angle
        angle = Int(360 - angleInt)

        //Update the textfield
        textField!.text = "\(angle)"

        //Redraw
        setNeedsDisplay()

    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants