Split Math.c into smaller files
Friend said that Math.c was too big and complicated.
This commit is contained in:
75
src/Math/Box3f.c
Normal file
75
src/Math/Box3f.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <BH/Math.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define EPSILON 0.00001f
|
||||
#define PI 3.14159265358979323846f
|
||||
|
||||
|
||||
void BH_Box3fUnion(const float *aMin,
|
||||
const float *aMax,
|
||||
const float *bMin,
|
||||
const float *bMax,
|
||||
float *outMin,
|
||||
float *outMax)
|
||||
{
|
||||
BH_Vec3fMin(aMin, bMin, outMin);
|
||||
BH_Vec3fMax(aMax, bMax, outMax);
|
||||
}
|
||||
|
||||
|
||||
int BH_Box3fIntersect(const float *aMin,
|
||||
const float *aMax,
|
||||
const float *bMin,
|
||||
const float *bMax,
|
||||
float *outMin,
|
||||
float *outMax)
|
||||
{
|
||||
BH_Vec3fMax(aMin, bMin, outMin);
|
||||
BH_Vec3fMin(aMax, bMax, outMax);
|
||||
|
||||
if (outMin[0] >= outMax[0] || outMin[1] >= outMax[1] || outMin[2] >= outMax[2])
|
||||
return BH_ERROR;
|
||||
|
||||
return BH_OK;
|
||||
}
|
||||
|
||||
|
||||
int BH_Box3fContains(const float *aMin,
|
||||
const float *aMax,
|
||||
const float *point)
|
||||
{
|
||||
if (point[0] < aMin[0] || point[1] < aMin[1] || point[2] < aMin[2])
|
||||
return BH_ERROR;
|
||||
|
||||
if (point[0] > aMax[0] || point[1] > aMax[1] || point[2] > aMax[2])
|
||||
return BH_ERROR;
|
||||
|
||||
return BH_OK;
|
||||
}
|
||||
|
||||
|
||||
int BH_Box3fEnclose(const float *points,
|
||||
size_t size,
|
||||
float *outMin,
|
||||
float *outMax)
|
||||
{
|
||||
float tmp1[3], tmp2[3];
|
||||
size_t i;
|
||||
|
||||
if (!size)
|
||||
return BH_ERROR;
|
||||
|
||||
memcpy(tmp1, points, sizeof(tmp1));
|
||||
memcpy(tmp2, points, sizeof(tmp2));
|
||||
|
||||
for (i = 1; i < size; i++)
|
||||
{
|
||||
BH_Vec3fMin(tmp1, points + i * 3, tmp1);
|
||||
BH_Vec3fMax(tmp2, points + i * 3, tmp2);
|
||||
}
|
||||
|
||||
memcpy(outMin, tmp1, sizeof(tmp1));
|
||||
memcpy(outMax, tmp2, sizeof(tmp2));
|
||||
return BH_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user