From be6b472472f6a55d9f698cff05259aeab7fc3ecb Mon Sep 17 00:00:00 2001 From: Godzil Date: Thu, 20 Feb 2020 01:40:50 +0000 Subject: [PATCH] Simplify hit search as now the list is ordered. --- source/intersect.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/source/intersect.cpp b/source/intersect.cpp index df8abfe..26c3274 100644 --- a/source/intersect.cpp +++ b/source/intersect.cpp @@ -55,21 +55,12 @@ void Intersect::add(Intersection i) Intersection Intersect::hit() { int i; - double minHit = DBL_MAX; - uint32_t curHit = -1; + for(i = 0; i < this->num; i++) { - if ((this->list[i]->t >= 0) && (this->list[i]->t < minHit)) - { - curHit = i; - minHit = this->list[i]->t; - } + if (this->list[i]->t >= 0) + return *this->list[i]; } - if (curHit == -1) - { - return Intersection(0, nullptr); - } - - return *this->list[curHit]; + return Intersection(0, nullptr); } \ No newline at end of file