| 53 | } |
| 54 | |
| 55 | float VInterpolator::GetTForX(float aX) const |
| 56 | { |
| 57 | // Find interval where t lies |
| 58 | float intervalStart = 0.0; |
| 59 | const float* currentSample = &mSampleValues[1]; |
| 60 | const float* const lastSample = &mSampleValues[kSplineTableSize - 1]; |
| 61 | for (; currentSample != lastSample && *currentSample <= aX; |
| 62 | ++currentSample) { |
| 63 | intervalStart += kSampleStepSize; |
| 64 | } |
| 65 | --currentSample; // t now lies between *currentSample and *currentSample+1 |
| 66 | |
| 67 | // Interpolate to provide an initial guess for t |
| 68 | float dist = |
| 69 | (aX - *currentSample) / (*(currentSample + 1) - *currentSample); |
| 70 | float guessForT = intervalStart + dist * kSampleStepSize; |
| 71 | |
| 72 | // Check the slope to see what strategy to use. If the slope is too small |
| 73 | // Newton-Raphson iteration won't converge on a root so we use bisection |
| 74 | // instead. |
| 75 | float initialSlope = GetSlope(guessForT, mX1, mX2); |
| 76 | if (initialSlope >= NEWTON_MIN_SLOPE) { |
| 77 | return NewtonRaphsonIterate(aX, guessForT); |
| 78 | } else if (initialSlope == 0.0) { |
| 79 | return guessForT; |
| 80 | } else { |
| 81 | return BinarySubdivide(aX, intervalStart, |
| 82 | intervalStart + kSampleStepSize); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | float VInterpolator::NewtonRaphsonIterate(float aX, float aGuessT) const |
| 87 | { |
nothing calls this directly
no outgoing calls
no test coverage detected