Get the direction of the curve at a specific index (increasing or decreasing)
| 290 | |
| 291 | // Get the direction of the curve at a specific index (increasing or decreasing) |
| 292 | bool Keyframe::IsIncreasing(int index) const |
| 293 | { |
| 294 | if (index <= 1) { |
| 295 | // Determine direction of frame 1 (and assume previous frames have same direction) |
| 296 | index = 1; |
| 297 | } else if (index >= GetLength()) { |
| 298 | // Determine direction of last valid frame # (and assume next frames have same direction) |
| 299 | index = GetLength() - 1; |
| 300 | } |
| 301 | |
| 302 | // Get current index value |
| 303 | const double current_value = GetValue(index); |
| 304 | |
| 305 | // Iterate from current index to next significant value change |
| 306 | int attempts = 1; |
| 307 | while (attempts < 600 && index + attempts <= GetLength()) { |
| 308 | // Get next value |
| 309 | const double next_value = GetValue(index + attempts); |
| 310 | |
| 311 | // Is value significantly different |
| 312 | const double diff = next_value - current_value; |
| 313 | if (fabs(diff) > 0.0001) { |
| 314 | if (diff < 0.0) { |
| 315 | // Decreasing value found next |
| 316 | return false; |
| 317 | } else { |
| 318 | // Increasing value found next |
| 319 | return true; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // increment attempt |
| 324 | attempts++; |
| 325 | } |
| 326 | |
| 327 | // If no next value found, assume increasing values |
| 328 | return true; |
| 329 | } |
| 330 | |
| 331 | // Generate JSON string of this object |
| 332 | std::string Keyframe::Json() const { |
no outgoing calls
no test coverage detected