1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-07 13:27:13 +01:00

Improve the AABB registration code to avoid using overloads where not necessary.

Also restructured the registration code a bit.
This commit is contained in:
Sandu Liviu Catalin 2016-07-24 23:18:27 +03:00
parent 3cea68bdca
commit 274ce72a4b
2 changed files with 59 additions and 24 deletions

View File

@ -65,6 +65,7 @@ AABB & AABB::operator = (Value s)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator = (const Vector3 & v) AABB & AABB::operator = (const Vector3 & v)
{ {
min.Set(-v); min.Set(-v);
@ -72,6 +73,7 @@ AABB & AABB::operator = (const Vector3 & v)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator = (const Vector4 & v) AABB & AABB::operator = (const Vector4 & v)
{ {
min.Set(-v); min.Set(-v);
@ -87,6 +89,7 @@ AABB & AABB::operator += (const AABB & b)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator -= (const AABB & b) AABB & AABB::operator -= (const AABB & b)
{ {
min -= b.min; min -= b.min;
@ -94,6 +97,7 @@ AABB & AABB::operator -= (const AABB & b)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator *= (const AABB & b) AABB & AABB::operator *= (const AABB & b)
{ {
min *= b.min; min *= b.min;
@ -101,6 +105,7 @@ AABB & AABB::operator *= (const AABB & b)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator /= (const AABB & b) AABB & AABB::operator /= (const AABB & b)
{ {
min /= b.min; min /= b.min;
@ -108,6 +113,7 @@ AABB & AABB::operator /= (const AABB & b)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator %= (const AABB & b) AABB & AABB::operator %= (const AABB & b)
{ {
min %= b.min; min %= b.min;
@ -123,6 +129,7 @@ AABB & AABB::operator += (Value s)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator -= (Value s) AABB & AABB::operator -= (Value s)
{ {
min -= s; min -= s;
@ -130,6 +137,7 @@ AABB & AABB::operator -= (Value s)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator *= (Value s) AABB & AABB::operator *= (Value s)
{ {
min *= s; min *= s;
@ -137,6 +145,7 @@ AABB & AABB::operator *= (Value s)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator /= (Value s) AABB & AABB::operator /= (Value s)
{ {
min /= s; min /= s;
@ -144,6 +153,7 @@ AABB & AABB::operator /= (Value s)
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator %= (Value s) AABB & AABB::operator %= (Value s)
{ {
min %= s; min %= s;
@ -159,6 +169,7 @@ AABB & AABB::operator ++ ()
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator -- () AABB & AABB::operator -- ()
{ {
--min; --min;
@ -175,6 +186,7 @@ AABB AABB::operator ++ (int)
return state; return state;
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator -- (int) AABB AABB::operator -- (int)
{ {
AABB state(*this); AABB state(*this);
@ -189,21 +201,25 @@ AABB AABB::operator + (const AABB & b) const
return AABB(min + b.min, max + b.max); return AABB(min + b.min, max + b.max);
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator - (const AABB & b) const AABB AABB::operator - (const AABB & b) const
{ {
return AABB(min - b.min, max - b.max); return AABB(min - b.min, max - b.max);
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator * (const AABB & b) const AABB AABB::operator * (const AABB & b) const
{ {
return AABB(min * b.min, max * b.max); return AABB(min * b.min, max * b.max);
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator / (const AABB & b) const AABB AABB::operator / (const AABB & b) const
{ {
return AABB(min / b.min, max / b.max); return AABB(min / b.min, max / b.max);
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator % (const AABB & b) const AABB AABB::operator % (const AABB & b) const
{ {
return AABB(min % b.min, max % b.max); return AABB(min % b.min, max % b.max);
@ -215,21 +231,25 @@ AABB AABB::operator + (Value s) const
return AABB(min + s, max + s); return AABB(min + s, max + s);
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator - (Value s) const AABB AABB::operator - (Value s) const
{ {
return AABB(min - s, max - s); return AABB(min - s, max - s);
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator * (Value s) const AABB AABB::operator * (Value s) const
{ {
return AABB(min * s, max * s); return AABB(min * s, max * s);
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator / (Value s) const AABB AABB::operator / (Value s) const
{ {
return AABB(min / s, max / s); return AABB(min / s, max / s);
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator % (Value s) const AABB AABB::operator % (Value s) const
{ {
return AABB(min % s, max % s); return AABB(min % s, max % s);
@ -241,6 +261,7 @@ AABB AABB::operator + () const
return AABB(min.Abs(), max.Abs()); return AABB(min.Abs(), max.Abs());
} }
// ------------------------------------------------------------------------------------------------
AABB AABB::operator - () const AABB AABB::operator - () const
{ {
return AABB(-min, -max); return AABB(-min, -max);
@ -252,26 +273,31 @@ bool AABB::operator == (const AABB & b) const
return (min == b.min) && (max == b.max); return (min == b.min) && (max == b.max);
} }
// ------------------------------------------------------------------------------------------------
bool AABB::operator != (const AABB & b) const bool AABB::operator != (const AABB & b) const
{ {
return (min != b.min) && (max != b.max); return (min != b.min) && (max != b.max);
} }
// ------------------------------------------------------------------------------------------------
bool AABB::operator < (const AABB & b) const bool AABB::operator < (const AABB & b) const
{ {
return (min < b.min) && (max < b.max); return (min < b.min) && (max < b.max);
} }
// ------------------------------------------------------------------------------------------------
bool AABB::operator > (const AABB & b) const bool AABB::operator > (const AABB & b) const
{ {
return (min > b.min) && (max > b.max); return (min > b.min) && (max > b.max);
} }
// ------------------------------------------------------------------------------------------------
bool AABB::operator <= (const AABB & b) const bool AABB::operator <= (const AABB & b) const
{ {
return (min <= b.min) && (max <= b.max); return (min <= b.min) && (max <= b.max);
} }
// ------------------------------------------------------------------------------------------------
bool AABB::operator >= (const AABB & b) const bool AABB::operator >= (const AABB & b) const
{ {
return (min >= b.min) && (max >= b.max); return (min >= b.min) && (max >= b.max);
@ -307,12 +333,14 @@ void AABB::Set(Value ns)
max = std::fabs(ns); max = std::fabs(ns);
} }
// ------------------------------------------------------------------------------------------------
void AABB::Set(Value nx, Value ny, Value nz) void AABB::Set(Value nx, Value ny, Value nz)
{ {
min.Set(-nx, -ny, -nz); min.Set(-nx, -ny, -nz);
max.Set(std::fabs(nx), std::fabs(ny), std::fabs(nz)); max.Set(std::fabs(nx), std::fabs(ny), std::fabs(nz));
} }
// ------------------------------------------------------------------------------------------------
void AABB::Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) void AABB::Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax)
{ {
min.Set(xmin, ymin, zmin); min.Set(xmin, ymin, zmin);
@ -320,33 +348,35 @@ void AABB::Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void AABB::SetBox(const AABB & b) void AABB::SetAABB(const AABB & b)
{ {
min = b.min; min = b.min;
max = b.max; max = b.max;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void AABB::SetVec3(const Vector3 & v) void AABB::SetVector3(const Vector3 & v)
{ {
min = -v; min = -v;
max = v.Abs(); max = v.Abs();
} }
void AABB::SetVec3(const Vector3 & nmin, const Vector3 & nmax) // ------------------------------------------------------------------------------------------------
void AABB::SetVector3(const Vector3 & nmin, const Vector3 & nmax)
{ {
min = nmin; min = nmin;
max = nmax; max = nmax;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void AABB::SetVec4(const Vector4 & v) void AABB::SetVector4(const Vector4 & v)
{ {
min = -v; min = -v;
max = v.Abs(); max = v.Abs();
} }
void AABB::SetVec4(const Vector4 & nmin, const Vector4 & nmax) // ------------------------------------------------------------------------------------------------
void AABB::SetVector4(const Vector4 & nmin, const Vector4 & nmax)
{ {
min = nmin; min = nmin;
max = nmax; max = nmax;
@ -355,7 +385,7 @@ void AABB::SetVec4(const Vector4 & nmin, const Vector4 & nmax)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void AABB::SetStr(CSStr values, SQChar delim) void AABB::SetStr(CSStr values, SQChar delim)
{ {
SetBox(AABB::Get(values, delim)); SetAABB(AABB::Get(values, delim));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -403,6 +433,7 @@ const AABB & GetAABB()
return box; return box;
} }
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(Float32 sv) const AABB & GetAABB(Float32 sv)
{ {
static AABB box; static AABB box;
@ -410,6 +441,7 @@ const AABB & GetAABB(Float32 sv)
return box; return box;
} }
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(Float32 xv, Float32 yv, Float32 zv) const AABB & GetAABB(Float32 xv, Float32 yv, Float32 zv)
{ {
static AABB box; static AABB box;
@ -417,6 +449,7 @@ const AABB & GetAABB(Float32 xv, Float32 yv, Float32 zv)
return box; return box;
} }
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(Float32 xmin, Float32 ymin, Float32 zmin, Float32 xmax, Float32 ymax, Float32 zmax) const AABB & GetAABB(Float32 xmin, Float32 ymin, Float32 zmin, Float32 xmax, Float32 ymax, Float32 zmax)
{ {
static AABB box; static AABB box;
@ -424,17 +457,19 @@ const AABB & GetAABB(Float32 xmin, Float32 ymin, Float32 zmin, Float32 xmax, Flo
return box; return box;
} }
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(const Vector3 & vmin, const Vector3 & vmax) const AABB & GetAABB(const Vector3 & vmin, const Vector3 & vmax)
{ {
static AABB box; static AABB box;
box.SetVec3(vmin, vmax); box.SetVector3(vmin, vmax);
return box; return box;
} }
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(const AABB & o) const AABB & GetAABB(const AABB & o)
{ {
static AABB box; static AABB box;
box.SetBox(o); box.SetAABB(o);
return box; return box;
} }
@ -455,8 +490,6 @@ void Register_AABB(HSQUIRRELVM vm)
.Var(_SC("max"), &AABB::max) .Var(_SC("max"), &AABB::max)
.Var(_SC("Min"), &AABB::min) .Var(_SC("Min"), &AABB::min)
.Var(_SC("Max"), &AABB::max) .Var(_SC("Max"), &AABB::max)
// Properties
.Prop(_SC("Abs"), &AABB::Abs)
// Core Meta-methods // Core Meta-methods
.Func(_SC("_tostring"), &AABB::ToString) .Func(_SC("_tostring"), &AABB::ToString)
.SquirrelFunc(_SC("_typename"), &AABB::Typename) .SquirrelFunc(_SC("_typename"), &AABB::Typename)
@ -468,18 +501,20 @@ void Register_AABB(HSQUIRRELVM vm)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_div"), &AABB::operator /) .Func< AABB (AABB::*)(const AABB &) const >(_SC("_div"), &AABB::operator /)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_modulo"), &AABB::operator %) .Func< AABB (AABB::*)(const AABB &) const >(_SC("_modulo"), &AABB::operator %)
.Func< AABB (AABB::*)(void) const >(_SC("_unm"), &AABB::operator -) .Func< AABB (AABB::*)(void) const >(_SC("_unm"), &AABB::operator -)
// Setters // Properties
.Prop(_SC("Abs"), &AABB::Abs)
// Member Methods
.Func(_SC("SetAABB"), &AABB::SetAABB)
.Func(_SC("SetStr"), &AABB::SetStr)
.Func(_SC("Clear"), &AABB::Clear)
// Member Overloads
.Overload< void (AABB::*)(Val) >(_SC("Set"), &AABB::Set) .Overload< void (AABB::*)(Val) >(_SC("Set"), &AABB::Set)
.Overload< void (AABB::*)(Val, Val, Val) >(_SC("Set"), &AABB::Set) .Overload< void (AABB::*)(Val, Val, Val) >(_SC("Set"), &AABB::Set)
.Overload< void (AABB::*)(Val, Val, Val, Val, Val, Val) >(_SC("Set"), &AABB::Set) .Overload< void (AABB::*)(Val, Val, Val, Val, Val, Val) >(_SC("Set"), &AABB::Set)
.Overload< void (AABB::*)(const Vector3 &) >(_SC("SetVec3"), &AABB::SetVec3) .Overload< void (AABB::*)(const Vector3 &) >(_SC("SetVector3"), &AABB::SetVector3)
.Overload< void (AABB::*)(const Vector3 &, const Vector3 &) >(_SC("SetVec3"), &AABB::SetVec3) .Overload< void (AABB::*)(const Vector3 &, const Vector3 &) >(_SC("SetVector3"), &AABB::SetVector3)
.Overload< void (AABB::*)(const Vector4 &) >(_SC("SetVec4"), &AABB::SetVec4) .Overload< void (AABB::*)(const Vector4 &) >(_SC("SetVector4"), &AABB::SetVector4)
.Overload< void (AABB::*)(const Vector4 &, const Vector4 &) >(_SC("SetVec4"), &AABB::SetVec4) .Overload< void (AABB::*)(const Vector4 &, const Vector4 &) >(_SC("SetVector4"), &AABB::SetVector4)
// Utility Methods
.Func(_SC("Clear"), &AABB::Clear)
.Func(_SC("SetBox"), &AABB::SetBox)
.Func(_SC("SetStr"), &AABB::SetStr)
// Static Overloads // Static Overloads
.StaticOverload< const AABB & (*)(CSStr) >(_SC("FromStr"), &AABB::Get) .StaticOverload< const AABB & (*)(CSStr) >(_SC("FromStr"), &AABB::Get)
.StaticOverload< const AABB & (*)(CSStr, SQChar) >(_SC("FromStr"), &AABB::Get) .StaticOverload< const AABB & (*)(CSStr, SQChar) >(_SC("FromStr"), &AABB::Get)

View File

@ -297,31 +297,31 @@ struct AABB
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set the same box from another instance of this type. * Set the same box from another instance of this type.
*/ */
void SetBox(const AABB & b); void SetAABB(const AABB & b);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set an equally sized and imperfectly shaped box from a single three-dimensional vector * Set an equally sized and imperfectly shaped box from a single three-dimensional vector
* representing a single three-dimensional point. * representing a single three-dimensional point.
*/ */
void SetVec3(const Vector3 & v); void SetVector3(const Vector3 & v);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set an unequally sized and imperfectly shaped box from two three-dimensional vectors * Set an unequally sized and imperfectly shaped box from two three-dimensional vectors
* representing two three-dimensional points. * representing two three-dimensional points.
*/ */
void SetVec3(const Vector3 & nmin, const Vector3 & nmax); void SetVector3(const Vector3 & nmin, const Vector3 & nmax);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set an equally sized and imperfectly shaped box from a single four-dimensional vector * Set an equally sized and imperfectly shaped box from a single four-dimensional vector
* representing a single three-dimensional point. * representing a single three-dimensional point.
*/ */
void SetVec4(const Vector4 & v); void SetVector4(const Vector4 & v);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set an unequally sized and imperfectly shaped box from two four-dimensional vectors * Set an unequally sized and imperfectly shaped box from two four-dimensional vectors
* representing two three-dimensional points. * representing two three-dimensional points.
*/ */
void SetVec4(const Vector4 & nmin, const Vector4 & nmax); void SetVector4(const Vector4 & nmin, const Vector4 & nmax);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set the values extracted from the specified string using the specified delimiter. * Set the values extracted from the specified string using the specified delimiter.