MCPcopy Create free account
hub / github.com/ANYbotics/grid_map / getUnitSquareCornerIndices

Function getUnitSquareCornerIndices

grid_map_core/src/CubicInterpolation.cpp:212–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210}
211
212bool getUnitSquareCornerIndices(const GridMap &gridMap, const Position &queriedPosition,
213 IndicesMatrix *indicesMatrix)
214{
215
216 Index closestPointId;
217 if (!getClosestPointIndices(gridMap, queriedPosition, &closestPointId)) {
218 return false;
219 }
220
221 Position closestPoint;
222 if (!gridMap.getPosition(closestPointId, closestPoint)) {
223 return false;
224 }
225
226 const int idx0 = closestPointId.x();
227 const int idy0 = closestPointId.y();
228 const double x0 = closestPoint.x();
229 const double y0 = closestPoint.y();
230 const double x = queriedPosition.x();
231 const double y = queriedPosition.y();
232
233 if (x > x0) { //first or fourth quadrant
234 if (y > y0) { //first quadrant
235 indicesMatrix->topLeft_ = Index(idx0, idy0 - 1);
236 indicesMatrix->topRight_ = Index(idx0 - 1, idy0 - 1);
237 indicesMatrix->bottomLeft_ = Index(idx0, idy0);
238 indicesMatrix->bottomRight_ = Index(idx0 - 1, idy0);
239 } else { // fourth quadrant
240 indicesMatrix->topLeft_ = Index(idx0, idy0);
241 indicesMatrix->topRight_ = Index(idx0 - 1, idy0);
242 indicesMatrix->bottomLeft_ = Index(idx0, idy0 + 1);
243 indicesMatrix->bottomRight_ = Index(idx0 - 1, idy0 + 1);
244 }
245 } else { // second or third quadrant
246 if (y > y0) { //second quadrant
247 indicesMatrix->topLeft_ = Index(idx0 + 1, idy0 - 1);
248 indicesMatrix->topRight_ = Index(idx0, idy0 - 1);
249 indicesMatrix->bottomLeft_ = Index(idx0 + 1, idy0);
250 indicesMatrix->bottomRight_ = Index(idx0, idy0);
251 } else { // third quadrant
252 indicesMatrix->topLeft_ = Index(idx0 + 1, idy0);
253 indicesMatrix->topRight_ = Index(idx0, idy0);
254 indicesMatrix->bottomLeft_ = Index(idx0 + 1, idy0 + 1);
255 indicesMatrix->bottomRight_ = Index(idx0, idy0 + 1);
256 }
257 }
258
259 bindIndicesToRange(gridMap, indicesMatrix);
260
261 return true;
262
263}
264
265bool getClosestPointIndices(const GridMap &gridMap, const Position &queriedPosition, Index *index)
266{

Callers 1

Calls 3

getClosestPointIndicesFunction · 0.85
bindIndicesToRangeFunction · 0.85
getPositionMethod · 0.80

Tested by

no test coverage detected