Skip to content

Commit

Permalink
fix small bug introduced by memory optimizations.
Browse files Browse the repository at this point in the history
No regression test for now, since desired semantics arent totally set in stone yet
  • Loading branch information
markasoftware committed Apr 7, 2023
1 parent 6e536bc commit c19296d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/star-id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ std::vector<BestPyramidAtStar> ComputeBestPyramids(const std::vector<Vec3> &allC
std::vector<std::pair<float, int16_t>> cosines; // allocating outside of the loop avoids repeated heap allocation
cosines.reserve(centroidIndices.size());
for (int i = 0; i < (int)centroidIndices.size(); i++) {
cosines.resize(0);

// TODO: optimize this using a sorted centroids list
for (int j = 0; j < (int)centroidIndices.size(); j++) {
Expand All @@ -602,6 +603,7 @@ std::vector<BestPyramidAtStar> ComputeBestPyramids(const std::vector<Vec3> &allC
float curCos = allCentroidSpatials[centroidIndices[i]] * allCentroidSpatials[centroidIndices[j]];
// float curDistance = (allCentroids[centroidIndices[i]].position - allCentroids[centroidIndices[j]].position).Magnitude();
if (minCos <= curCos && curCos <= maxCos) {
assert(centroidIndices[i] != centroidIndices[j]);
// emplace the NEGATIVE cosine so that the sort will be smallest angle first.
cosines.emplace_back(-curCos, centroidIndices[j]);
}
Expand All @@ -623,7 +625,6 @@ std::vector<BestPyramidAtStar> ComputeBestPyramids(const std::vector<Vec3> &allC

// Add the best pyramid starting from this centroid to the result
result.emplace_back(centroidIndices[i], cosines[0].second, cosines[1].second, cosines[2].second, distancesSum);
cosines.resize(0);
}

return result;
Expand Down

0 comments on commit c19296d

Please sign in to comment.