Search code examples
scaleperformancepinch

how can i make this equation faster


right now i have a bottle neck in my program I'm trying to write. i am trying to use a pinch gesture to control the scale of a UIImage. its the calculation of the scale that is causing the program to slow down and become choppy. below is the equation.

currentScale = (currentDistance / initialDistance) * scaleMod;

scaleMod is what ever the current scale was the user took their fingers off the screen. so the next time the user does a pinch the old scale is essentially the starting point of the new scaling action.


Solution

  • 1) Can't you calculate scaleMod / initialDistance once while currentDistance is changing. That way you only have do that value times currentDistance, which removes a divide.

    2) Make sure that this is actually the bottleneck. It most likely isn't, unless your doing something really wrong.