Skip to content

Commit

Permalink
Tidied up nmath namespaces
Browse files Browse the repository at this point in the history
Also adds a wip for bvh

Fixes #59
  • Loading branch information
4rknova committed May 11, 2022
1 parent 11e1e47 commit b247807
Show file tree
Hide file tree
Showing 88 changed files with 483 additions and 279 deletions.
8 changes: 4 additions & 4 deletions lib/nmath/interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "types.h"

namespace NMath {
namespace Interpolation {
namespace nmath {
namespace interpolation {

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -52,8 +52,8 @@ static inline scalar_t bezier_cubic(const scalar_t a, const scalar_t b, const sc
} /* extern "C" */
#endif

} /* namespace Interpolation */
} /* namespace NMath */
} /* namespace interpolation */
} /* namespace nmath */

#include "interpolation.inl"

Expand Down
8 changes: 4 additions & 4 deletions lib/nmath/interpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include "precision.h"
#include "defs.h"

namespace NMath {
namespace Interpolation {
namespace nmath {
namespace interpolation {

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -272,7 +272,7 @@ static inline scalar_t bezier_cubic(const scalar_t a, const scalar_t b, const sc
} /* extern "C" */
#endif

} /* namespace Interpolation */
} /* namespace NMath */
} /* namespace interpolation */
} /* namespace nmath */

#endif /* NMATH_INTERPOLATION_INL_INCLUDED */
4 changes: 2 additions & 2 deletions lib/nmath/matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "matrix.h"
#include "vector.h"

namespace NMath {
namespace nmath {

const Matrix3x3f Matrix3x3f::identity = Matrix3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1);

Expand Down Expand Up @@ -710,4 +710,4 @@ Matrix4x4f Matrix4x4f::inverse() const
return adjMat * (1.0f / determinant());
}

} /* namespace NMath */
} /* namespace nmath */
4 changes: 2 additions & 2 deletions lib/nmath/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "precision.h"
#include "types.h"

namespace NMath {
namespace nmath {

class Matrix3x3f
{
Expand Down Expand Up @@ -144,7 +144,7 @@ class Matrix4x4f
scalar_t data[4][4];
};

} /* namespace NMath */
} /* namespace nmath */

#include "matrix.inl"

Expand Down
4 changes: 2 additions & 2 deletions lib/nmath/matrix.inl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <cstring>

namespace NMath {
namespace nmath {

inline scalar_t *Matrix3x3f::operator [](int index)
{
Expand Down Expand Up @@ -39,6 +39,6 @@ inline void Matrix4x4f::reset_identity()
memcpy(data, identity.data, 16 * sizeof(scalar_t));
}

} /* namespace NMath */
} /* namespace nmath */

#endif /* NMATH_MATRIX_INL_INCLUDED */
12 changes: 10 additions & 2 deletions lib/nmath/mutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@

#include "precision.h"

namespace NMath {
namespace nmath {

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

static inline scalar_t max (scalar_t x, scalar_t y);
static inline scalar_t max3 (scalar_t x, scalar_t y, scalar_t z);
static inline scalar_t max4 (scalar_t x, scalar_t y, scalar_t z, scalar_t w);
static inline scalar_t min (scalar_t x, scalar_t y);
static inline scalar_t min3 (scalar_t x, scalar_t y, scalar_t z);
static inline scalar_t min4 (scalar_t x, scalar_t y, scalar_t z, scalar_t w);
static inline scalar_t sign (scalar_t x);

/* Angle conversion */
static inline scalar_t degree_to_radian(const scalar_t r);
static inline scalar_t radian_to_degree(const scalar_t d);
Expand All @@ -26,7 +34,7 @@ static inline int is_power_of_2(const int v);
} /* extern "C" */
#endif /* __cplusplus */

} /* namespace NMath */
} /* namespace nmath */

#include "mutil.inl"

Expand Down
12 changes: 10 additions & 2 deletions lib/nmath/mutil.inl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@
#error "mutil.h must be included before mutil.inl"
#endif /* NMATH_MUTIL_H_INCLUDED */

