| 2081 | } |
| 2082 | |
| 2083 | float Path2d::calcNormalizedTime( float relativeTime, bool wrap, float tolerance, int maxIterations ) const |
| 2084 | { |
| 2085 | if( mSegments.empty() ) |
| 2086 | return 0; |
| 2087 | |
| 2088 | // Wrap relative time if necessary |
| 2089 | if( relativeTime >= 1 ) { |
| 2090 | if( wrap ) |
| 2091 | relativeTime = math<float>::fmod( relativeTime, 1.0f ); |
| 2092 | else |
| 2093 | return 1.0f; |
| 2094 | } |
| 2095 | else if( relativeTime < 0 ) { |
| 2096 | if( wrap ) |
| 2097 | relativeTime = 1.0f - math<float>::fmod( math<float>::abs( relativeTime ), 1.0f ); |
| 2098 | else |
| 2099 | return 0.0f; |
| 2100 | } |
| 2101 | |
| 2102 | float targetLength = calcLength() * math<float>::clamp( relativeTime, 0.0f, 1.0f ); |
| 2103 | // test for 0-length Path2d |
| 2104 | if( targetLength < 0.0001f ) |
| 2105 | return 0; |
| 2106 | |
| 2107 | int currentSegment = 0; |
| 2108 | float currentSegmentLength = calcSegmentLength( 0 ); |
| 2109 | while( targetLength > currentSegmentLength ) { |
| 2110 | targetLength -= currentSegmentLength; |
| 2111 | currentSegmentLength = calcSegmentLength( ++currentSegment ); |
| 2112 | } |
| 2113 | |
| 2114 | return segmentSolveTimeForDistance( currentSegment, currentSegmentLength, targetLength, tolerance, maxIterations ); |
| 2115 | } |
| 2116 | |
| 2117 | float Path2d::calcTimeForDistance( float distance, bool wrap, float tolerance, int maxIterations ) const |
| 2118 | { |