2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Base/Circle.hpp"
|
2016-08-24 22:17:01 +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:21:15 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_DECL_TYPENAME(Typename, _SC("Circle"))
|
2016-11-15 20:21:15 +01:00
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const Circle Circle::NIL = Circle();
|
|
|
|
const Circle Circle::MIN = Circle(0.0);
|
2016-03-22 01:05:50 +01:00
|
|
|
const Circle Circle::MAX = Circle(std::numeric_limits< Circle::Value >::max());
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQChar Circle::Delim = ',';
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Circle::Circle(Value rv) noexcept
|
2016-02-20 23:25:00 +01:00
|
|
|
: pos(0.0, 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
|
|
|
Circle::Circle(const Vector2 & 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
|
|
|
Circle::Circle(Value xv, Value yv, Value rv) noexcept
|
2016-02-20 23:25:00 +01:00
|
|
|
: pos(xv, yv), 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
|
|
|
Circle & Circle::operator = (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad = r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle & Circle::operator = (const Vector2 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos = p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator += (const Circle & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos += c.pos;
|
|
|
|
rad += c.rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator -= (const Circle & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos -= c.pos;
|
|
|
|
rad -= c.rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator *= (const Circle & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos *= c.pos;
|
|
|
|
rad *= c.rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator /= (const Circle & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos /= c.pos;
|
|
|
|
rad /= c.rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator %= (const Circle & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos %= c.pos;
|
2021-01-30 07:51:39 +01:00
|
|
|
rad = fmodf(rad, c.rad);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator += (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad += r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator -= (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad -= r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator *= (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad *= r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator /= (Value r)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad /= r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle & Circle::operator += (const Vector2 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos += p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle & Circle::operator -= (const Vector2 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos -= p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle & Circle::operator *= (const Vector2 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos *= p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle & Circle::operator /= (const Vector2 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos /= p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle & Circle::operator %= (const Vector2 & p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos %= p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator ++ ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
++pos;
|
|
|
|
++rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle & Circle::operator -- ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
--pos;
|
|
|
|
--rad;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Circle Circle::operator ++ (int) // NOLINT(cert-dcl21-cpp)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Circle state(*this);
|
|
|
|
++pos;
|
|
|
|
++rad;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 08:16:40 +01:00
|
|
|
Circle Circle::operator -- (int) // NOLINT(cert-dcl21-cpp)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Circle state(*this);
|
|
|
|
--pos;
|
|
|
|
--rad;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::operator + (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos + c.pos, rad + c.rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::operator - (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos - c.pos, rad - c.rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::operator * (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos * c.pos, rad * c.rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::operator / (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2020-03-22 08:16:40 +01:00
|
|
|
return {pos / c.pos, rad / c.rad};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::operator % (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return {pos % c.pos, fmodf(rad, c.rad)};
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::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
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle Circle::operator + (const Vector2 & 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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle Circle::operator - (const Vector2 & 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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle Circle::operator * (const Vector2 & 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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle Circle::operator / (const Vector2 & 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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Circle Circle::operator % (const Vector2 & 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
|
|
|
Circle Circle::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 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::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 Circle::operator == (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsEq(rad, c.rad) && (pos == c.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Circle::operator != (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-29 17:00:10 +02:00
|
|
|
return !EpsEq(rad, c.rad) || (pos != c.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Circle::operator < (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsLt(rad, c.rad) && (pos < c.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Circle::operator > (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsGt(rad, c.rad) && (pos > c.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Circle::operator <= (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsLtEq(rad, c.rad) && (pos <= c.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Circle::operator >= (const Circle & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return EpsGtEq(rad, c.rad) && (pos >= c.pos);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t Circle::Cmp(const Circle & 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 Circle::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, rad);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 22:17:47 +02:00
|
|
|
void Circle::SetRadius(Value nr)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
rad = nr;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Circle::SetCircle(const Circle & nc)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos = nc.pos;
|
|
|
|
rad = nc.rad;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:32:35 +02:00
|
|
|
void Circle::SetCircleEx(Value nx, Value ny, Value nr)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:32:35 +02:00
|
|
|
pos.SetVector2Ex(nx, ny);
|
|
|
|
rad = nr;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Circle::SetValues(const Vector2 & np, Value nr)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos = np;
|
|
|
|
rad = nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:32:35 +02:00
|
|
|
void Circle::SetPosition(const Vector2 & np)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:32:35 +02:00
|
|
|
pos = np;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-07-24 23:32:35 +02:00
|
|
|
void Circle::SetPositionEx(Value nx, Value ny)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-07-24 23:09:31 +02:00
|
|
|
pos.SetVector2Ex(nx, ny);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
void Circle::SetStr(SQChar delim, StackStrF & values)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-11-16 15:18:45 +01:00
|
|
|
SetCircle(Circle::GetEx(delim, values));
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Circle & Circle::Generate()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
pos.Generate();
|
2016-02-20 23:25:00 +01:00
|
|
|
rad = GetRandomFloat32();
|
2021-03-20 16:56:38 +01:00
|
|
|
// Allow chaining
|
|
|
|
return *this;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Circle & Circle::GenerateB(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
|
|
|
{
|
2021-03-20 16:56:38 +01:00
|
|
|
pos.GenerateB(min, max);
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2021-03-20 16:56:38 +01:00
|
|
|
// Allow chaining
|
|
|
|
return *this;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Circle & Circle::GenerateR(Value xmin, Value xmax, Value ymin, Value ymax)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin))
|
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
|
|
|
|
2021-03-20 16:56:38 +01:00
|
|
|
pos.GenerateR(xmin, xmax, ymin, ymax);
|
|
|
|
// Allow chaining
|
|
|
|
return *this;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 22:17:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-03-20 16:56:38 +01:00
|
|
|
Circle & Circle::GenerateR2(Value xmin, Value xmax, Value ymin, Value ymax, 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(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
|
|
|
|
2021-03-20 16:56:38 +01:00
|
|
|
pos.GenerateR(xmin, xmax, ymin, ymax);
|
2016-03-10 04:57:13 +01:00
|
|
|
rad = GetRandomFloat32(rmin, rmax);
|
2021-03-20 16:56:38 +01:00
|
|
|
// Allow chaining
|
|
|
|
return *this;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Circle Circle::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-04-20 15:00:47 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Array Circle::ToPointsArray(SQInteger num_segments) const
|
|
|
|
{
|
|
|
|
// Allocate an array with the same amount of elements as the number of segments
|
2020-04-20 15:07:42 +02:00
|
|
|
Array arr(SqVM());
|
2020-04-20 15:00:47 +02:00
|
|
|
// Iterate the specified segments array
|
|
|
|
arr.AppendFromCounted([this](HSQUIRRELVM vm, SQInteger i, SQInteger num_segments) -> bool {
|
|
|
|
if (i >= num_segments) return false;
|
|
|
|
// Get the current angle
|
|
|
|
#ifdef SQUSEDOUBLE
|
|
|
|
SQFloat theta = 2.0d * SQMOD_PI64 * static_cast< SQFloat >(i) / static_cast< SQFloat >(num_segments);
|
|
|
|
#else
|
|
|
|
SQFloat theta = 2.0f * SQMOD_PI * static_cast< SQFloat >(i) / static_cast< SQFloat >(num_segments);
|
|
|
|
#endif // SQUSEDOUBLE
|
|
|
|
// Calculate the x component
|
2021-01-30 07:51:39 +01:00
|
|
|
SQFloat x = (rad * cosf(theta)) + pos.x;
|
2020-04-20 15:00:47 +02:00
|
|
|
// Calculate the y component
|
2021-01-30 07:51:39 +01:00
|
|
|
SQFloat y = (rad * sinf(theta)) + pos.y;
|
2020-04-20 15:00:47 +02:00
|
|
|
// Push the Vector2 instance on the stack
|
|
|
|
Var< Vector2 >::push(vm, Vector2{x, y});
|
|
|
|
// Insert the element on the stack into the array
|
|
|
|
return true;
|
|
|
|
}, num_segments);
|
|
|
|
// Return the resulted array
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2020-09-03 19:33:51 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
String Circle::Format(StackStrF & str) const
|
2020-09-03 19:33:51 +02:00
|
|
|
{
|
2021-07-03 13:09:58 +02:00
|
|
|
return fmt::format(fmt::runtime(str.ToStr())
|
2021-01-30 07:51:39 +01:00
|
|
|
, fmt::arg("x", pos.x)
|
|
|
|
, fmt::arg("y", pos.y)
|
|
|
|
, 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 Circle & Circle::Get(StackStrF & str)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
2016-11-16 15:18:45 +01:00
|
|
|
return Circle::GetEx(Circle::Delim, str);
|
2016-03-21 21:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
const Circle & Circle::GetEx(SQChar delim, StackStrF & str)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
|
|
|
static Circle circle;
|
|
|
|
// Clear previous values, if any
|
|
|
|
circle.Clear();
|
|
|
|
// Is the specified string empty?
|
2016-11-16 15:18:45 +01:00
|
|
|
if (str.mLen <= 0)
|
2016-03-21 21:37:58 +01:00
|
|
|
{
|
|
|
|
return circle; // 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 ");
|
2016-03-21 21:37:58 +01:00
|
|
|
// Assign the specified delimiter
|
|
|
|
fs[4] = delim;
|
|
|
|
fs[9] = delim;
|
|
|
|
// Attempt to extract the component values from the specified string
|
2016-11-16 15:18:45 +01:00
|
|
|
std::sscanf(str.mPtr, fs, &circle.pos.x, &circle.pos.y, &circle.rad);
|
2016-03-21 21:37:58 +01:00
|
|
|
// Return the resulted value
|
|
|
|
return circle;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ================================================================================================
|
|
|
|
void Register_Circle(HSQUIRRELVM vm)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
typedef Circle::Value Val;
|
|
|
|
|
2016-11-15 20:55:03 +01:00
|
|
|
RootTable(vm).Bind(Typename::Str,
|
|
|
|
Class< Circle >(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 Vector2 &, Val >()
|
|
|
|
.Ctor< Val, Val, Val >()
|
2016-05-22 05:20:38 +02:00
|
|
|
// Member Variables
|
2016-07-17 14:39:59 +02:00
|
|
|
.Var(_SC("pos"), &Circle::pos)
|
|
|
|
.Var(_SC("rad"), &Circle::rad)
|
2016-05-22 05:20:38 +02:00
|
|
|
.Var(_SC("Pos"), &Circle::pos)
|
|
|
|
.Var(_SC("Rad"), &Circle::rad)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Core Meta-methods
|
2016-08-24 22:17:01 +02:00
|
|
|
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Circle >, SQFloat, SQInteger, bool, std::nullptr_t, Circle >)
|
2016-11-15 20:21:15 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
|
|
|
|
.Func(_SC("_tostring"), &Circle::ToString)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Meta-methods
|
2016-08-24 22:17:01 +02:00
|
|
|
.SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Circle >, SQFloat, SQInteger, bool, std::nullptr_t, Circle >)
|
|
|
|
.SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Circle >, SQFloat, SQInteger, bool, std::nullptr_t, Circle >)
|
|
|
|
.SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< Circle >, SQFloat, SQInteger, bool, std::nullptr_t, Circle >)
|
|
|
|
.SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< Circle >, SQFloat, SQInteger, bool, std::nullptr_t, Circle >)
|
|
|
|
.SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< Circle >, SQFloat, SQInteger, bool, std::nullptr_t, Circle >)
|
2016-05-22 05:20:38 +02:00
|
|
|
.Func< Circle (Circle::*)(void) const >(_SC("_unm"), &Circle::operator -)
|
2016-07-24 22:17:47 +02:00
|
|
|
// Properties
|
|
|
|
.Prop(_SC("Abs"), &Circle::Abs)
|
|
|
|
// Member Methods
|
|
|
|
.Func(_SC("SetRadius"), &Circle::SetRadius)
|
|
|
|
.Func(_SC("SetCircle"), &Circle::SetCircle)
|
2016-07-24 23:32:35 +02:00
|
|
|
.Func(_SC("SetCircleEx"), &Circle::SetCircleEx)
|
|
|
|
.Func(_SC("SetValues"), &Circle::SetValues)
|
2016-07-24 22:17:47 +02:00
|
|
|
.Func(_SC("SetPos"), &Circle::SetPosition)
|
|
|
|
.Func(_SC("SetPosition"), &Circle::SetPosition)
|
|
|
|
.Func(_SC("SetPosEx"), &Circle::SetPositionEx)
|
|
|
|
.Func(_SC("SetPositionEx"), &Circle::SetPositionEx)
|
2016-11-16 15:18:45 +01:00
|
|
|
.FmtFunc(_SC("SetStr"), &Circle::SetStr)
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("Clear"), &Circle::Clear)
|
2020-09-03 19:33:51 +02:00
|
|
|
.FmtFunc(_SC("Format"), &Circle::Format)
|
2020-04-20 15:00:47 +02:00
|
|
|
.Func(_SC("ToPointsArray"), &Circle::ToPointsArray)
|
2016-07-24 22:17:47 +02:00
|
|
|
// Member Overloads
|
2021-03-20 16:56:38 +01:00
|
|
|
.Overload(_SC("Generate"), &Circle::Generate)
|
|
|
|
.Overload(_SC("Generate"), &Circle::GenerateB)
|
|
|
|
.Overload(_SC("Generate"), &Circle::GenerateR)
|
|
|
|
.Overload(_SC("Generate"), &Circle::GenerateR2)
|
2016-07-24 20:29:37 +02:00
|
|
|
// Static Functions
|
|
|
|
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Circle >)
|
|
|
|
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Circle >)
|
2016-11-16 15:18:45 +01:00
|
|
|
.StaticFmtFunc(_SC("FromStr"), &Circle::Get)
|
|
|
|
.StaticFmtFunc(_SC("FromStrEx"), &Circle::GetEx)
|
2015-09-30 02:56:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|