12 #include <unordered_map>
29 void getValueAlongLine(
const std::vector<T>& vertexData,
float location,
bool closed, T& outValue);
42 int resampleLine(std::vector<T>& vertices, std::vector<T>& buffer,
int segments,
bool closed);
53 float NAPAPI
getDistancesAlongLine(
const std::vector<glm::vec3>& vertexPositions, std::map<float, int>& outDistances,
bool loop);
63 float NAPAPI
getVertexLerpValue(
const std::map<float, int>& distanceMap,
float location,
int& outMinVertex,
int& outMaxVertex);
74 void getValueAlongLine(
const std::map<float, int>& distanceMap,
const std::vector<T>& vertexData,
float location, T& outValue);
85 void NAPAPI
getNormalAlongLine(
const std::map<float, int>& distanceMap,
const std::vector<glm::vec3>& vertexNormals,
float location, glm::vec3& outNormal);
93 void getValueAlongLine(
const std::vector<T>& vertexData,
float location,
bool closed, T& outValue)
97 int vert_count =
static_cast<int>(vertexData.size());
98 assert(vert_count > 0);
99 int range = closed ? vert_count : vert_count - 1;
102 float loc = location *
static_cast<float>(range);
106 int min_vertex =
static_cast<int>(math::floor<float>(loc));
107 int max_vertex =
static_cast<int>(math::ceil<float>(loc));
109 min_vertex = min_vertex % vert_count;
110 max_vertex = max_vertex % vert_count;
113 float lerp_v = loc -
static_cast<float>(
static_cast<int>(loc));
116 assert(min_vertex <= vert_count - 1);
117 assert(max_vertex <= vert_count - 1);
120 const T& min_p_value = vertexData[min_vertex];
121 const T& max_p_value = vertexData[max_vertex];
123 outValue = math::lerp<T>(min_p_value, max_p_value, lerp_v);
128 int resampleLine(std::vector<T>& vertices, std::vector<T>& buffer,
int segments,
bool closed)
130 assert(segments > 0);
131 int vertex_count =
static_cast<int>(vertices.size());
134 if (segments <= vertex_count || vertex_count < 2)
137 return vertices.size();
141 int edge_count = closed ? vertex_count : vertex_count - 1;
144 int pps = segments / edge_count;
150 buffer.reserve(segments);
152 for (
int i = 0; i < edge_count; i++)
155 T& point_one = vertices[i];
156 T& point_two = i + 1 >= vertex_count ? vertices[0] : vertices[i + 1];
159 for (
int p = 0; p < pps; p++)
161 float inc =
static_cast<float>(p) /
static_cast<float>(pps);
162 buffer.emplace_back(nap::math::lerp<T>(point_one, point_two, inc));
169 buffer.emplace_back(vertices.back());
173 return buffer.size();
178 void getValueAlongLine(
const std::map<float, int>& distances,
const std::vector<T>& vertexData,
float location, T& outValue)
180 int vert_min, vert_max;
184 const T& lower_value = vertexData[vert_min];
185 const T& upper_value = vertexData[vert_max];
187 outValue = math::lerp<T>(lower_value, upper_value, lerp_v);