function mapPathDistanceToPoint (out, path, pathDistance) {
    // clip or wrap given path distance according to cyclic flag
    let remaining = pathDistance

    if (path.cyclic) {
        remaining = pathDistance % path.totalPathLength //fmod(pathDistance, totalPathLength)
    } else {
        if (pathDistance < 0)
            return vec2.copy(out, path.points[0])
        if (pathDistance >= path.totalPathLength)
            return vec2.copy(out, path.points[path.pointCount-1])
    }

    // step through segments, subtracting off segment lengths until
    // locating the segment that contains the original pathDistance.
    // Interpolate along that segment to find 3d point value to return.
    for (let i = 1; i < path.pointCount; i++) {
        const segmentLength = path.lengths[i]
        if (segmentLength < remaining) {
            remaining -= segmentLength
        } else {
            const ratio = remaining / segmentLength
            //result = interpolate(ratio, points[i-1], points[i])
            vec2.lerp(out, path.points[i-1], path.points[i], ratio)
            break
        }
    }
    return out
}
// given a distance along the path, convert it to a point on the path
given a distance along the path, convert it to a point on the path
given a distance along the path convert it to a point on the path
function mapPathDistanceToPoint (out, path, pathDistance) {
    let remaining = pathDistance
    if (path.cyclic) {
        remaining = pathDistance % path.totalPathLength 
    } else {
        if (pathDistance < 0)
            return vec2.copy(out, path.points[0])
        if (pathDistance >= path.totalPathLength)
            return vec2.copy(out, path.points[path.pointCount-1])
    }
    for (let i = 1; i < path.pointCount; i++) {
        const segmentLength = path.lengths[i]
        if (segmentLength < remaining) {
            remaining -= segmentLength
        } else {
            const ratio = remaining / segmentLength
            vec2.lerp(out, path.points[i-1], path.points[i], ratio)
            break
        }
    }
    return out
}
function mapPathDistanceToPoint ( out , path , pathDistance ) { let remaining = pathDistance if ( path . cyclic ) { remaining = pathDistance % path . totalPathLength } else { if ( pathDistance < 0 ) return vec2 . copy ( out , path . points [ 0 ] ) if ( pathDistance >= path . totalPathLength ) return vec2 . copy ( out , path . points [ path . pointCount - 1 ] ) } for ( let i = 1 ; i < path . pointCount ; i ++ ) { const segmentLength = path . lengths [ i ] if ( segmentLength < remaining ) { remaining -= segmentLength } else { const ratio = remaining / segmentLength vec2 . lerp ( out , path . points [ i - 1 ] , path . points [ i ] , ratio ) break } } return out }
given a distance along the path, convert it to a point on the path
given a distance along the path convert it to a point on the path
// clip or wrap given path distance according to cyclic flag //fmod(pathDistance, totalPathLength) // step through segments, subtracting off segment lengths until // locating the segment that contains the original pathDistance. // Interpolate along that segment to find 3d point value to return. //result = interpolate(ratio, points[i-1], points[i])