2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Base/Sphere.hpp"
|
2016-08-24 22:17:37 +02:00
|
|
|
#include "Base/DynArg.hpp"
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Buffer.hpp"
|
|
|
|
#include "Core/Utility.hpp"
|
2016-06-05 03:15:23 +02:00
|
|
|
#include "Library/Numeric/Random.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2016-11-15 20:24:39 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_DECL_TYPENAME(Typename, _SC("Sphere"))
|
2016-11-15 20:24:39 +01:00
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const Sphere Sphere::NIL = Sphere();
|
|
|
|
const Sphere Sphere::MIN = Sphere(0.0);
|
2016-03-22 01:05:50 +01:00
|
|
|
const Sphere Sphere::MAX = Sphere(std::numeric_limits< Sphere::Value >::max());
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQChar Sphere::Delim = ',';
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Sphere::Sphere(Value rv) noexcept
|
2016-02-20 23:25:00 +01:00
|
|
|
: pos(0.0), rad(rv)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Sphere::Sphere(const Vector3 & pv, Value rv) noexcept
|
2016-02-20 23:25:00 +01:00
|
|
|
: pos(pv), rad(rv)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Sphere::Sphere(Value xv, Value yv, Value zv, Value rv) noexcept
|
2016-02-20 23:25:00 +01:00
|
|
|
: pos(xv, yv, zv), rad(rv)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator = (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad = r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator = (const Vector3 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos = p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator += (const Sphere & s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos += s.pos;
|
|
|
|
rad += s.rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator -= (const Sphere & s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos -= s.pos;
|
|
|
|
rad -= s.rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator *= (const Sphere & s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos *= s.pos;
|
|
|
|
rad *= s.rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator /= (const Sphere & s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos /= s.pos;
|
|
|
|
rad /= s.rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator %= (const Sphere & s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos %= s.pos;
|
2021-01-30 07:51:39 +01:00
|
|
|
rad = fmodf(rad, s.rad);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator += (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad += r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator -= (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad -= r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator *= (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad *= r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator /= (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad /= r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator %= (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
rad = fmodf(rad, r);
|
2015-09-30 02:56:11 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator += (const Vector3 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos += p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator -= (const Vector3 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos -= p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator *= (const Vector3 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos *= p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator /= (const Vector3 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos /= p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator %= (const Vector3 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos %= p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator ++ ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
++pos;
|
|
|
|
++rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere & Sphere::operator -- ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
--pos;
|
|
|
|
--rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Sphere Sphere::operator ++ (int) // NOLINT(cert-dcl21-cpp)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Sphere state(*this);
|
|
|
|
++pos;
|
|
|
|
++rad;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Sphere Sphere::operator -- (int) // NOLINT(cert-dcl21-cpp)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Sphere state(*this);
|
|
|
|
--pos;
|
|
|
|
--rad;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator + (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos + s.pos, rad + s.rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator - (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos - s.pos, rad - s.rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator * (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos * s.pos, rad * s.rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator / (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos / s.pos, rad / s.rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator % (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {pos % s.pos, fmodf(rad, s.rad)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator + (Value r) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {rad + r};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator - (Value r) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {rad - r};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator * (Value r) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {rad * r};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator / (Value r) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {rad / r};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator % (Value r) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {fmodf(rad, r)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator + (const Vector3 & p) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos + p, rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator - (const Vector3 & p) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos - p, rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator * (const Vector3 & p) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos * p, rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator / (const Vector3 & p) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos / p, rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator % (const Vector3 & p) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos % p, rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator + () const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {pos.Abs(), fabsf(rad)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::operator - () const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {-pos, -rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Sphere::operator == (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsEq(rad, s.rad) && (pos == s.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Sphere::operator != (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-29 17:00:10 +02:00
|
|
|
return !EpsEq(rad, s.rad) || (pos != s.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Sphere::operator < (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsLt(rad, s.rad) && (pos < s.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Sphere::operator > (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsGt(rad, s.rad) && (pos > s.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Sphere::operator <= (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsLtEq(rad, s.rad) && (pos <= s.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Sphere::operator >= (const Sphere & s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsGtEq(rad, s.rad) && (pos >= s.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t Sphere::Cmp(const Sphere & o) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
if (*this == o)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return 0;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
else if (*this > o)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return 1;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
else
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return -1;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
String Sphere::ToString() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return fmt::format("{},{},{},{}", pos.x, pos.y, pos.z, rad);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:08:37 +02:00
|
|
|
void Sphere::SetRadius(Value nr)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad = nr;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Sphere::SetSphere(const Sphere & ns)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos = ns.pos;
|
|
|
|
rad = ns.rad;
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Sphere::SetSphereEx(Value nx, Value ny, Value nz, Value nr)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:08:37 +02:00
|
|
|
pos.SetVector3Ex(nx, ny, nz);
|
|
|
|
rad = nr;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Sphere::SetValues(const Vector3 & np, Value nr)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos = np;
|
|
|
|
rad = nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:08:37 +02:00
|
|
|
void Sphere::SetPosition(const Vector3 & np)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:08:37 +02:00
|
|
|
pos = np;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Sphere::SetPositionEx(Value nx, Value ny, Value nz)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:08:37 +02:00
|
|
|
pos.SetVector3Ex(nx, ny, nz);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
void Sphere::SetStr(SQChar delim, StackStrF & values)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-11-16 15:19:38 +01:00
|
|
|
SetSphere(Sphere::GetEx(delim, values));
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Sphere::Generate()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos.Generate();
|
2016-02-20 23:25:00 +01:00
|
|
|
rad = GetRandomFloat32();
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Sphere::Generate(Value min, Value max, bool r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
if (EpsLt(max, min))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-03-21 21:37:58 +01:00
|
|
|
STHROWF("max value is lower than min value");
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
else if (r)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
rad = GetRandomFloat32(min, max);
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
else
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2015-09-30 02:56:11 +02:00
|
|
|
pos.Generate(min, max);
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-03-21 21:37:58 +01:00
|
|
|
STHROWF("max value is lower than min value");
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:08:37 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value rmin, Value rmax)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(rmax, rmin))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-03-21 21:37:58 +01:00
|
|
|
STHROWF("max value is lower than min value");
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
|
|
|
|
rad = GetRandomFloat32(rmin, rmax);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Sphere Sphere::Abs() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {pos.Abs(), fabsf(rad)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 19:33:51 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
String Sphere::Format(StackStrF & str) const
|
2020-09-03 19:33:51 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return fmt::format(str.ToStr()
|
|
|
|
, fmt::arg("x", pos.x)
|
|
|
|
, fmt::arg("y", pos.y)
|
|
|
|
, fmt::arg("z", pos.z)
|
|
|
|
, fmt::arg("r", rad)
|
|
|
|
);
|
2020-09-03 19:33:51 +02:00
|
|
|
}
|
|
|
|
|
2016-03-21 21:37:58 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
const Sphere & Sphere::Get(StackStrF & str)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
2016-11-16 15:19:38 +01:00
|
|
|
return Sphere::GetEx(Sphere::Delim, str);
|
2016-03-21 21:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
const Sphere & Sphere::GetEx(SQChar delim, StackStrF & str)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
|
|
|
static Sphere sphere;
|
|
|
|
// Clear previous values, if any
|
|
|
|
sphere.Clear();
|
|
|
|
// Is the specified string empty?
|
2016-11-16 15:19:38 +01:00
|
|
|
if (str.mLen <= 0)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
|
|
|
return sphere; // Return the value as is!
|
|
|
|
}
|
2020-09-03 17:26:24 +02:00
|
|
|
// The format specifications that will be used to scan the string
|
|
|
|
SQChar fs[] = _SC(" %f , %f , %f , %f ");
|
2016-03-21 21:37:58 +01:00
|
|
|
// Assign the specified delimiter
|
|
|
|
fs[4] = delim;
|
|
|
|
fs[9] = delim;
|
|
|
|
fs[14] = delim;
|
|
|
|
// Attempt to extract the component values from the specified string
|
2016-11-16 15:19:38 +01:00
|
|
|
std::sscanf(str.mPtr, fs, &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad);
|
2016-03-21 21:37:58 +01:00
|
|
|
// Return the resulted value
|
|
|
|
return sphere;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ================================================================================================
|
|
|
|
void Register_Sphere(HSQUIRRELVM vm)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
typedef Sphere::Value Val;
|
|
|
|
|
2016-11-15 20:55:03 +01:00
|
|
|
RootTable(vm).Bind(Typename::Str,
|
|
|
|
Class< Sphere >(vm, Typename::Str)
|
2016-05-22 05:20:38 +02:00
|
|
|
// Constructors
|
2015-09-30 02:56:11 +02:00
|
|
|
.Ctor()
|
2016-02-20 23:25:00 +01:00
|
|
|
.Ctor< Val >()
|
|
|
|
.Ctor< const Vector3 &, Val >()
|
|
|
|
.Ctor< Val, Val, Val, Val >()
|
2016-05-22 05:20:38 +02:00
|
|
|
// Member Variables
|
2016-07-17 14:39:59 +02:00
|
|
|
.Var(_SC("pos"), &Sphere::pos)
|
|
|
|
.Var(_SC("rad"), &Sphere::rad)
|
2016-05-22 05:20:38 +02:00
|
|
|
.Var(_SC("Pos"), &Sphere::pos)
|
|
|
|
.Var(_SC("Rad"), &Sphere::rad)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Core Meta-methods
|
2016-08-24 22:17:37 +02:00
|
|
|
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >)
|
2016-11-15 20:24:39 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
|
|
|
|
.Func(_SC("_tostring"), &Sphere::ToString)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Meta-methods
|
2016-08-24 22:17:37 +02:00
|
|
|
.SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >)
|
|
|
|
.SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >)
|
|
|
|
.SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >)
|
|
|
|
.SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >)
|
|
|
|
.SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >)
|
2016-05-22 05:20:38 +02:00
|
|
|
.Func< Sphere (Sphere::*)(void) const >(_SC("_unm"), &Sphere::operator -)
|
2016-07-24 23:08:37 +02:00
|
|
|
// Properties
|
|
|
|
.Prop(_SC("Abs"), &Sphere::Abs)
|
|
|
|
// Member Methods
|
|
|
|
.Func(_SC("SetRadius"), &Sphere::SetRadius)
|
|
|
|
.Func(_SC("SetSphere"), &Sphere::SetSphere)
|
|
|
|
.Func(_SC("SetSphereEx"), &Sphere::SetSphereEx)
|
|
|
|
.Func(_SC("SetValues"), &Sphere::SetValues)
|
|
|
|
.Func(_SC("SetPosition"), &Sphere::SetPosition)
|
|
|
|
.Func(_SC("SetPositionEx"), &Sphere::SetPositionEx)
|
2016-11-16 15:19:38 +01:00
|
|
|
.FmtFunc(_SC("SetStr"), &Sphere::SetStr)
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("Clear"), &Sphere::Clear)
|
2020-09-03 19:33:51 +02:00
|
|
|
.FmtFunc(_SC("Format"), &Sphere::Format)
|
2016-07-24 23:08:37 +02:00
|
|
|
// Member Overloads
|
|
|
|
.Overload< void (Sphere::*)(void) >(_SC("Generate"), &Sphere::Generate)
|
|
|
|
.Overload< void (Sphere::*)(Val, Val, bool) >(_SC("Generate"), &Sphere::Generate)
|
|
|
|
.Overload< void (Sphere::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Sphere::Generate)
|
|
|
|
.Overload< void (Sphere::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Sphere::Generate)
|
2016-07-24 20:29:37 +02:00
|
|
|
// Static Functions
|
|
|
|
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Sphere >)
|
|
|
|
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Sphere >)
|
2016-11-16 15:19:38 +01:00
|
|
|
.StaticFmtFunc(_SC("FromStr"), &Sphere::Get)
|
|
|
|
.StaticFmtFunc(_SC("FromStrEx"), &Sphere::GetEx)
|
2015-09-30 02:56:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-11-15 20:24:39 +01:00
|
|
|
} // Namespace:: SqMod
|