geom/aabb: rename AABB to aabb

This commit is contained in:
Danny Robson 2017-08-24 16:43:54 +10:00
parent 359702fb86
commit cd1bb730f2
11 changed files with 61 additions and 61 deletions

View File

@ -21,11 +21,11 @@
#include "../coord/iostream.hpp" #include "../coord/iostream.hpp"
#include "../debug.hpp" #include "../debug.hpp"
using util::geom::AABB; using util::geom::aabb;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
AABB<S,T>::AABB (point<S,T> _p0, point<S,T> _p1): aabb<S,T>::aabb (point<S,T> _p0, point<S,T> _p1):
p0 (_p0), p0 (_p0),
p1 (_p1) p1 (_p1)
{ {
@ -36,7 +36,7 @@ AABB<S,T>::AABB (point<S,T> _p0, point<S,T> _p1):
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
T T
AABB<S,T>::diameter (void) const aabb<S,T>::diameter (void) const
{ {
return magnitude ().diameter (); return magnitude ().diameter ();
} }
@ -45,7 +45,7 @@ AABB<S,T>::diameter (void) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
util::extent<S,T> util::extent<S,T>
AABB<S,T>::magnitude (void) const aabb<S,T>::magnitude (void) const
{ {
extent<S,T> out; extent<S,T> out;
for (size_t i = 0; i < S; ++i) for (size_t i = 0; i < S; ++i)
@ -57,7 +57,7 @@ AABB<S,T>::magnitude (void) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
bool bool
AABB<S,T>::overlaps (point<S,T> p) const aabb<S,T>::overlaps (point<S,T> p) const
{ {
for (size_t i = 0; i < S; ++i) for (size_t i = 0; i < S; ++i)
if (p0[i] > p[i] || p1[i] < p[i]) if (p0[i] > p[i] || p1[i] < p[i])
@ -70,7 +70,7 @@ AABB<S,T>::overlaps (point<S,T> p) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
util::point<S,T> util::point<S,T>
AABB<S,T>::closest (point<S,T> q) const aabb<S,T>::closest (point<S,T> q) const
{ {
point<S,T> res; point<S,T> res;
@ -85,8 +85,8 @@ AABB<S,T>::closest (point<S,T> q) const
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T> template <size_t S, typename T>
AABB<S,T> aabb<S,T>
AABB<S,T>::expanded (vector<S,T> mag) const noexcept aabb<S,T>::expanded (vector<S,T> mag) const noexcept
{ {
CHECK (all (mag >= T{0})); CHECK (all (mag >= T{0}));
CHECK (all (mag < p1 - p0)); CHECK (all (mag < p1 - p0));
@ -100,8 +100,8 @@ AABB<S,T>::expanded (vector<S,T> mag) const noexcept
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
AABB<S,T> aabb<S,T>
AABB<S,T>::expanded (T t) const noexcept aabb<S,T>::expanded (T t) const noexcept
{ {
CHECK_GE (t, T{0}); CHECK_GE (t, T{0});
CHECK (all (t < p1 - p0)); CHECK (all (t < p1 - p0));
@ -115,8 +115,8 @@ AABB<S,T>::expanded (T t) const noexcept
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T> template <size_t S, typename T>
AABB<S,T> aabb<S,T>
AABB<S,T>::contracted (util::vector<S,T> mag) const noexcept aabb<S,T>::contracted (util::vector<S,T> mag) const noexcept
{ {
CHECK (all (mag > T{0})); CHECK (all (mag > T{0}));
CHECK (all (mag <= p1 - p0)); CHECK (all (mag <= p1 - p0));
@ -130,8 +130,8 @@ AABB<S,T>::contracted (util::vector<S,T> mag) const noexcept
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
AABB<S,T> aabb<S,T>
AABB<S,T>::contracted (T mag) const noexcept aabb<S,T>::contracted (T mag) const noexcept
{ {
CHECK_GE (mag, T{0}); CHECK_GE (mag, T{0});
CHECK (all (mag <= p1 - p0)); CHECK (all (mag <= p1 - p0));
@ -146,7 +146,7 @@ AABB<S,T>::contracted (T mag) const noexcept
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T> template <size_t S, typename T>
void void
AABB<S,T>::cover (point<S,T> p) aabb<S,T>::cover (point<S,T> p)
{ {
p0 = min (p, p0); p0 = min (p, p0);
p1 = max (p, p1); p1 = max (p, p1);
@ -155,8 +155,8 @@ AABB<S,T>::cover (point<S,T> p)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T> template <size_t S, typename T>
AABB<S,T> aabb<S,T>
AABB<S,T>::operator+ (vector<S,T> v) const aabb<S,T>::operator+ (vector<S,T> v) const
{ {
return { p0 + v, p1 + v }; return { p0 + v, p1 + v };
} }
@ -164,8 +164,8 @@ AABB<S,T>::operator+ (vector<S,T> v) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
AABB<S,T> aabb<S,T>
AABB<S,T>::operator- (vector<S,T> v) const aabb<S,T>::operator- (vector<S,T> v) const
{ {
return { p0 - v, p1 - v }; return { p0 - v, p1 - v };
} }
@ -174,7 +174,7 @@ AABB<S,T>::operator- (vector<S,T> v) const
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T> template <size_t S, typename T>
bool bool
AABB<S,T>::operator== (const AABB<S,T> rhs) const aabb<S,T>::operator== (const aabb<S,T> rhs) const
{ {
return rhs.p0 == p0 && rhs.p1 == p1; return rhs.p0 == p0 && rhs.p1 == p1;
} }
@ -184,8 +184,8 @@ AABB<S,T>::operator== (const AABB<S,T> rhs) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
namespace util::debug { namespace util::debug {
template <size_t S, typename T> template <size_t S, typename T>
struct validator<AABB<S,T>> { struct validator<aabb<S,T>> {
static bool is_valid (const AABB<S,T> &b) static bool is_valid (const aabb<S,T> &b)
{ {
for (size_t i = 0; i < S; ++i) for (size_t i = 0; i < S; ++i)
if (b.p1[i] < b.p0[i]) if (b.p1[i] < b.p0[i])
@ -200,18 +200,18 @@ namespace util::debug {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
std::ostream& std::ostream&
util::geom::operator<< (std::ostream &os, util::geom::AABB<S,T> b) util::geom::operator<< (std::ostream &os, util::geom::aabb<S,T> b)
{ {
os << "AABB(" << b.p0 << ", " << b.p1 << ")"; os << "aabb(" << b.p0 << ", " << b.p1 << ")";
return os; return os;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#define INSTANTIATE_S_T(S,T) \ #define INSTANTIATE_S_T(S,T) \
namespace util::geom { template struct AABB<S,T>; } \ namespace util::geom { template struct aabb<S,T>; } \
template bool util::debug::is_valid (const AABB<S,T>&); \ template bool util::debug::is_valid (const aabb<S,T>&); \
template std::ostream& util::geom::operator<< (std::ostream&, AABB<S,T>); template std::ostream& util::geom::operator<< (std::ostream&, aabb<S,T>);
#define INSTANTIATE(T) \ #define INSTANTIATE(T) \
INSTANTIATE_S_T(2,T) \ INSTANTIATE_S_T(2,T) \

View File

@ -25,9 +25,9 @@
namespace util::geom { namespace util::geom {
template <size_t S, typename T> template <size_t S, typename T>
struct AABB { struct aabb {
AABB () = default; aabb () = default;
AABB (point<S,T>, point<S,T>); aabb (point<S,T>, point<S,T>);
T diameter (void) const; T diameter (void) const;
extent<S,T> magnitude (void) const; extent<S,T> magnitude (void) const;
@ -36,30 +36,30 @@ namespace util::geom {
point<S,T> closest (point<S,T>) const; point<S,T> closest (point<S,T>) const;
AABB<S,T> expanded (util::vector<S,T>) const noexcept; aabb<S,T> expanded (util::vector<S,T>) const noexcept;
AABB<S,T> expanded (T) const noexcept; aabb<S,T> expanded (T) const noexcept;
AABB<S,T> contracted (util::vector<S,T>) const noexcept; aabb<S,T> contracted (util::vector<S,T>) const noexcept;
AABB<S,T> contracted (T) const noexcept; aabb<S,T> contracted (T) const noexcept;
void cover (point<S,T>); void cover (point<S,T>);
AABB<S,T> operator+ (vector<S,T>) const; aabb<S,T> operator+ (vector<S,T>) const;
AABB<S,T> operator- (vector<S,T>) const; aabb<S,T> operator- (vector<S,T>) const;
bool operator== (AABB) const; bool operator== (aabb) const;
point<S,T> p0; point<S,T> p0;
point<S,T> p1; point<S,T> p1;
}; };
typedef AABB<2,float> AABB2f; typedef aabb<2,float> aabb2f;
typedef AABB<2,unsigned> AABB2u; typedef aabb<2,unsigned> aabb2u;
typedef AABB<2,int> AABB2i; typedef aabb<2,int> aabb2i;
typedef AABB<3,float> AABB3f; typedef aabb<3,float> aabb3f;
typedef AABB<3,unsigned> AABB3u; typedef aabb<3,unsigned> aabb3u;
typedef AABB<3,int> AABB3i; typedef aabb<3,int> aabb3i;
} }
#include "aabb.ipp" #include "aabb.ipp"

View File

@ -28,9 +28,9 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
namespace util::geom { namespace util::geom {
template <size_t S, typename T, typename G> template <size_t S, typename T, typename G>
struct sampler<S,T,AABB,G> { struct sampler<S,T,aabb,G> {
static point<S,T> static point<S,T>
fn (AABB<S,T> b, G &g) fn (aabb<S,T> b, G &g)
{ {
std::uniform_real_distribution<T> d; std::uniform_real_distribution<T> d;

View File

@ -47,7 +47,7 @@ template bool util::geom::intersects (ellipse<3,float>, util::point<3,float>);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T> template <size_t S, typename T>
static util::geom::AABB<S,T> static util::geom::aabb<S,T>
bounds (ellipse<S,T> e) bounds (ellipse<S,T> e)
{ {
return { return {
@ -59,7 +59,7 @@ bounds (ellipse<S,T> e)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T, template <size_t,typename> class K> template <size_t S, typename T, template <size_t,typename> class K>
util::geom::AABB<S,T> util::geom::aabb<S,T>
util::geom::bounds (K<S,T> k) util::geom::bounds (K<S,T> k)
{ {
return ::bounds (k); return ::bounds (k);
@ -67,5 +67,5 @@ util::geom::bounds (K<S,T> k)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template util::geom::AABB<2,float> util::geom::bounds (ellipse<2,float>); template util::geom::aabb<2,float> util::geom::bounds (ellipse<2,float>);
template util::geom::AABB<3,float> util::geom::bounds (ellipse<3,float>); template util::geom::aabb<3,float> util::geom::bounds (ellipse<3,float>);

View File

@ -22,7 +22,7 @@
namespace util::geom { namespace util::geom {
template <size_t S, typename T> struct ray; template <size_t S, typename T> struct ray;
template <size_t S, typename T> struct plane; template <size_t S, typename T> struct plane;
template <size_t S, typename T> struct AABB; template <size_t S, typename T> struct aabb;
template <size_t S, typename T> struct sphere; template <size_t S, typename T> struct sphere;
template <size_t S, typename T> struct ellipse; template <size_t S, typename T> struct ellipse;
template <size_t S, typename T> struct rect; template <size_t S, typename T> struct rect;

View File

@ -26,7 +26,7 @@
namespace util::geom { namespace util::geom {
template <size_t S, typename T> template <size_t S, typename T>
std::ostream& std::ostream&
operator<< (std::ostream&, AABB<S,T>); operator<< (std::ostream&, aabb<S,T>);
template <size_t S, typename T> template <size_t S, typename T>
std::ostream& std::ostream&

View File

@ -55,7 +55,7 @@ namespace util::geom {
typename T, typename T,
template <size_t,typename> class K template <size_t,typename> class K
> >
AABB<S,T> aabb<S,T>
bounds (K<S,T>); bounds (K<S,T>);
template < template <

View File

@ -44,7 +44,7 @@ ray<S,T>::intersect (plane<S,T> q) const
/// returns NaN if behind /// returns NaN if behind
template <size_t S, typename T> template <size_t S, typename T>
T T
ray<S,T>::intersect (AABB<S,T> r) const ray<S,T>::intersect (aabb<S,T> r) const
{ {
auto t1 = (r.p0 - origin) / direction; auto t1 = (r.p0 - origin) / direction;
auto t2 = (r.p1 - origin) / direction; auto t2 = (r.p1 - origin) / direction;

View File

@ -47,7 +47,7 @@ namespace util::geom {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// intersection tests // intersection tests
T intersect (plane<S,T>) const; T intersect (plane<S,T>) const;
T intersect (AABB<S,T>) const; T intersect (aabb<S,T>) const;
T intersect (sphere<S,T>) const; T intersect (sphere<S,T>) const;
// queries // queries

View File

@ -4,7 +4,7 @@
#include <tuple> #include <tuple>
using util::geom::AABB2f; using util::geom::aabb2f;
int int
@ -14,16 +14,16 @@ main (int, char**)
{ {
// Test contraction // Test contraction
const AABB2f val { { 2, 2 }, { 8, 8 } }; const aabb2f val { { 2, 2 }, { 8, 8 } };
const AABB2f res { { 3, 3 }, { 7, 7 } }; const aabb2f res { { 3, 3 }, { 7, 7 } };
tap.expect_eq (val.contracted (2.f), res, "over contraction"); tap.expect_eq (val.contracted (2.f), res, "over contraction");
} }
{ {
// Test expansion // Test expansion
const AABB2f val { { 2, 2 }, { 8, 8 } }; const aabb2f val { { 2, 2 }, { 8, 8 } };
const AABB2f res { { 1, 1 }, { 9, 9 } }; const aabb2f res { { 1, 1 }, { 9, 9 } };
tap.expect_eq (val.expanded (2.f), res, "expansion"); tap.expect_eq (val.expanded (2.f), res, "expansion");
} }

View File

@ -23,10 +23,10 @@ test_intersect_plane (util::TAP::logger &tap)
void void
test_intersect_aabb (util::TAP::logger &tap) test_intersect_aabb (util::TAP::logger &tap)
{ {
using util::geom::AABB2f; using util::geom::aabb2f;
// trivial case: unit aabb at origin, ray from (0.5,-0.5) upwards // trivial case: unit aabb at origin, ray from (0.5,-0.5) upwards
const AABB2f box { const aabb2f box {
{ 0.f, 0.f }, { 0.f, 0.f },
{ 1.f, 1.f } { 1.f, 1.f }
}; };