MCPcopy
hub / github.com/greensock/GSAP / getPositionOnPath

Function getPositionOnPath

esm/utils/paths.js:656–712  ·  view source on GitHub ↗
(rawPath, progress, includeAngle, point)

Source from the content-addressed store, hash-verified

654}
655
656export function getPositionOnPath(rawPath, progress, includeAngle, point) {
657 var segment = rawPath[0],
658 result = point || {},
659 samples,
660 resolution,
661 length,
662 min,
663 max,
664 i,
665 t,
666 a,
667 inv;
668
669 if (progress < 0 || progress > 1) {
670 progress = _wrapProgress(progress);
671 }
672
673 segment.lookup || cacheRawPathMeasurements(rawPath);
674
675 if (rawPath.length > 1) {
676 //speed optimization: most of the time, there's only one segment so skip the recursion.
677 length = rawPath.totalLength * progress;
678 max = i = 0;
679
680 while ((max += rawPath[i++].totalLength) < length) {
681 segment = rawPath[i];
682 }
683
684 min = max - segment.totalLength;
685 progress = (length - min) / (max - min) || 0;
686 }
687
688 samples = segment.samples;
689 resolution = segment.resolution;
690 length = segment.totalLength * progress;
691 i = segment.lookup.length ? segment.lookup[progress < 1 ? ~~(length / segment.minLength) : segment.lookup.length - 1] || 0 : _getSampleIndex(samples, length, progress);
692 min = i ? samples[i - 1] : 0;
693 max = samples[i];
694
695 if (max < length) {
696 min = max;
697 max = samples[++i];
698 }
699
700 t = 1 / resolution * ((length - min) / (max - min) + i % resolution) || 0;
701 inv = 1 - t;
702 i = ~~(i / resolution) * 6;
703 a = segment[i];
704 result.x = _round((t * t * (segment[i + 6] - a) + 3 * inv * (t * (segment[i + 4] - a) + inv * (segment[i + 2] - a))) * t + a);
705 result.y = _round((t * t * (segment[i + 7] - (a = segment[i + 1])) + 3 * inv * (t * (segment[i + 5] - a) + inv * (segment[i + 3] - a))) * t + a);
706
707 if (includeAngle) {
708 result.angle = segment.totalLength ? getRotationAtBezierT(segment, i, t >= 1 ? 1 - 1e-9 : t ? t : 1e-9) : segment.angle || 0;
709 }
710
711 return result;
712} //applies a matrix transform to RawPath (or a segment in a RawPath) and returns whatever was passed in (it transforms the values in the array(s), not a copy).
713

Callers 1

Calls 5

_wrapProgressFunction · 0.70
cacheRawPathMeasurementsFunction · 0.70
_getSampleIndexFunction · 0.70
_roundFunction · 0.70
getRotationAtBezierTFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…