namespace NMath {
namespace nmath {

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

static inline scalar_t max (scalar_t x, scalar_t y) { return (x > y ? x : y); }
static inline scalar_t max3 (scalar_t x, scalar_t y, scalar_t z) { return (max(max(x,y),z)); }
static inline scalar_t max4 (scalar_t x, scalar_t y, scalar_t z, scalar_t w) { return (max(max(max(x,y),z),w)); }
static inline scalar_t min (scalar_t x, scalar_t y) { return (y > x ? x : y); }
static inline scalar_t min3 (scalar_t x, scalar_t y, scalar_t z) { return (min(min(x,y),z)); }
static inline scalar_t min4 (scalar_t x, scalar_t y, scalar_t z, scalar_t w) { return (min(min(min(x,y),z),w)); }
static inline scalar_t sign (scalar_t x) { return (x < 0 ? -1 : ( x > 0 ? 1 : 0)); }

/* Inverse square root */
/*
Notes:
Expand Down Expand Up @@ -116,6 +124,6 @@ static inline int is_power_of_2(const int v)
} /* extern "C" */
#endif /* __cplusplus */

} /* namespace NMath */
} /* namespace nmath */

#endif /* NMATH_MUTIL_INL_INCLUDED */
16 changes: 4 additions & 12 deletions lib/nmath/precision.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <math.h>
#endif /* __cplusplus */

namespace NMath {
namespace nmath {

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -115,23 +115,15 @@ const scalar_t RADIAN = 0.017453292519943;
} /* extern "C" */
#endif

inline scalar_t max (scalar_t x, scalar_t y) { return (x > y ? x : y); }
inline scalar_t max3 (scalar_t x, scalar_t y, scalar_t z) { return (max(max(x,y),z)); }
inline scalar_t max4 (scalar_t x, scalar_t y, scalar_t z, scalar_t w) { return (max(max(max(x,y),z),w)); }
inline scalar_t min (scalar_t x, scalar_t y) { return (y > x ? x : y); }
inline scalar_t min3 (scalar_t x, scalar_t y, scalar_t z) { return (min(min(x,y),z)); }
inline scalar_t min4 (scalar_t x, scalar_t y, scalar_t z, scalar_t w) { return (min(min(min(x,y),z),w)); }
inline scalar_t sign (scalar_t x) { return (x < 0 ? -1 : ( x > 0 ? 1 : 0)); }

} /* namespace NMath */
} /* namespace nmath */

// Check for standard definitions
#ifndef M_PI
#define M_PI NMath::PI
#define M_PI nmath::PI
#endif /* M_PI */

#ifndef M_E
#define M_E NMath::EULER_E
#define M_E nmath::EULER_E
#endif /* M_E */

#endif /* NMATH_PRECISION_H_INCLUDED */
4 changes: 2 additions & 2 deletions lib/nmath/prime.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "defs.h"

namespace NMath {
namespace nmath {

#ifdef __cplusplus
extern "C" {
Expand All @@ -17,7 +17,7 @@ static inline unsigned long getPrevPrime(unsigned long i);
} /* extern "C" */
#endif

} /* namespace NMath */
} /* namespace nmath */

#include "prime.inl"

Expand Down
4 changes: 2 additions & 2 deletions lib/nmath/prime.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <math.h>
#include <limits.h>

namespace NMath {
namespace nmath {

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -83,6 +83,6 @@ static inline unsigned long getPrevPrime(unsigned long i)
} /* extern "C" */
#endif

} /* namespace NMath */
} /* namespace nmath */

#endif /* NMATH_PRIME_INL_INCLUDED */
4 changes: 2 additions & 2 deletions lib/nmath/prng.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "vector.h"
#include "types.h"

