diff --git a/src/simplnx/Utilities/Math/GeometryMath.hpp b/src/simplnx/Utilities/Math/GeometryMath.hpp index 2d247c0058..fc42f9cf50 100644 --- a/src/simplnx/Utilities/Math/GeometryMath.hpp +++ b/src/simplnx/Utilities/Math/GeometryMath.hpp @@ -323,27 +323,21 @@ char IsPointInTriangle(const nx::core::Point3D& p0, const nx::core::Point3D -char RayCrossesTriangle(const Point3D& p0, const Point3D& p1, const Point3D& p2, const Ray& ray) +char RayCrossesTriangle(const Ray& ray, const Point3D& p0, const Point3D& p1, const Point3D& p2) { T vol0 = FindTetrahedronVolume(ray.getOrigin(), p0, p1, ray.getEndPoint()); T vol1 = FindTetrahedronVolume(ray.getOrigin(), p1, p2, ray.getEndPoint()); @@ -443,27 +437,21 @@ char RayCrossesTriangle(const Point3D& p0, const Point3D& p1, const Point3 bool hasNeg = vol0 < 0 || vol1 < 0 || vol2 < 0; int32 zeroCount = !vol0 + !vol1 + !vol2; - if(!(hasPos && hasNeg)) - { - if(zeroCount == 0) - { - return 'f'; - } - else if(zeroCount == 1) - { - return 'e'; - } - else if(zeroCount == 2) - { - return 'v'; - } - else if(zeroCount == 3) - { - return '?'; - } - } + char code = '?'; - return '0'; + bool secondaryCond = !zeroCount; + code = secondaryCond * 'f' + !secondaryCond * code; + + secondaryCond = zeroCount == 1; + code = secondaryCond * 'e' + !secondaryCond * code; + + secondaryCond = zeroCount == 2; + code = secondaryCond * 'v' + !secondaryCond * code; + + bool primaryCond = !(hasPos && hasNeg); + code = !primaryCond * '0' + primaryCond * code; + + return code; } /** @@ -479,7 +467,7 @@ char RayCrossesTriangle(const Point3D& p0, const Point3D& p1, const Point3 * @return bool */ template -char RayCrossesTriangle(const Point3D& p0, const Point3D& p1, const Point3D& p2, const Ray& ray) +char RayCrossesTriangle(const Ray& ray, const Point3D& p0, const Point3D& p1, const Point3D& p2) { T vol0 = FindTetrahedronVolume(ray.getOrigin(), p0, p1, ray.getEndPointRef()); T vol1 = FindTetrahedronVolume(ray.getOrigin(), p1, p2, ray.getEndPointRef()); @@ -489,27 +477,21 @@ char RayCrossesTriangle(const Point3D& p0, const Point3D& p1, const Point3 bool hasNeg = vol0 < 0 || vol1 < 0 || vol2 < 0; int32 zeroCount = !vol0 + !vol1 + !vol2; - if(!(hasPos && hasNeg)) - { - if(zeroCount == 0) - { - return 'f'; - } - else if(zeroCount == 1) - { - return 'e'; - } - else if(zeroCount == 2) - { - return 'v'; - } - else if(zeroCount == 3) - { - return '?'; - } - } + char code = '?'; - return '0'; + bool secondaryCond = !zeroCount; + code = secondaryCond * 'f' + !secondaryCond * code; + + secondaryCond = zeroCount == 1; + code = secondaryCond * 'e' + !secondaryCond * code; + + secondaryCond = zeroCount == 2; + code = secondaryCond * 'v' + !secondaryCond * code; + + bool primaryCond = !(hasPos && hasNeg); + code = !primaryCond * '0' + primaryCond * code; + + return code; } /** @@ -627,7 +609,7 @@ char RayIntersectsTriangle(const Ray& ray, const nx::core::Point3D& p0, co // switch-like optimizations over the chain because 'code' is unbounded if(code == '1') { - return RayCrossesTriangle(p0, p1, p2, ray); + return RayCrossesTriangle(ray, p0, p1, p2); } else if(code == 'q') { @@ -664,7 +646,7 @@ char RayIntersectsTriangle(const Ray& ray, const nx::core::Point3D& // switch-like optimizations over the chain because 'code' is unbounded if(code == '1') { - return RayCrossesTriangle(p0, p1, p2, ray); + return RayCrossesTriangle(ray, p0, p1, p2); } else if(code == 'q') {