2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-23 21:22:07 +00:00

chore: use std min and std max in bsp utils

This commit is contained in:
Jan Laupetin
2025-11-06 20:25:32 +01:00
parent bbb07e2b59
commit a8456f88a4
2 changed files with 14 additions and 32 deletions

View File

@@ -1,5 +1,6 @@
#include "BSPUtil.h" #include "BSPUtil.h"
#include <algorithm>
#include <cmath> #include <cmath>
#include <format> #include <format>
@@ -32,44 +33,26 @@ namespace BSP
void BSPUtil::updateAABB(vec3_t& newAABBMins, vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs) void BSPUtil::updateAABB(vec3_t& newAABBMins, vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs)
{ {
if (AABBMins.x > newAABBMins.x) AABBMins.x = std::min(AABBMins.x, newAABBMins.x);
AABBMins.x = newAABBMins.x; AABBMaxs.x = std::max(AABBMaxs.x, newAABBMaxs.x);
if (newAABBMaxs.x > AABBMaxs.x) AABBMins.y = std::min(AABBMins.y, newAABBMins.y);
AABBMaxs.x = newAABBMaxs.x; AABBMaxs.y = std::max(AABBMaxs.y, newAABBMaxs.y);
if (AABBMins.y > newAABBMins.y) AABBMins.z = std::min(AABBMins.z, newAABBMins.z);
AABBMins.y = newAABBMins.y; AABBMaxs.z = std::max(AABBMaxs.z, newAABBMaxs.z);
if (newAABBMaxs.y > AABBMaxs.y)
AABBMaxs.y = newAABBMaxs.y;
if (AABBMins.z > newAABBMins.z)
AABBMins.z = newAABBMins.z;
if (newAABBMaxs.z > AABBMaxs.z)
AABBMaxs.z = newAABBMaxs.z;
} }
void BSPUtil::updateAABBWithPoint(vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs) void BSPUtil::updateAABBWithPoint(vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs)
{ {
if (AABBMins.x > point.x) AABBMins.x = std::min(AABBMins.x, point.x);
AABBMins.x = point.x; AABBMaxs.x = std::max(AABBMaxs.x, point.x);
if (point.x > AABBMaxs.x) AABBMins.y = std::min(AABBMins.y, point.y);
AABBMaxs.x = point.x; AABBMaxs.y = std::max(AABBMaxs.y, point.y);
if (AABBMins.y > point.y) AABBMins.z = std::min(AABBMins.z, point.z);
AABBMins.y = point.y; AABBMaxs.z = std::max(AABBMaxs.z, point.z);
if (point.y > AABBMaxs.y)
AABBMaxs.y = point.y;
if (AABBMins.z > point.z)
AABBMins.z = point.z;
if (point.z > AABBMaxs.z)
AABBMaxs.z = point.z;
} }
vec3_t BSPUtil::calcMiddleOfAABB(vec3_t& mins, vec3_t& maxs) vec3_t BSPUtil::calcMiddleOfAABB(vec3_t& mins, vec3_t& maxs)

View File

@@ -217,8 +217,7 @@ namespace BSP
size_t leafObjectCount = tree->leaf->getObjectCount(); size_t leafObjectCount = tree->leaf->getObjectCount();
assert(leafObjectCount > 0); assert(leafObjectCount > 0);
if (leafObjectCount > highestLeafObjectCount) highestLeafObjectCount = std::max(leafObjectCount, highestLeafObjectCount);
highestLeafObjectCount = leafObjectCount;
// BO2 has a maximum limit of 128 children per AABB tree (essentially), // BO2 has a maximum limit of 128 children per AABB tree (essentially),
// so this is fixed by adding multiple parent AABB trees that hold 128 children each // so this is fixed by adding multiple parent AABB trees that hold 128 children each