From c19296df35040c9c448f74b1b69644d61f780dc6 Mon Sep 17 00:00:00 2001 From: Mark Polyakov Date: Thu, 6 Apr 2023 23:30:07 -0700 Subject: [PATCH] fix small bug introduced by memory optimizations. No regression test for now, since desired semantics arent totally set in stone yet --- src/star-id.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/star-id.cpp b/src/star-id.cpp index e5c0ff5a..c0c65ce7 100644 --- a/src/star-id.cpp +++ b/src/star-id.cpp @@ -593,6 +593,7 @@ std::vector ComputeBestPyramids(const std::vector &allC std::vector> 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++) { @@ -602,6 +603,7 @@ std::vector ComputeBestPyramids(const std::vector &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]); } @@ -623,7 +625,6 @@ std::vector ComputeBestPyramids(const std::vector &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;