#include "Base/Sphere.hpp" #include "Base/Shared.hpp" #include "Register.hpp" // ------------------------------------------------------------------------------------------------ namespace SqMod { // ------------------------------------------------------------------------------------------------ const Sphere Sphere::NIL = Sphere(); const Sphere Sphere::MIN = Sphere(0.0); const Sphere Sphere::MAX = Sphere(std::numeric_limits::max()); // ------------------------------------------------------------------------------------------------ SQChar Sphere::Delim = ','; // ------------------------------------------------------------------------------------------------ Sphere::Sphere() noexcept : pos(0.0, 0.0, 0.0), rad(0.0) { } Sphere::Sphere(Value r) noexcept : pos(0.0, 0.0, 0.0), rad(r) { } Sphere::Sphere(const Vector3 & p) noexcept : pos(p), rad(0.0) { } Sphere::Sphere(const Vector3 & p, Value r) noexcept : pos(p), rad(r) { } Sphere::Sphere(Value x, Value y, Value z, Value r) noexcept : pos(x, y, z), rad(r) { } // ------------------------------------------------------------------------------------------------ Sphere::Sphere(const Sphere & s) noexcept : pos(s.pos), rad(s.rad) { } Sphere::Sphere(Sphere && s) noexcept : pos(s.pos), rad(s.rad) { } // ------------------------------------------------------------------------------------------------ Sphere::~Sphere() { } // ------------------------------------------------------------------------------------------------ Sphere & Sphere::operator = (const Sphere & s) noexcept { pos = s.pos; rad = s.rad; return *this; } Sphere & Sphere::operator = (Sphere && s) noexcept { pos = s.pos; rad = s.rad; return *this; } // ------------------------------------------------------------------------------------------------ Sphere & Sphere::operator = (Value r) noexcept { rad = r; return *this; } Sphere & Sphere::operator = (const Vector3 & p) noexcept { pos = p; return *this; } // ------------------------------------------------------------------------------------------------ Sphere & Sphere::operator += (const Sphere & s) noexcept { pos += s.pos; rad += s.rad; return *this; } Sphere & Sphere::operator -= (const Sphere & s) noexcept { pos -= s.pos; rad -= s.rad; return *this; } Sphere & Sphere::operator *= (const Sphere & s) noexcept { pos *= s.pos; rad *= s.rad; return *this; } Sphere & Sphere::operator /= (const Sphere & s) noexcept { pos /= s.pos; rad /= s.rad; return *this; } Sphere & Sphere::operator %= (const Sphere & s) noexcept { pos %= s.pos; rad = std::fmod(rad, s.rad); return *this; } // ------------------------------------------------------------------------------------------------ Sphere & Sphere::operator += (Value r) noexcept { rad += r; return *this; } Sphere & Sphere::operator -= (Value r) noexcept { rad -= r; return *this; } Sphere & Sphere::operator *= (Value r) noexcept { rad *= r; return *this; } Sphere & Sphere::operator /= (Value r) noexcept { rad /= r; return *this; } Sphere & Sphere::operator %= (Value r) noexcept { rad = std::fmod(rad, r); return *this; } // ------------------------------------------------------------------------------------------------ Sphere & Sphere::operator += (const Vector3 & p) noexcept { pos += p; return *this; } Sphere & Sphere::operator -= (const Vector3 & p) noexcept { pos -= p; return *this; } Sphere & Sphere::operator *= (const Vector3 & p) noexcept { pos *= p; return *this; } Sphere & Sphere::operator /= (const Vector3 & p) noexcept { pos /= p; return *this; } Sphere & Sphere::operator %= (const Vector3 & p) noexcept { pos %= p; return *this; } // ------------------------------------------------------------------------------------------------ Sphere & Sphere::operator ++ () noexcept { ++pos; ++rad; return *this; } Sphere & Sphere::operator -- () noexcept { --pos; --rad; return *this; } // ------------------------------------------------------------------------------------------------ Sphere Sphere::operator ++ (int) noexcept { Sphere state(*this); ++pos; ++rad; return state; } Sphere Sphere::operator -- (int) noexcept { Sphere state(*this); --pos; --rad; return state; } // ------------------------------------------------------------------------------------------------ Sphere Sphere::operator + (const Sphere & s) const noexcept { return Sphere(pos + s.pos, rad + s.rad); } Sphere Sphere::operator - (const Sphere & s) const noexcept { return Sphere(pos - s.pos, rad - s.rad); } Sphere Sphere::operator * (const Sphere & s) const noexcept { return Sphere(pos * s.pos, rad * s.rad); } Sphere Sphere::operator / (const Sphere & s) const noexcept { return Sphere(pos / s.pos, rad / s.rad); } Sphere Sphere::operator % (const Sphere & s) const noexcept { return Sphere(pos % s.pos, std::fmod(rad, s.rad)); } // ------------------------------------------------------------------------------------------------ Sphere Sphere::operator + (Value r) const noexcept { return Sphere(rad + r); } Sphere Sphere::operator - (Value r) const noexcept { return Sphere(rad - r); } Sphere Sphere::operator * (Value r) const noexcept { return Sphere(rad * r); } Sphere Sphere::operator / (Value r) const noexcept { return Sphere(rad / r); } Sphere Sphere::operator % (Value r) const noexcept { return Sphere(std::fmod(rad, r)); } // ------------------------------------------------------------------------------------------------ Sphere Sphere::operator + (const Vector3 & p) const noexcept { return Sphere(pos + p); } Sphere Sphere::operator - (const Vector3 & p) const noexcept { return Sphere(pos - p); } Sphere Sphere::operator * (const Vector3 & p) const noexcept { return Sphere(pos * p); } Sphere Sphere::operator / (const Vector3 & p) const noexcept { return Sphere(pos / p); } Sphere Sphere::operator % (const Vector3 & p) const noexcept { return Sphere(pos % p); } // ------------------------------------------------------------------------------------------------ Sphere Sphere::operator + () const noexcept { return Sphere(pos.Abs(), std::fabs(rad)); } Sphere Sphere::operator - () const noexcept { return Sphere(-pos, -rad); } // ------------------------------------------------------------------------------------------------ bool Sphere::operator == (const Sphere & s) const noexcept { return (rad == s.rad) && (pos == s.pos); } bool Sphere::operator != (const Sphere & s) const noexcept { return (rad != s.rad) && (pos != s.pos); } bool Sphere::operator < (const Sphere & s) const noexcept { return (rad < s.rad) && (pos < s.pos); } bool Sphere::operator > (const Sphere & s) const noexcept { return (rad > s.rad) && (pos > s.pos); } bool Sphere::operator <= (const Sphere & s) const noexcept { return (rad <= s.rad) && (pos <= s.pos); } bool Sphere::operator >= (const Sphere & s) const noexcept { return (rad >= s.rad) && (pos >= s.pos); } // ------------------------------------------------------------------------------------------------ SQInteger Sphere::Cmp(const Sphere & s) const noexcept { return *this == s ? 0 : (*this > s ? 1 : -1); } // ------------------------------------------------------------------------------------------------ const SQChar * Sphere::ToString() const noexcept { return ToStringF("%f,%f,%f,%f", pos.x, pos.y, pos.z, rad); } // ------------------------------------------------------------------------------------------------ void Sphere::Set(Value nr) noexcept { rad = nr; } void Sphere::Set(const Sphere & ns) noexcept { pos = ns.pos; rad = ns.rad; } void Sphere::Set(const Vector3 & np) noexcept { pos = np; } void Sphere::Set(const Vector3 & np, Value nr) noexcept { pos = np; rad = nr; } // ------------------------------------------------------------------------------------------------ void Sphere::Set(Value nx, Value ny, Value nz) noexcept { pos.Set(nx, ny, nz); } void Sphere::Set(Value nx, Value ny, Value nz, Value nr) noexcept { pos.Set(nx, ny, nz); rad = nr; } // ------------------------------------------------------------------------------------------------ void Sphere::Set(const SQChar * values, SQChar delim) noexcept { Set(GetSphere(values, delim)); } // ------------------------------------------------------------------------------------------------ void Sphere::Generate() noexcept { pos.Generate(); rad = RandomVal::Get(); } void Sphere::Generate(Value min, Value max, bool r) noexcept { if (max < min) { LogErr("max value is lower than min value"); } else if (r) { rad = RandomVal::Get(min, max); } else { pos.Generate(min, max); } } void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax) noexcept { pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax); } void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value rmin, Value rmax) noexcept { if (std::isless(rmax, rmin)) { LogErr("max value is lower than min value"); } else { pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax); rad = RandomVal::Get(rmin, rmax); } } // ------------------------------------------------------------------------------------------------ Sphere Sphere::Abs() const noexcept { return Sphere(pos.Abs(), std::fabs(rad)); } // ------------------------------------------------------------------------------------------------ bool Register_Sphere(HSQUIRRELVM vm) { LogDbg("Beginning registration of type"); typedef Sphere::Value Val; Sqrat::RootTable(vm).Bind(_SC("Sphere"), Sqrat::Class(vm, _SC("Sphere")) .Ctor() .Ctor() .Ctor() .Ctor() .SetStaticValue(_SC("delim"), &Sphere::Delim) .Var(_SC("pos"), &Sphere::pos) .Var(_SC("rad"), &Sphere::rad) .Prop(_SC("abs"), &Sphere::Abs) .Func(_SC("_tostring"), &Sphere::ToString) .Func(_SC("_cmp"), &Sphere::Cmp) .Func(_SC("_add"), &Sphere::operator +) .Func(_SC("_sub"), &Sphere::operator -) .Func(_SC("_mul"), &Sphere::operator *) .Func(_SC("_div"), &Sphere::operator /) .Func(_SC("_modulo"), &Sphere::operator %) .Func(_SC("_unm"), &Sphere::operator -) .Overload(_SC("set"), &Sphere::Set) .Overload(_SC("set"), &Sphere::Set) .Overload(_SC("set"), &Sphere::Set) .Overload(_SC("set_rad"), &Sphere::Set) .Overload(_SC("set_vec3"), &Sphere::Set) .Overload(_SC("set_vec3"), &Sphere::Set) .Overload(_SC("set_str"), &Sphere::Set) .Func(_SC("clear"), &Sphere::Clear) .Func(_SC("opAddAssign"), &Sphere::operator +=) .Func(_SC("opSubAssign"), &Sphere::operator -=) .Func(_SC("opMulAssign"), &Sphere::operator *=) .Func(_SC("opDivAssign"), &Sphere::operator /=) .Func(_SC("opModAssign"), &Sphere::operator %=) .Func(_SC("opAddAssignR"), &Sphere::operator +=) .Func(_SC("opSubAssignR"), &Sphere::operator -=) .Func(_SC("opMulAssignR"), &Sphere::operator *=) .Func(_SC("opDivAssignR"), &Sphere::operator /=) .Func(_SC("opModAssignR"), &Sphere::operator %=) .Func(_SC("opAddAssignP"), &Sphere::operator +=) .Func(_SC("opSubAssignP"), &Sphere::operator -=) .Func(_SC("opMulAssignP"), &Sphere::operator *=) .Func(_SC("opDivAssignP"), &Sphere::operator /=) .Func(_SC("opModAssignP"), &Sphere::operator %=) .Func(_SC("opPreInc"), &Sphere::operator ++) .Func(_SC("opPreDec"), &Sphere::operator --) .Func(_SC("opPostInc"), &Sphere::operator ++) .Func(_SC("opPostDec"), &Sphere::operator --) .Func(_SC("opAdd"), &Sphere::operator +) .Func(_SC("opSub"), &Sphere::operator -) .Func(_SC("opMul"), &Sphere::operator *) .Func(_SC("opDiv"), &Sphere::operator /) .Func(_SC("opMod"), &Sphere::operator %) .Func(_SC("opAddR"), &Sphere::operator +) .Func(_SC("opSubR"), &Sphere::operator -) .Func(_SC("opMulR"), &Sphere::operator *) .Func(_SC("opDivR"), &Sphere::operator /) .Func(_SC("opModR"), &Sphere::operator %) .Func(_SC("opAddP"), &Sphere::operator +) .Func(_SC("opSubP"), &Sphere::operator -) .Func(_SC("opMulP"), &Sphere::operator *) .Func(_SC("opDivP"), &Sphere::operator /) .Func(_SC("opModP"), &Sphere::operator %) .Func(_SC("opUnPlus"), &Sphere::operator +) .Func(_SC("opUnMinus"), &Sphere::operator -) .Func(_SC("opEqual"), &Sphere::operator ==) .Func(_SC("opNotEqual"), &Sphere::operator !=) .Func(_SC("opLessThan"), &Sphere::operator <) .Func(_SC("opGreaterThan"), &Sphere::operator >) .Func(_SC("opLessEqual"), &Sphere::operator <=) .Func(_SC("opGreaterEqual"), &Sphere::operator >=) ); LogDbg("Registration of type was successful"); return true; } } // Namespace:: SqMod