MCPcopy Create free account
hub / github.com/cinder/Cinder / calcNormalizedTime

Method calcNormalizedTime

src/cinder/Path2d.cpp:2083–2115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2081}
2082
2083float 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
2117float Path2d::calcTimeForDistance( float distance, bool wrap, float tolerance, int maxIterations ) const
2118{

Callers 3

drawMethod · 0.80
subPathHelperFunction · 0.80
Path2dTest.cppFile · 0.80

Calls 5

fmodFunction · 0.85
absFunction · 0.85
clampFunction · 0.85
emptyMethod · 0.45

Tested by 1

subPathHelperFunction · 0.64