namespace NMath {
namespace nmath {

#ifdef __cplusplus
extern "C" {
Expand All @@ -20,7 +20,7 @@ static inline scalar_t prng_multiplyWithCarry(const scalar_t a, const scalar_t b
} /* extern "C" */
#endif

} /* namespace NMath */
} /* namespace nmath */

#include "prng.inl"

Expand Down
4 changes: 2 additions & 2 deletions lib/nmath/prng.inl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include "precision.h"
#include "types.h"

namespace NMath {
namespace nmath {

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -211,6 +211,6 @@ static inline scalar_t prng_multiplyWithCarry(const scalar_t a, const scalar_t b
} /* extern "C" */
#endif

} /* namespace NMath */
} /* namespace nmath */

#endif /* NMATH_PRNG_INL_INCLUDED */
4 changes: 2 additions & 2 deletions lib/nmath/quadratic.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <algorithm>
#include "quadratic.h"

namespace NMath {
namespace nmath {

bool solve_quadratic(const scalar_t a, const scalar_t b, const scalar_t c, scalar_t &x0, scalar_t &x1)
{
Expand All @@ -23,4 +23,4 @@ bool solve_quadratic(const scalar_t a, const scalar_t b, const scalar_t c, scala
return true;
}

} /* namespace NMath */
} /* namespace nmath */
4 changes: 2 additions & 2 deletions lib/nmath/quadratic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <algorithm>
#include "precision.h"

namespace NMath {
namespace nmath {

bool solve_quadratic(const scalar_t a, const scalar_t b, const scalar_t c, scalar_t &x0, scalar_t &x1);

} /* namespace NMath */
} /* namespace nmath */

#endif /* NMATH_QUADRATIC_H_INCLUDED */
8 changes: 4 additions & 4 deletions lib/nmath/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
#include "precision.h"
#include "vector.h"

namespace NMath {
namespace Sample {
namespace nmath {
namespace sample {

inline Vector3f sphere();
inline Vector3f hemisphere(const Vector3f &normal, const Vector3f &direction);
inline Vector3f lobe(const Vector3f &normal, const Vector3f &direction, const scalar_t exponent);
inline Vector3f diffuse(const Vector3f &normal);

} /* namespace Sample */
} /* namespace NMath */
} /* namespace sample */
} /* namespace nmath */

#include "sample.inl"

Expand Down
10 changes: 5 additions & 5 deletions lib/nmath/sample.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "prng.h"
#include "matrix.h"

namespace NMath {
namespace Sample {
namespace nmath {
namespace sample {

inline Vector3f sphere()
{
Expand Down Expand Up @@ -38,7 +38,7 @@ inline Vector3f hemisphere(const Vector3f &normal, const Vector3f &direction)
d.y = nmath_cos(phi);
d.z = nmath_sin(theta) * nmath_sin(phi);

NMath::Matrix3x3f mat;
nmath::Matrix3x3f mat;

Vector3f norm = normal.normalized();

Expand Down Expand Up @@ -106,7 +106,7 @@ inline Vector3f diffuse(const Vector3f &normal)
return p;
}

} /* namespace Sample */
} /* namespace NMath */
} /* namespace sample */
} /* namespace nmath */

#endif /* NMATH_SAMPLE_INL_INCLUDED */
4 changes: 2 additions & 2 deletions lib/nmath/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "precision.h"

namespace NMath {
namespace nmath {

/* C++ equivalents - Forward declarations */
class Vector2f;
Expand All @@ -13,6 +13,6 @@ class Vector4f;
class Matrix3x3f;
class Matrix4x4f;

} /* namespace NMath */
} /* namespace nmath */

#endif /* NMATH_TYPES_H_INCLUDED */
4 changes: 2 additions & 2 deletions lib/nmath/vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#ifdef __cplusplus

namespace NMath {
namespace nmath {

Vector2f::Vector2f(scalar_t aX, scalar_t aY): x(aX), y(aY){}
Vector2f::Vector2f(const Vector2f& v): x(v.x), y(v.y){}
Expand All @@ -19,4 +19,4 @@ Vector4f::Vector4f(const Vector3f& v): x(v.x), y(v.y), z(v.z), w(0.0f){}

#endif /* __cplusplus */

} /* namespace NMath */
} /* namespace nmath */
4 changes: 2 additions & 2 deletions lib/nmath/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <ostream>
#include <cstdio>

namespace NMath {
namespace nmath {

class Vector2f
{
Expand Down Expand Up @@ -223,7 +223,7 @@ class Vector4f

inline scalar_t dot(const Vector4f &v1, const Vector4f &v2);

} /* namespace NMath */
} /* namespace nmath */

#include "vector.inl"

Expand Down
Loading

0 comments on commit b247807

Please sign in to comment.