From 9a2799bc6bced9597896565c508ca5b34d4933bc Mon Sep 17 00:00:00 2001 From: skell999 Date: Thu, 24 Mar 2022 14:43:56 +0000 Subject: [PATCH] Fixed spelling and removed calls to ofxSpatialHash::isInsideBoundingBox() --- tests/ofxSpacialHash_Test.cpp | 123 +++------------------------------- tests/ofxSpacialHash_Test.h | 2 +- 2 files changed, 11 insertions(+), 114 deletions(-) diff --git a/tests/ofxSpacialHash_Test.cpp b/tests/ofxSpacialHash_Test.cpp index 550538c..14293ba 100644 --- a/tests/ofxSpacialHash_Test.cpp +++ b/tests/ofxSpacialHash_Test.cpp @@ -13,6 +13,7 @@ void ofxSpacialHash_Test::init(float width, float height, float gridSize, int nu ofRegisterMouseEvents(this); ofRegisterKeyEvents(this); + std::cout << "Running performace tests\n"; spatialTest(1000, 1000, 10, 0); m_worldWidth = width; @@ -121,16 +122,10 @@ void ofxSpacialHash_Test::draw() // Draw radius ofDrawCircle(m_mouseX, m_mouseY, m_searchRadius); - // Draw bounding box - ofDrawRectangle(m_mouseX - m_searchRadius, m_mouseY - m_searchRadius, m_searchRadius * 2.f, m_searchRadius * 2.f); ofFill(); for (auto& p : points) { - if (!m_sh.isInsideBoundingBox(p->x, p->y, m_mouseX - m_searchRadius, m_mouseY - m_searchRadius, m_searchRadius * 2.f, m_searchRadius * 2.f)) - { - continue; - } if (p->distance({ m_mouseX,m_mouseY }) < m_searchRadius) { // Points color within radius @@ -158,7 +153,7 @@ struct Result long long min = 0; }; -Result test_glm_spatial_hash(ofxSpacialHash& spatialHash, glm::vec2 searchPoint, float searchRadius, int iterations) +Result test_glm_spatial_hash(ofxSpatialHash& spatialHash, glm::vec2 searchPoint, float searchRadius, int iterations) { Result r; using namespace std::chrono; @@ -200,7 +195,7 @@ Result test_glm_spatial_hash(ofxSpacialHash& spatialHash, glm::vec2 return r; } -Result test_ofVec2f_spatial_hash(ofxSpacialHash& spatialHash, ofVec2f searchPoint, float searchRadius, int iterations) +Result test_ofVec2f_spatial_hash(ofxSpatialHash& spatialHash, ofVec2f searchPoint, float searchRadius, int iterations) { Result r; using namespace std::chrono; @@ -242,105 +237,7 @@ Result test_ofVec2f_spatial_hash(ofxSpacialHash& spatialHash, ofVec2f return r; } -Result glm_early_out(ofxSpacialHash& spatialHash, glm::vec2 searchPoint, float searchRadius, int iterations) -{ - Result r; - using namespace std::chrono; - steady_clock::time_point begin; - steady_clock::time_point end; - auto& shPointsGlm = spatialHash.getNearestPoints(searchPoint.x, searchPoint.y, searchRadius); - float bbx = searchPoint.x - searchRadius; - float bby = searchPoint.y - searchRadius; - float w = searchRadius * 2.f; - float h = w; - for (size_t i = 0; i < iterations; i++) - { - r.loopCount = 0; - r.distCount = 0; - r.inRadiusCount = 0; - begin = std::chrono::steady_clock::now(); - auto& shPointsGlm = spatialHash.getNearestPoints(searchPoint.x, searchPoint.y, searchRadius); - - for (const auto& p : shPointsGlm) - { - if (spatialHash.isInsideBoundingBox(p->x, p->y, bbx, bby, w, h)) - { - r.distCount++; - if (glm::distance(*p, searchPoint) < searchRadius) - { - r.inRadiusCount++; - } - } - r.loopCount++; - } - end = std::chrono::steady_clock::now(); - - r.micro += duration_cast(end - begin).count(); - r.nano += duration_cast(end - begin).count(); - r.milli += duration_cast(end - begin).count(); - r.sec += duration_cast(end - begin).count(); - r.min += duration_cast(end - begin).count(); - } - - r.micro /= iterations; - r.nano /= iterations; - r.milli /= iterations; - r.sec /= iterations; - r.min /= iterations; - - return r; -} - -Result ofVec2f_early_out(ofxSpacialHash& spatialHash, ofVec2f searchPoint, float searchRadius, int iterations) -{ - Result r; - using namespace std::chrono; - steady_clock::time_point begin; - steady_clock::time_point end; - auto& shPointsGlm = spatialHash.getNearestPoints(searchPoint.x, searchPoint.y, searchRadius); - float bbx = searchPoint.x - searchRadius; - float bby = searchPoint.y - searchRadius; - float w = searchRadius * 2.f; - float h = w; - for (size_t i = 0; i < iterations; i++) - { - r.loopCount = 0; - r.distCount = 0; - r.inRadiusCount = 0; - begin = std::chrono::steady_clock::now(); - auto& shPointsGlm = spatialHash.getNearestPoints(searchPoint.x, searchPoint.y, searchRadius); - - for (const auto& p : shPointsGlm) - { - if (spatialHash.isInsideBoundingBox(p->x, p->y, bbx, bby, w, h)) - { - r.distCount++; - if (p->distance(searchPoint) < searchRadius) - { - r.inRadiusCount++; - } - } - r.loopCount++; - } - end = std::chrono::steady_clock::now(); - - r.micro += duration_cast(end - begin).count(); - r.nano += duration_cast(end - begin).count(); - r.milli += duration_cast(end - begin).count(); - r.sec += duration_cast(end - begin).count(); - r.min += duration_cast(end - begin).count(); - } - - r.micro /= iterations; - r.nano /= iterations; - r.milli /= iterations; - r.sec /= iterations; - r.min /= iterations; - - return r; -} - -Result ofVec2f_naive(ofxSpacialHash& spatialHash, ofVec2f searchPoint, float searchRadius, int iterations) +Result ofVec2f_naive(ofxSpatialHash& spatialHash, ofVec2f searchPoint, float searchRadius, int iterations) { Result r; using namespace std::chrono; @@ -385,7 +282,7 @@ Result ofVec2f_naive(ofxSpacialHash& spatialHash, ofVec2f searchPoint, return r; } -Result glmvec2_naive(ofxSpacialHash& spatialHash, glm::vec2 searchPoint, float searchRadius, int iterations) +Result glmvec2_naive(ofxSpatialHash& spatialHash, glm::vec2 searchPoint, float searchRadius, int iterations) { Result r; using namespace std::chrono; @@ -486,7 +383,7 @@ void spatialTest(float worldW, float worldH, float gridSize, int preAllocSize) using namespace std; steady_clock::time_point begin; steady_clock::time_point end; - ofxSpacialHash hash; + ofxSpatialHash hash; hash.init(worldW, worldH, gridSize, 100'000); std::vector points; @@ -525,7 +422,7 @@ void spatialTest(float worldW, float worldH, float gridSize, int preAllocSize) { ofSeedRandom(3286428356); std::vector points; - ofxSpacialHash hash; + ofxSpatialHash hash; hash.init(worldW, worldH, gridSize, 100'000); for (size_t j = 0; j < numPoints[i]; j++) { @@ -542,7 +439,7 @@ void spatialTest(float worldW, float worldH, float gridSize, int preAllocSize) { ofSeedRandom(3286428356); std::vector points; - ofxSpacialHash hash; + ofxSpatialHash hash; hash.init(worldW, worldH, gridSize, 100'000); for (size_t j = 0; j < numPoints[i]; j++) { @@ -560,7 +457,7 @@ void spatialTest(float worldW, float worldH, float gridSize, int preAllocSize) if (numPoints[i] > 500'000) { std::cout << " none "; continue; } ofSeedRandom(3286428356); std::vector points; - ofxSpacialHash hash; + ofxSpatialHash hash; hash.init(worldW, worldH, gridSize, 100'000); for (size_t j = 0; j < numPoints[i]; j++) { @@ -578,7 +475,7 @@ void spatialTest(float worldW, float worldH, float gridSize, int preAllocSize) if (numPoints[i] > 500'000) { std::cout << " none "; continue; } ofSeedRandom(3286428356); std::vector points; - ofxSpacialHash hash; + ofxSpatialHash hash; hash.init(worldW, worldH, gridSize, 100'000); for (size_t j = 0; j < numPoints[i]; j++) { diff --git a/tests/ofxSpacialHash_Test.h b/tests/ofxSpacialHash_Test.h index e7f8282..8183695 100644 --- a/tests/ofxSpacialHash_Test.h +++ b/tests/ofxSpacialHash_Test.h @@ -1,6 +1,6 @@ #pragma once #include "ofMain.h" -#include +#include void spatialTest(float worldW, float worldH, float gridSize, int preAllocSize);