// ------------------------------------------------------------------------------------------------ #include "Base/Circle.hpp" #include "Base/Shared.hpp" #include "Library/Random.hpp" // ------------------------------------------------------------------------------------------------ namespace SqMod { // ------------------------------------------------------------------------------------------------ const Circle Circle::NIL = Circle(); const Circle Circle::MIN = Circle(0.0); const Circle Circle::MAX = Circle(NumLimit< Circle::Value >::Max); // ------------------------------------------------------------------------------------------------ SQChar Circle::Delim = ','; // ------------------------------------------------------------------------------------------------ Circle::Circle() : pos(0.0, 0.0), rad(0.0) { /* ... */ } // ------------------------------------------------------------------------------------------------ Circle::Circle(Value rv) : pos(0.0, 0.0), rad(rv) { /* ... */ } // ------------------------------------------------------------------------------------------------ Circle::Circle(const Vector2 & pv, Value rv) : pos(pv), rad(rv) { /* ... */ } // ------------------------------------------------------------------------------------------------ Circle::Circle(Value xv, Value yv, Value rv) : pos(xv, yv), rad(rv) { /* ... */ } // ------------------------------------------------------------------------------------------------ Circle::Circle(const Circle & o) : pos(o.pos), rad(o.rad) { } // ------------------------------------------------------------------------------------------------ Circle::~Circle() { /* ... */ } // ------------------------------------------------------------------------------------------------ Circle & Circle::operator = (const Circle & o) { pos = o.pos; rad = o.rad; return *this; } // ------------------------------------------------------------------------------------------------ Circle & Circle::operator = (Value r) { rad = r; return *this; } Circle & Circle::operator = (const Vector2 & p) { pos = p; return *this; } // ------------------------------------------------------------------------------------------------ Circle & Circle::operator += (const Circle & c) { pos += c.pos; rad += c.rad; return *this; } Circle & Circle::operator -= (const Circle & c) { pos -= c.pos; rad -= c.rad; return *this; } Circle & Circle::operator *= (const Circle & c) { pos *= c.pos; rad *= c.rad; return *this; } Circle & Circle::operator /= (const Circle & c) { pos /= c.pos; rad /= c.rad; return *this; } Circle & Circle::operator %= (const Circle & c) { pos %= c.pos; rad = fmod(rad, c.rad); return *this; } // ------------------------------------------------------------------------------------------------ Circle & Circle::operator += (Value r) { rad += r; return *this; } Circle & Circle::operator -= (Value r) { rad -= r; return *this; } Circle & Circle::operator *= (Value r) { rad *= r; return *this; } Circle & Circle::operator /= (Value r) { rad /= r; return *this; } Circle & Circle::operator %= (Value r) { rad = fmod(rad, r); return *this; } // ------------------------------------------------------------------------------------------------ Circle & Circle::operator += (const Vector2 & p) { pos += p; return *this; } Circle & Circle::operator -= (const Vector2 & p) { pos -= p; return *this; } Circle & Circle::operator *= (const Vector2 & p) { pos *= p; return *this; } Circle & Circle::operator /= (const Vector2 & p) { pos /= p; return *this; } Circle & Circle::operator %= (const Vector2 & p) { pos %= p; return *this; } // ------------------------------------------------------------------------------------------------ Circle & Circle::operator ++ () { ++pos; ++rad; return *this; } Circle & Circle::operator -- () { --pos; --rad; return *this; } // ------------------------------------------------------------------------------------------------ Circle Circle::operator ++ (int) { Circle state(*this); ++pos; ++rad; return state; } Circle Circle::operator -- (int) { Circle state(*this); --pos; --rad; return state; } // ------------------------------------------------------------------------------------------------ Circle Circle::operator + (const Circle & c) const { return Circle(pos + c.pos, rad + c.rad); } Circle Circle::operator - (const Circle & c) const { return Circle(pos - c.pos, rad - c.rad); } Circle Circle::operator * (const Circle & c) const { return Circle(pos * c.pos, rad * c.rad); } Circle Circle::operator / (const Circle & c) const { return Circle(pos / c.pos, rad / c.rad); } Circle Circle::operator % (const Circle & c) const { return Circle(pos % c.pos, fmod(rad, c.rad)); } // ------------------------------------------------------------------------------------------------ Circle Circle::operator + (Value r) const { return Circle(rad + r); } Circle Circle::operator - (Value r) const { return Circle(rad - r); } Circle Circle::operator * (Value r) const { return Circle(rad * r); } Circle Circle::operator / (Value r) const { return Circle(rad / r); } Circle Circle::operator % (Value r) const { return Circle(fmod(rad, r)); } // ------------------------------------------------------------------------------------------------ Circle Circle::operator + (const Vector2 & p) const { return Circle(pos + p, rad); } Circle Circle::operator - (const Vector2 & p) const { return Circle(pos - p, rad); } Circle Circle::operator * (const Vector2 & p) const { return Circle(pos * p, rad); } Circle Circle::operator / (const Vector2 & p) const { return Circle(pos / p, rad); } Circle Circle::operator % (const Vector2 & p) const { return Circle(pos % p, rad); } // ------------------------------------------------------------------------------------------------ Circle Circle::operator + () const { return Circle(pos.Abs(), fabs(rad)); } Circle Circle::operator - () const { return Circle(-pos, -rad); } // ------------------------------------------------------------------------------------------------ bool Circle::operator == (const Circle & c) const { return EpsEq(rad, c.rad) && (pos == c.pos); } bool Circle::operator != (const Circle & c) const { return !EpsEq(rad, c.rad) && (pos != c.pos); } bool Circle::operator < (const Circle & c) const { return EpsLt(rad, c.rad) && (pos < c.pos); } bool Circle::operator > (const Circle & c) const { return EpsGt(rad, c.rad) && (pos > c.pos); } bool Circle::operator <= (const Circle & c) const { return EpsLtEq(rad, c.rad) && (pos <= c.pos); } bool Circle::operator >= (const Circle & c) const { return EpsGtEq(rad, c.rad) && (pos >= c.pos); } // ------------------------------------------------------------------------------------------------ Int32 Circle::Cmp(const Circle & o) const { if (*this == o) return 0; else if (*this > o) return 1; else return -1; } // ------------------------------------------------------------------------------------------------ CSStr Circle::ToString() const { return ToStringF("%f,%f,%f", pos.x, pos.y, rad); } // ------------------------------------------------------------------------------------------------ void Circle::Set(Value nr) { rad = nr; } void Circle::Set(const Circle & nc) { pos = nc.pos; rad = nc.rad; } void Circle::Set(const Vector2 & np) { pos = np; } void Circle::Set(const Vector2 & np, Value nr) { pos = np; rad = nr; } // ------------------------------------------------------------------------------------------------ void Circle::Set(Value nx, Value ny) { pos.Set(nx, ny); } void Circle::Set(Value nx, Value ny, Value nr) { pos.Set(nx, ny); rad = nr; } // ------------------------------------------------------------------------------------------------ void Circle::Set(CSStr values, SQChar delim) { Set(GetCircle(values, delim)); } // ------------------------------------------------------------------------------------------------ void Circle::Generate() { pos.Generate(); rad = GetRandomFloat32(); } void Circle::Generate(Value min, Value max, bool r) { if (EpsLt(max, min)) { SqThrow("max value is lower than min value"); } else if (r) { rad = GetRandomFloat32(min, max); } else { pos.Generate(min, max); } } void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax) { pos.Generate(xmin, xmax, ymin, ymax); } void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin, Value rmax) { if (EpsLt(rmax, rmin)) { SqThrow("max value is lower than min value"); } else { pos.Generate(xmin, xmax, ymin, ymax); rad = GetRandomFloat32(rmin, rmax); } } // ------------------------------------------------------------------------------------------------ Circle Circle::Abs() const { return Circle(pos.Abs(), fabs(rad)); } // ================================================================================================ void Register_Circle(HSQUIRRELVM vm) { typedef Circle::Value Val; RootTable(vm).Bind(_SC("Circle"), Class< Circle >(vm, _SC("Circle")) /* Constructors */ .Ctor() .Ctor< Val >() .Ctor< const Vector2 &, Val >() .Ctor< Val, Val, Val >() /* Static Members */ .SetStaticValue(_SC("Delim"), &Circle::Delim) /* Member Variables */ .Var(_SC("pos"), &Circle::pos) .Var(_SC("rad"), &Circle::rad) /* Properties */ .Prop(_SC("abs"), &Circle::Abs) /* Core Metamethods */ .Func(_SC("_tostring"), &Circle::ToString) .Func(_SC("_cmp"), &Circle::Cmp) /* Metamethods */ .Func(_SC("_add"), &Circle::operator +) .Func(_SC("_sub"), &Circle::operator -) .Func(_SC("_mul"), &Circle::operator *) .Func(_SC("_div"), &Circle::operator /) .Func(_SC("_modulo"), &Circle::operator %) .Func(_SC("_unm"), &Circle::operator -) /* Setters */ .Overload(_SC("Set"), &Circle::Set) .Overload(_SC("Set"), &Circle::Set) .Overload(_SC("Set"), &Circle::Set) .Overload(_SC("SetRad"), &Circle::Set) .Overload(_SC("SetVec2"), &Circle::Set) .Overload(_SC("SetVec2"), &Circle::Set) .Overload(_SC("SetStr"), &Circle::Set) /* Utility Methods */ .Func(_SC("Clear"), &Circle::Clear) /* Operator Exposure */ .Func(_SC("opAddAssign"), &Circle::operator +=) .Func(_SC("opSubAssign"), &Circle::operator -=) .Func(_SC("opMulAssign"), &Circle::operator *=) .Func(_SC("opDivAssign"), &Circle::operator /=) .Func(_SC("opModAssign"), &Circle::operator %=) .Func(_SC("opAddAssignR"), &Circle::operator +=) .Func(_SC("opSubAssignR"), &Circle::operator -=) .Func(_SC("opMulAssignR"), &Circle::operator *=) .Func(_SC("opDivAssignR"), &Circle::operator /=) .Func(_SC("opModAssignR"), &Circle::operator %=) .Func(_SC("opAddAssignP"), &Circle::operator +=) .Func(_SC("opSubAssignP"), &Circle::operator -=) .Func(_SC("opMulAssignP"), &Circle::operator *=) .Func(_SC("opDivAssignP"), &Circle::operator /=) .Func(_SC("opModAssignP"), &Circle::operator %=) .Func(_SC("opPreInc"), &Circle::operator ++) .Func(_SC("opPreDec"), &Circle::operator --) .Func(_SC("opPostInc"), &Circle::operator ++) .Func(_SC("opPostDec"), &Circle::operator --) .Func(_SC("opAdd"), &Circle::operator +) .Func(_SC("opSub"), &Circle::operator -) .Func(_SC("opMul"), &Circle::operator *) .Func(_SC("opDiv"), &Circle::operator /) .Func(_SC("opMod"), &Circle::operator %) .Func(_SC("opAddR"), &Circle::operator +) .Func(_SC("opSubR"), &Circle::operator -) .Func(_SC("opMulR"), &Circle::operator *) .Func(_SC("opDivR"), &Circle::operator /) .Func(_SC("opModR"), &Circle::operator %) .Func(_SC("opAddP"), &Circle::operator +) .Func(_SC("opSubP"), &Circle::operator -) .Func(_SC("opMulP"), &Circle::operator *) .Func(_SC("opDivP"), &Circle::operator /) .Func(_SC("opModP"), &Circle::operator %) .Func(_SC("opUnPlus"), &Circle::operator +) .Func(_SC("opUnMinus"), &Circle::operator -) .Func(_SC("opEqual"), &Circle::operator ==) .Func(_SC("opNotEqual"), &Circle::operator !=) .Func(_SC("opLessThan"), &Circle::operator <) .Func(_SC("opGreaterThan"), &Circle::operator >) .Func(_SC("opLessEqual"), &Circle::operator <=) .Func(_SC("opGreaterEqual"), &Circle::operator >=) ); } } // Namespace:: SqMod