1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

Use std::min and std::max

This commit is contained in:
2014-07-22 21:12:09 -07:00
parent 4f5a941d41
commit e36220cca5
35 changed files with 101 additions and 108 deletions

View File

@ -59,6 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <cctype>
#include <cstdarg>
#include <cstdint>
#include <algorithm>
//======================================
// Winblows Hacks
@ -132,8 +133,6 @@ typedef uint32_t hsGSeedValue;
#define hsLongAlign(n) (((n) + 3) & ~3L)
#define hsMaximum(a, b) ((a) > (b) ? (a) : (b))
#define hsMinimum(a, b) ((a) < (b) ? (a) : (b))
#define hsABS(x) ((x) < 0 ? -(x) : (x))
#define hsSGN(x) (((x) < 0) ? -1 : ( ((x) > 0) ? 1 : 0 ))

View File

@ -195,9 +195,9 @@ void hsBounds3::MakeSymmetric(const hsPoint3* p)
float delUp;
delUp = fMaxs[i] - (*p)[i];
delMax = hsMaximum(delMax, delUp);
delMax = std::max(delMax, delUp);
delUp = (*p)[i] - fMins[i];
delMax = hsMaximum(delMax, delUp);
delMax = std::max(delMax, delUp);
}
const float sqrtTwo = 1.41421f;
delMax *= sqrtTwo;

View File

@ -42,7 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef hsBounds_inc
#define hsBounds_inc
#include "hsGeometry3.h"
#include "hsPoint2.h"
#include "hsMatrix44.h"
@ -186,7 +186,7 @@ inline const hsPoint3& hsBounds3::GetCenter() const
inline float hsBounds3::GetMaxDim() const
{
hsAssert(kBoundsNormal == fType, "Invalid type for GetMaxDim");
return hsMaximum(hsMaximum(fMaxs.fX-fMins.fX, fMaxs.fY-fMins.fY), fMaxs.fZ-fMins.fZ);
return std::max({ fMaxs.fX - fMins.fX, fMaxs.fY - fMins.fY, fMaxs.fZ - fMins.fZ });
}
//

View File

@ -1054,7 +1054,7 @@ uint32_t hsQueueStream::Read(uint32_t byteCount, void * buffer)
int32_t limit, length, total;
limit = fWriteCursor >= fReadCursor ? fWriteCursor : fSize;
length = hsMinimum(limit-fReadCursor,byteCount);
length = std::min(limit-fReadCursor, byteCount);
HSMemory::BlockMove(fQueue+fReadCursor,buffer,length);
fReadCursor += length;
fReadCursor %= fSize;
@ -1063,7 +1063,7 @@ uint32_t hsQueueStream::Read(uint32_t byteCount, void * buffer)
if (length < byteCount && limit != fWriteCursor)
{
limit = fWriteCursor;
length = hsMinimum(limit,byteCount-length);
length = std::min(limit, static_cast<int32_t>(byteCount)-length);
HSMemory::BlockMove(fQueue,static_cast<char*>(buffer)+total,length);
fReadCursor = length;
total += length;
@ -1079,7 +1079,7 @@ uint32_t hsQueueStream::Write(uint32_t byteCount, const void* buffer)
int32_t length;
length = hsMinimum(fSize-fWriteCursor,byteCount);
length = std::min(fSize-fWriteCursor, byteCount);
HSMemory::BlockMove(buffer,fQueue+fWriteCursor,length);
if (fReadCursor > fWriteCursor)
{
@ -1087,7 +1087,7 @@ uint32_t hsQueueStream::Write(uint32_t byteCount, const void* buffer)
if (fReadCursor < fWriteCursor+length+1)
hsStatusMessage("ReadCursor wrapped\n");
#endif
fReadCursor = hsMaximum(fReadCursor,fWriteCursor+length+1);
fReadCursor = std::min(fReadCursor, fWriteCursor+length+1);
fReadCursor %= fSize;
}
fWriteCursor += length;
@ -1106,19 +1106,19 @@ void hsQueueStream::Skip(uint32_t deltaByteCount)
int32_t limit, length;
limit = fWriteCursor >= fReadCursor ? fWriteCursor : fSize;
length = hsMinimum(limit-fReadCursor,deltaByteCount);
length = std::min(limit-fReadCursor, deltaByteCount);
fReadCursor += length;
if (length < deltaByteCount && limit != fWriteCursor)
{
limit = fWriteCursor;
length = hsMinimum(limit,deltaByteCount-length);
length = std::min(limit, static_cast<int32_t>(deltaByteCount)-length);
fReadCursor = length;
}
else
{
fReadCursor %= fSize;
}
}
}
void hsQueueStream::Rewind()

View File

@ -238,7 +238,7 @@ void hsDynamicArray<T>::SetCount(int32_t count)
{ T* newArray = new T[count];
if (fArray)
{ int copyCount = hsMinimum(count, fCount);
{ int copyCount = std::min(count, fCount);
for (int i = 0; i < copyCount; i++)
newArray[i] = fArray[i];

View File

@ -270,9 +270,9 @@ bool plViewTransform::Intersect(const plViewTransform& view)
int i;
for( i = 0; i < 3; i++ )
{
mins[i] = hsMaximum(fMin[i], view.fMin[i]);
mins[i] = std::max(fMin[i], view.fMin[i]);
maxs[i] = hsMinimum(fMax[i], view.fMax[i]);
maxs[i] = std::min(fMax[i], view.fMax[i]);
if( mins[i] >= maxs[i] )
{
@ -292,9 +292,9 @@ bool plViewTransform::Union(const plViewTransform& view)
int i;
for( i = 0; i < 3; i++ )
{
mins[i] = hsMinimum(fMin[i], view.fMin[i]);
mins[i] = std::min(fMin[i], view.fMin[i]);
maxs[i] = hsMaximum(fMax[i], view.fMax[i]);
maxs[i] = std::max(fMax[i], view.fMax[i]);
}
SetView(mins, maxs);