BWCircularSlider icon indicating copy to clipboard operation
BWCircularSlider copied to clipboard

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

Open mikemonteith opened this issue 10 years ago • 1 comments

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

mikemonteith avatar Feb 04 '15 11:02 mikemonteith

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()

    }

behrad-kzm avatar Apr 07 '16 08:04 behrad-kzm