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

Initial commit.

This commit is contained in:
Sandu Liviu Catalin
2015-09-30 03:56:11 +03:00
parent 4bd8e68a7b
commit 6ed02d0fd4
118 changed files with 23795 additions and 0 deletions

492
source/Base/AABB.cpp Normal file
View File

@@ -0,0 +1,492 @@
#include "Base/AABB.hpp"
#include "Base/Vector4.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const AABB AABB::NIL = AABB(0);
const AABB AABB::MIN = AABB(-1, -1, -1, 1, 1, 1);
const AABB AABB::MAX = AABB(Vector3::MIN, Vector3::MAX);
// ------------------------------------------------------------------------------------------------
SQChar AABB::Delim = ',';
// ------------------------------------------------------------------------------------------------
AABB::AABB() noexcept
: min(-1), max(1)
{
}
AABB::AABB(Value s) noexcept
: min(-s), max(std::fabs(s))
{
}
AABB::AABB(Value xv, Value yv, Value zv) noexcept
: min(-xv, -yv, -zv), max(std::fabs(xv), std::fabs(yv), std::fabs(zv))
{
}
AABB::AABB(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) noexcept
: min(xmin, ymin, zmin), max(xmax, ymax, zmax)
{
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(const Vector3 & v) noexcept
: min(-v), max(v.Abs())
{
}
AABB::AABB(const Vector3 & vmin, const Vector3 & vmax) noexcept
: min(vmin), max(vmax)
{
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(const Vector4 & v) noexcept
: min(-v), max(v.Abs())
{
}
AABB::AABB(const Vector4 & vmin, const Vector4 & vmax) noexcept
: min(vmin), max(vmax)
{
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(const SQChar * values, SQChar delim) noexcept
: AABB(GetAABB(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(const AABB & b) noexcept
: min(b.min), max(b.max)
{
}
AABB::AABB(AABB && b) noexcept
: min(b.min), max(b.max)
{
}
// ------------------------------------------------------------------------------------------------
AABB::~AABB()
{
}
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator = (const AABB & b) noexcept
{
min = b.min;
max = b.max;
return *this;
}
AABB & AABB::operator = (AABB && b) noexcept
{
min = b.min;
max = b.max;
return *this;
}
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator = (Value s) noexcept
{
min.Set(-s);
max.Set(std::fabs(s));
return *this;
}
AABB & AABB::operator = (const Vector3 & v) noexcept
{
min.Set(-v);
max.Set(v.Abs());
return *this;
}
AABB & AABB::operator = (const Vector4 & v) noexcept
{
min.Set(-v);
max.Set(v.Abs());
return *this;
}
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator += (const AABB & b) noexcept
{
min += b.min;
max += b.max;
return *this;
}
AABB & AABB::operator -= (const AABB & b) noexcept
{
min -= b.min;
max -= b.max;
return *this;
}
AABB & AABB::operator *= (const AABB & b) noexcept
{
min *= b.min;
max *= b.max;
return *this;
}
AABB & AABB::operator /= (const AABB & b) noexcept
{
min /= b.min;
max /= b.max;
return *this;
}
AABB & AABB::operator %= (const AABB & b) noexcept
{
min %= b.min;
max %= b.max;
return *this;
}
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator += (Value s) noexcept
{
min += s;
max += s;
return *this;
}
AABB & AABB::operator -= (Value s) noexcept
{
min -= s;
max -= s;
return *this;
}
AABB & AABB::operator *= (Value s) noexcept
{
min *= s;
max *= s;
return *this;
}
AABB & AABB::operator /= (Value s) noexcept
{
min /= s;
max /= s;
return *this;
}
AABB & AABB::operator %= (Value s) noexcept
{
min %= s;
max %= s;
return *this;
}
// ------------------------------------------------------------------------------------------------
AABB & AABB::operator ++ () noexcept
{
++min;
++max;
return *this;
}
AABB & AABB::operator -- () noexcept
{
--min;
--max;
return *this;
}
// ------------------------------------------------------------------------------------------------
AABB AABB::operator ++ (int) noexcept
{
AABB state(*this);
++min;
++max;
return state;
}
AABB AABB::operator -- (int) noexcept
{
AABB state(*this);
--min;
--max;
return state;
}
// ------------------------------------------------------------------------------------------------
AABB AABB::operator + (const AABB & b) const noexcept
{
return AABB(min + b.min, max + b.max);
}
AABB AABB::operator - (const AABB & b) const noexcept
{
return AABB(min - b.min, max - b.max);
}
AABB AABB::operator * (const AABB & b) const noexcept
{
return AABB(min * b.min, max * b.max);
}
AABB AABB::operator / (const AABB & b) const noexcept
{
return AABB(min / b.min, max / b.max);
}
AABB AABB::operator % (const AABB & b) const noexcept
{
return AABB(min % b.min, max % b.max);
}
// ------------------------------------------------------------------------------------------------
AABB AABB::operator + (Value s) const noexcept
{
return AABB(min + s, max + s);
}
AABB AABB::operator - (Value s) const noexcept
{
return AABB(min - s, max - s);
}
AABB AABB::operator * (Value s) const noexcept
{
return AABB(min * s, max * s);
}
AABB AABB::operator / (Value s) const noexcept
{
return AABB(min / s, max / s);
}
AABB AABB::operator % (Value s) const noexcept
{
return AABB(min % s, max % s);
}
// ------------------------------------------------------------------------------------------------
AABB AABB::operator + () const noexcept
{
return AABB(min.Abs(), max.Abs());
}
AABB AABB::operator - () const noexcept
{
return AABB(-min, -max);
}
// ------------------------------------------------------------------------------------------------
bool AABB::operator == (const AABB & b) const noexcept
{
return (min == b.min) && (max == b.max);
}
bool AABB::operator != (const AABB & b) const noexcept
{
return (min != b.min) && (max != b.max);
}
bool AABB::operator < (const AABB & b) const noexcept
{
return (min < b.min) && (max < b.max);
}
bool AABB::operator > (const AABB & b) const noexcept
{
return (min > b.min) && (max > b.max);
}
bool AABB::operator <= (const AABB & b) const noexcept
{
return (min <= b.min) && (max <= b.max);
}
bool AABB::operator >= (const AABB & b) const noexcept
{
return (min >= b.min) && (max >= b.max);
}
// ------------------------------------------------------------------------------------------------
SQInteger AABB::Cmp(const AABB & b) const noexcept
{
return *this == b ? 0 : (*this > b ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * AABB::ToString() const noexcept
{
return ToStringF("%f,%f,%f,%f,%f,%f", min.x, min.y, min.z, max.x, max.y, max.z);
}
// ------------------------------------------------------------------------------------------------
void AABB::Set(Value ns) noexcept
{
min = -ns;
max = std::fabs(ns);
}
void AABB::Set(Value nx, Value ny, Value nz) noexcept
{
min.Set(-nx, -ny, -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) noexcept
{
min.Set(xmin, ymin, zmin);
max.Set(xmax, ymax, zmax);
}
// ------------------------------------------------------------------------------------------------
void AABB::Set(const AABB & b) noexcept
{
min = b.min;
max = b.max;
}
// ------------------------------------------------------------------------------------------------
void AABB::Set(const Vector3 & v) noexcept
{
min = -v;
max = v.Abs();
}
void AABB::Set(const Vector3 & nmin, const Vector3 & nmax) noexcept
{
min = nmin;
max = nmax;
}
// ------------------------------------------------------------------------------------------------
void AABB::Set(const Vector4 & v) noexcept
{
min = -v;
max = v.Abs();
}
void AABB::Set(const Vector4 & nmin, const Vector4 & nmax) noexcept
{
min = nmin;
max = nmax;
}
// ------------------------------------------------------------------------------------------------
void AABB::Set(const SQChar * values, SQChar delim) noexcept
{
Set(GetAABB(values, delim));
}
// ------------------------------------------------------------------------------------------------
AABB AABB::Abs() const noexcept
{
return AABB(min.Abs(), max.Abs());
}
// ================================================================================================
bool Register_AABB(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <AABB> type");
typedef AABB::Value Val;
Sqrat::RootTable(vm).Bind(_SC("AABB"), Sqrat::Class<AABB>(vm, _SC("AABB"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<Val, Val, Val, Val, Val, Val>()
.Ctor<const Vector3 &, const Vector3 &>()
.SetStaticValue(_SC("delim"), &AABB::Delim)
.Var(_SC("min"), &AABB::min)
.Var(_SC("max"), &AABB::max)
.Prop(_SC("abs"), &AABB::Abs)
.Func(_SC("_tostring"), &AABB::ToString)
.Func(_SC("_cmp"), &AABB::Cmp)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_add"), &AABB::operator +)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_sub"), &AABB::operator -)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_mul"), &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::*)(void) const>(_SC("_unm"), &AABB::operator -)
.Overload<void (AABB::*)(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::*)(const AABB &)>(_SC("set_box"), &AABB::Set)
.Overload<void (AABB::*)(const Vector3 &)>(_SC("set_vec3"), &AABB::Set)
.Overload<void (AABB::*)(const Vector3 &, const Vector3 &)>(_SC("set_vec3"), &AABB::Set)
.Overload<void (AABB::*)(const Vector4 &)>(_SC("set_vec4"), &AABB::Set)
.Overload<void (AABB::*)(const Vector4 &, const Vector4 &)>(_SC("set_vec4"), &AABB::Set)
.Overload<void (AABB::*)(const SQChar *, SQChar)>(_SC("set_str"), &AABB::Set)
.Func(_SC("clear"), &AABB::Clear)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opAddAssign"), &AABB::operator +=)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opSubAssign"), &AABB::operator -=)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opMulAssign"), &AABB::operator *=)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opDivAssign"), &AABB::operator /=)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opModAssign"), &AABB::operator %=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opAddAssignS"), &AABB::operator +=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opSubAssignS"), &AABB::operator -=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opMulAssignS"), &AABB::operator *=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opDivAssignS"), &AABB::operator /=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opModAssignS"), &AABB::operator %=)
.Func<AABB & (AABB::*)(void)>(_SC("opPreInc"), &AABB::operator ++)
.Func<AABB & (AABB::*)(void)>(_SC("opPreDec"), &AABB::operator --)
.Func<AABB (AABB::*)(int)>(_SC("opPostInc"), &AABB::operator ++)
.Func<AABB (AABB::*)(int)>(_SC("opPostDec"), &AABB::operator --)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opAdd"), &AABB::operator +)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opAddS"), &AABB::operator +)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opSub"), &AABB::operator -)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opSubS"), &AABB::operator -)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opMul"), &AABB::operator *)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opMulS"), &AABB::operator *)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opDiv"), &AABB::operator /)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opDivS"), &AABB::operator /)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opMod"), &AABB::operator %)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opModS"), &AABB::operator %)
.Func<AABB (AABB::*)(void) const>(_SC("opUnPlus"), &AABB::operator +)
.Func<AABB (AABB::*)(void) const>(_SC("opUnMinus"), &AABB::operator -)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opEqual"), &AABB::operator ==)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opNotEqual"), &AABB::operator !=)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opLessThan"), &AABB::operator <)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterThan"), &AABB::operator >)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opLessEqual"), &AABB::operator <=)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterEqual"), &AABB::operator >=)
);
LogDbg("Registration of <AABB> type was successful");
return true;
}
} // Namespace:: SqMod

117
source/Base/AABB.hpp Normal file
View File

@@ -0,0 +1,117 @@
#ifndef _BASE_AABB_HPP_
#define _BASE_AABB_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "Base/Vector3.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct AABB
{
// --------------------------------------------------------------------------------------------
typedef SQFloat Value;
// --------------------------------------------------------------------------------------------
static const AABB NIL;
static const AABB MIN;
static const AABB MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Vector3 min, max;
// --------------------------------------------------------------------------------------------
AABB() noexcept;
AABB(Value s) noexcept;
AABB(Value x, Value y, Value z) noexcept;
AABB(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) noexcept;
// --------------------------------------------------------------------------------------------
AABB(const Vector3 & b) noexcept;
AABB(const Vector3 & vmin, const Vector3 & vmax) noexcept;
// --------------------------------------------------------------------------------------------
AABB(const Vector4 & b) noexcept;
AABB(const Vector4 & vmin, const Vector4 & vmax) noexcept;
// --------------------------------------------------------------------------------------------
AABB(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
AABB(const AABB & b) noexcept;
AABB(AABB && b) noexcept;
// --------------------------------------------------------------------------------------------
~AABB();
// --------------------------------------------------------------------------------------------
AABB & operator = (const AABB & b) noexcept;
AABB & operator = (AABB && b) noexcept;
// --------------------------------------------------------------------------------------------
AABB & operator = (Value s) noexcept;
AABB & operator = (const Vector3 & v) noexcept;
AABB & operator = (const Vector4 & v) noexcept;
// --------------------------------------------------------------------------------------------
AABB & operator += (const AABB & b) noexcept;
AABB & operator -= (const AABB & b) noexcept;
AABB & operator *= (const AABB & b) noexcept;
AABB & operator /= (const AABB & b) noexcept;
AABB & operator %= (const AABB & b) noexcept;
// --------------------------------------------------------------------------------------------
AABB & operator += (Value s) noexcept;
AABB & operator -= (Value s) noexcept;
AABB & operator *= (Value s) noexcept;
AABB & operator /= (Value s) noexcept;
AABB & operator %= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
AABB & operator ++ () noexcept;
AABB & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
AABB operator ++ (int) noexcept;
AABB operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
AABB operator + (const AABB & b) const noexcept;
AABB operator - (const AABB & b) const noexcept;
AABB operator * (const AABB & b) const noexcept;
AABB operator / (const AABB & b) const noexcept;
AABB operator % (const AABB & b) const noexcept;
// --------------------------------------------------------------------------------------------
AABB operator + (Value s) const noexcept;
AABB operator - (Value s) const noexcept;
AABB operator * (Value s) const noexcept;
AABB operator / (Value s) const noexcept;
AABB operator % (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
AABB operator + () const noexcept;
AABB operator - () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const AABB & b) const noexcept;
bool operator != (const AABB & b) const noexcept;
bool operator < (const AABB & b) const noexcept;
bool operator > (const AABB & b) const noexcept;
bool operator <= (const AABB & b) const noexcept;
bool operator >= (const AABB & b) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const AABB & b) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nx, Value ny, Value nz) noexcept;
void Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const AABB & b) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Vector3 & v) noexcept;
void Set(const Vector3 & nmin, const Vector3 & nmax) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Vector4 & v) noexcept;
void Set(const Vector4 & nmin, const Vector4 & nmax) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { min.Clear(); max.Clear(); }
// --------------------------------------------------------------------------------------------
AABB Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_AABB_HPP_

542
source/Base/Circle.cpp Normal file
View File

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

123
source/Base/Circle.hpp Normal file
View File

@@ -0,0 +1,123 @@
#ifndef _BASE_CIRCLE_HPP_
#define _BASE_CIRCLE_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "Base/Vector2f.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Circle
{
// --------------------------------------------------------------------------------------------
typedef SQFloat Value;
// --------------------------------------------------------------------------------------------
static const Circle NIL;
static const Circle MIN;
static const Circle MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Vector2f pos;
Value rad;
// --------------------------------------------------------------------------------------------
Circle() noexcept;
Circle(Value r) noexcept;
Circle(const Vector2f & p) noexcept;
Circle(const Vector2f & p, Value r) noexcept;
Circle(Value x, Value y, Value r) noexcept;
// --------------------------------------------------------------------------------------------
Circle(const Circle & c) noexcept;
Circle(Circle && c) noexcept;
// --------------------------------------------------------------------------------------------
~Circle();
// --------------------------------------------------------------------------------------------
Circle & operator = (const Circle & c) noexcept;
Circle & operator = (Circle && c) noexcept;
// --------------------------------------------------------------------------------------------
Circle & operator = (Value r) noexcept;
Circle & operator = (const Vector2f & p) noexcept;
// --------------------------------------------------------------------------------------------
Circle & operator += (const Circle & c) noexcept;
Circle & operator -= (const Circle & c) noexcept;
Circle & operator *= (const Circle & c) noexcept;
Circle & operator /= (const Circle & c) noexcept;
Circle & operator %= (const Circle & c) noexcept;
// --------------------------------------------------------------------------------------------
Circle & operator += (Value r) noexcept;
Circle & operator -= (Value r) noexcept;
Circle & operator *= (Value r) noexcept;
Circle & operator /= (Value r) noexcept;
Circle & operator %= (Value r) noexcept;
// --------------------------------------------------------------------------------------------
Circle & operator += (const Vector2f & p) noexcept;
Circle & operator -= (const Vector2f & p) noexcept;
Circle & operator *= (const Vector2f & p) noexcept;
Circle & operator /= (const Vector2f & p) noexcept;
Circle & operator %= (const Vector2f & p) noexcept;
// --------------------------------------------------------------------------------------------
Circle & operator ++ () noexcept;
Circle & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Circle operator ++ (int) noexcept;
Circle operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Circle operator + (const Circle & c) const noexcept;
Circle operator - (const Circle & c) const noexcept;
Circle operator * (const Circle & c) const noexcept;
Circle operator / (const Circle & c) const noexcept;
Circle operator % (const Circle & c) const noexcept;
// --------------------------------------------------------------------------------------------
Circle operator + (Value r) const noexcept;
Circle operator - (Value r) const noexcept;
Circle operator * (Value r) const noexcept;
Circle operator / (Value r) const noexcept;
Circle operator % (Value r) const noexcept;
// --------------------------------------------------------------------------------------------
Circle operator + (const Vector2f & p) const noexcept;
Circle operator - (const Vector2f & p) const noexcept;
Circle operator * (const Vector2f & p) const noexcept;
Circle operator / (const Vector2f & p) const noexcept;
Circle operator % (const Vector2f & p) const noexcept;
// --------------------------------------------------------------------------------------------
Circle operator + () const noexcept;
Circle operator - () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Circle & c) const noexcept;
bool operator != (const Circle & c) const noexcept;
bool operator < (const Circle & c) const noexcept;
bool operator > (const Circle & c) const noexcept;
bool operator <= (const Circle & c) const noexcept;
bool operator >= (const Circle & c) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Circle & c) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value nr) noexcept;
void Set(const Circle & nc) noexcept;
void Set(const Vector2f & np) noexcept;
void Set(const Vector2f & np, Value nr) noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value nx, Value ny) noexcept;
void Set(Value nx, Value ny, Value nr) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max, bool r) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin, Value rmax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { pos.Clear(); rad = 0.0; }
// --------------------------------------------------------------------------------------------
Circle Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_CIRCLE_HPP_

720
source/Base/Color3.cpp Normal file
View File

@@ -0,0 +1,720 @@
#include "Base/Color3.hpp"
#include "Base/Color4.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Color3 Color3::NIL = Color3();
const Color3 Color3::MIN = Color3(std::numeric_limits<Color3::Value>::min());
const Color3 Color3::MAX = Color3(std::numeric_limits<Color3::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Color3::Delim = ',';
// ------------------------------------------------------------------------------------------------
Color3::Color3() noexcept
: r(0), g(0), b(0)
{
}
Color3::Color3(Value s) noexcept
: r(s), g(s), b(s)
{
}
Color3::Color3(Value rv, Value gv, Value bv) noexcept
: r(rv), g(gv), b(bv)
{
}
// ------------------------------------------------------------------------------------------------
Color3::Color3(const Color4 & c) noexcept
: r(c.r), g(c.g), b(c.b)
{
}
// ------------------------------------------------------------------------------------------------
Color3::Color3(const SQChar * name) noexcept
: Color3(GetColor(name))
{
}
Color3::Color3(const SQChar * str, SQChar delim) noexcept
: Color3(GetColor3(str, delim))
{
}
// ------------------------------------------------------------------------------------------------
Color3::Color3(const Color3 & c) noexcept
: r(c.r), g(c.g), b(c.b)
{
}
Color3::Color3(Color3 && c) noexcept
: r(c.r), g(c.g), b(c.b)
{
}
// ------------------------------------------------------------------------------------------------
Color3::~Color3()
{
}
// ------------------------------------------------------------------------------------------------
Color3 & Color3::operator = (const Color3 & c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
return *this;
}
Color3 & Color3::operator = (Color3 && c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color3 & Color3::operator = (Value s) noexcept
{
r = s;
g = s;
b = s;
return *this;
}
Color3 & Color3::operator = (const SQChar * name) noexcept
{
Set(GetColor(name));
return *this;
}
Color3 & Color3::operator = (const Color4 & c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color3 & Color3::operator += (const Color3 & c) noexcept
{
r += c.r;
g += c.g;
b += c.b;
return *this;
}
Color3 & Color3::operator -= (const Color3 & c) noexcept
{
r -= c.r;
g -= c.g;
b -= c.b;
return *this;
}
Color3 & Color3::operator *= (const Color3 & c) noexcept
{
r *= c.r;
g *= c.g;
b *= c.b;
return *this;
}
Color3 & Color3::operator /= (const Color3 & c) noexcept
{
r /= c.r;
g /= c.g;
b /= c.b;
return *this;
}
Color3 & Color3::operator %= (const Color3 & c) noexcept
{
r %= c.r;
g %= c.g;
b %= c.b;
return *this;
}
Color3 & Color3::operator &= (const Color3 & c) noexcept
{
r &= c.r;
g &= c.g;
b &= c.b;
return *this;
}
Color3 & Color3::operator |= (const Color3 & c) noexcept
{
r |= c.r;
g |= c.g;
b |= c.b;
return *this;
}
Color3 & Color3::operator ^= (const Color3 & c) noexcept
{
r ^= c.r;
g ^= c.g;
b ^= c.b;
return *this;
}
Color3 & Color3::operator <<= (const Color3 & c) noexcept
{
r <<= c.r;
g <<= c.g;
b <<= c.b;
return *this;
}
Color3 & Color3::operator >>= (const Color3 & c) noexcept
{
r >>= c.r;
g >>= c.g;
b >>= c.b;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color3 & Color3::operator += (Value s) noexcept
{
r += s;
g += s;
b += s;
return *this;
}
Color3 & Color3::operator -= (Value s) noexcept
{
r -= s;
g -= s;
b -= s;
return *this;
}
Color3 & Color3::operator *= (Value s) noexcept
{
r *= s;
g *= s;
b *= s;
return *this;
}
Color3 & Color3::operator /= (Value s) noexcept
{
r /= s;
g /= s;
b /= s;
return *this;
}
Color3 & Color3::operator %= (Value s) noexcept
{
r %= s;
g %= s;
b %= s;
return *this;
}
Color3 & Color3::operator &= (Value s) noexcept
{
r &= s;
g &= s;
b &= s;
return *this;
}
Color3 & Color3::operator |= (Value s) noexcept
{
r |= s;
g |= s;
b |= s;
return *this;
}
Color3 & Color3::operator ^= (Value s) noexcept
{
r ^= s;
g ^= s;
b ^= s;
return *this;
}
Color3 & Color3::operator <<= (Value s) noexcept
{
r <<= s;
g <<= s;
b <<= s;
return *this;
}
Color3 & Color3::operator >>= (Value s) noexcept
{
r >>= s;
g >>= s;
b >>= s;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color3 & Color3::operator ++ () noexcept
{
++r;
++g;
++b;
return *this;
}
Color3 & Color3::operator -- () noexcept
{
--r;
--g;
--b;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color3 Color3::operator ++ (int) noexcept
{
Color3 state(*this);
++r;
++g;
++b;
return state;
}
Color3 Color3::operator -- (int) noexcept
{
Color3 state(*this);
--r;
--g;
--b;
return state;
}
// ------------------------------------------------------------------------------------------------
Color3 Color3::operator + (const Color3 & c) const noexcept
{
return Color3(r + c.r, g + c.g, b + c.b);
}
Color3 Color3::operator - (const Color3 & c) const noexcept
{
return Color3(r - c.r, g - c.g, b - c.b);
}
Color3 Color3::operator * (const Color3 & c) const noexcept
{
return Color3(r * c.r, g * c.g, b * c.b);
}
Color3 Color3::operator / (const Color3 & c) const noexcept
{
return Color3(r / c.r, g / c.g, b / c.b);
}
Color3 Color3::operator % (const Color3 & c) const noexcept
{
return Color3(r % c.r, g % c.g, b % c.b);
}
Color3 Color3::operator & (const Color3 & c) const noexcept
{
return Color3(r & c.r, g & c.g, b & c.b);
}
Color3 Color3::operator | (const Color3 & c) const noexcept
{
return Color3(r | c.r, g | c.g, b | c.b);
}
Color3 Color3::operator ^ (const Color3 & c) const noexcept
{
return Color3(r ^ c.r, g ^ c.g, b ^ c.b);
}
Color3 Color3::operator << (const Color3 & c) const noexcept
{
return Color3(r << c.r, g << c.g, b << c.b);
}
Color3 Color3::operator >> (const Color3 & c) const noexcept
{
return Color3(r >> c.r, g >> c.g, b >> c.b);
}
// ------------------------------------------------------------------------------------------------
Color3 Color3::operator + (Value s) const noexcept
{
return Color3(r + s, g + s, b + s);
}
Color3 Color3::operator - (Value s) const noexcept
{
return Color3(r - s, g - s, b - s);
}
Color3 Color3::operator * (Value s) const noexcept
{
return Color3(r * s, g * s, b * s);
}
Color3 Color3::operator / (Value s) const noexcept
{
return Color3(r / s, g / s, b / s);
}
Color3 Color3::operator % (Value s) const noexcept
{
return Color3(r % s, g % s, b % s);
}
Color3 Color3::operator & (Value s) const noexcept
{
return Color3(r & s, g & s, b & s);
}
Color3 Color3::operator | (Value s) const noexcept
{
return Color3(r | s, g | s, b | s);
}
Color3 Color3::operator ^ (Value s) const noexcept
{
return Color3(r ^ s, g ^ s, b ^ s);
}
Color3 Color3::operator << (Value s) const noexcept
{
return Color3(r << s, g << s, b << s);
}
Color3 Color3::operator >> (Value s) const noexcept
{
return Color3(r >> s, g >> s, b >> s);
}
// ------------------------------------------------------------------------------------------------
Color3 Color3::operator + () const noexcept
{
return Color3(r, g, b);
}
Color3 Color3::operator - () const noexcept
{
return Color3(0, 0, 0);
}
// ------------------------------------------------------------------------------------------------
Color3 Color3::operator ~ () const noexcept
{
return Color3(~r, ~g, ~b);
}
// ------------------------------------------------------------------------------------------------
bool Color3::operator == (const Color3 & c) const noexcept
{
return (r == c.r) && (g == c.g) && (b == c.b);
}
bool Color3::operator != (const Color3 & c) const noexcept
{
return (r != c.r) && (g != c.g) && (b != c.b);
}
bool Color3::operator < (const Color3 & c) const noexcept
{
return (r < c.r) && (g < c.g) && (b < c.b);
}
bool Color3::operator > (const Color3 & c) const noexcept
{
return (r > c.r) && (g > c.g) && (b > c.b);
}
bool Color3::operator <= (const Color3 & c) const noexcept
{
return (r <= c.r) && (g <= c.g) && (b <= c.b);
}
bool Color3::operator >= (const Color3 & c) const noexcept
{
return (r >= c.r) && (g >= c.g) && (b >= c.b);
}
// ------------------------------------------------------------------------------------------------
SQInteger Color3::Cmp(const Color3 & c) const noexcept
{
return *this == c ? 0 : (*this > c ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Color3::ToString() const noexcept
{
return ToStringF("%u,%u,%u", r, g, b);
}
// ------------------------------------------------------------------------------------------------
void Color3::Set(Value ns) noexcept
{
r = ns;
g = ns;
b = ns;
}
void Color3::Set(Value nr, Value ng, Value nb) noexcept
{
r = nr;
g = ng;
b = nb;
}
// ------------------------------------------------------------------------------------------------
void Color3::Set(const Color3 & c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
}
void Color3::Set(const Color4 & c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
}
// ------------------------------------------------------------------------------------------------
void Color3::Set(const SQChar * str, SQChar delim) noexcept
{
Set(GetColor3(str, delim));
}
// ------------------------------------------------------------------------------------------------
void Color3::SetCol(const SQChar * name) noexcept
{
Set(GetColor(name));
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color3::GetRGB() const noexcept
{
return static_cast<SQUint32>(r << 16 | g << 8 | b);
}
void Color3::SetRGB(SQUint32 p) noexcept
{
r = static_cast<Value>((p >> 16) & 0xFF);
g = static_cast<Value>((p >> 8) & 0xFF);
b = static_cast<Value>((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color3::GetRGBA() const noexcept
{
return static_cast<SQUint32>(r << 24 | g << 16 | b << 8 | 0x00);
}
void Color3::SetRGBA(SQUint32 p) noexcept
{
r = static_cast<Value>((p >> 24) & 0xFF);
g = static_cast<Value>((p >> 16) & 0xFF);
b = static_cast<Value>((p >> 8) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color3::GetARGB() const noexcept
{
return static_cast<SQUint32>(0x00 << 24 | r << 16 | g << 8 | b);
}
void Color3::SetARGB(SQUint32 p) noexcept
{
r = static_cast<Value>((p >> 16) & 0xFF);
g = static_cast<Value>((p >> 8) & 0xFF);
b = static_cast<Value>((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
void Color3::Generate() noexcept
{
r = RandomVal<Value>::Get();
g = RandomVal<Value>::Get();
b = RandomVal<Value>::Get();
}
void Color3::Generate(Value min, Value max) noexcept
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
r = RandomVal<Value>::Get(min, max);
g = RandomVal<Value>::Get(min, max);
b = RandomVal<Value>::Get(min, max);
}
}
void Color3::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax) noexcept
{
if (rmax < rmin || gmax < gmin || bmax < bmin)
{
LogErr("max value is lower than min value");
}
else
{
r = RandomVal<Value>::Get(rmin, rmax);
g = RandomVal<Value>::Get(gmin, gmax);
b = RandomVal<Value>::Get(bmin, bmax);
}
}
// ------------------------------------------------------------------------------------------------
void Color3::Random() noexcept
{
Set(GetRandomColor());
}
// ------------------------------------------------------------------------------------------------
void Color3::Inverse() noexcept
{
r = static_cast<Value>(~r);
g = static_cast<Value>(~g);
b = static_cast<Value>(~b);
}
// ================================================================================================
bool Register_Color3(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Color3> type");
typedef Color3::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Color3"), Sqrat::Class<Color3>(vm, _SC("Color3"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Color3::Delim)
.Var(_SC("r"), &Color3::r)
.Var(_SC("g"), &Color3::g)
.Var(_SC("b"), &Color3::b)
.Prop(_SC("rgb"), &Color3::GetRGB, &Color3::SetRGB)
.Prop(_SC("rgba"), &Color3::GetRGBA, &Color3::SetRGBA)
.Prop(_SC("argb"), &Color3::GetARGB, &Color3::SetARGB)
.Prop(_SC("str"), &Color3::SetCol)
.Func(_SC("_tostring"), &Color3::ToString)
.Func(_SC("_cmp"), &Color3::Cmp)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_add"), &Color3::operator +)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_sub"), &Color3::operator -)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_mul"), &Color3::operator *)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_div"), &Color3::operator /)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_modulo"), &Color3::operator %)
.Func<Color3 (Color3::*)(void) const>(_SC("_unm"), &Color3::operator -)
.Overload<void (Color3::*)(Val)>(_SC("set"), &Color3::Set)
.Overload<void (Color3::*)(Val, Val, Val)>(_SC("set"), &Color3::Set)
.Overload<void (Color3::*)(const Color3 &)>(_SC("set_col3"), &Color3::Set)
.Overload<void (Color3::*)(const Color4 &)>(_SC("set_col4"), &Color3::Set)
.Overload<void (Color3::*)(const SQChar *, SQChar)>(_SC("set_str"), &Color3::Set)
.Overload<void (Color3::*)(void)>(_SC("generate"), &Color3::Generate)
.Overload<void (Color3::*)(Val, Val)>(_SC("generate"), &Color3::Generate)
.Overload<void (Color3::*)(Val, Val, Val, Val, Val, Val)>(_SC("generate"), &Color3::Generate)
.Func(_SC("clear"), &Color3::Clear)
.Func(_SC("random"), &Color3::Random)
.Func(_SC("inverse"), &Color3::Inverse)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opAddAssign"), &Color3::operator +=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opSubAssign"), &Color3::operator -=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opMulAssign"), &Color3::operator *=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opDivAssign"), &Color3::operator /=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opModAssign"), &Color3::operator %=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opAndAssign"), &Color3::operator &=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opOrAssign"), &Color3::operator |=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opXorAssign"), &Color3::operator ^=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opShlAssign"), &Color3::operator <<=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opShrAssign"), &Color3::operator >>=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opAddAssignS"), &Color3::operator +=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opSubAssignS"), &Color3::operator -=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opMulAssignS"), &Color3::operator *=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opDivAssignS"), &Color3::operator /=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opModAssignS"), &Color3::operator %=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opAndAssignS"), &Color3::operator &=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opOrAssignS"), &Color3::operator |=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opXorAssignS"), &Color3::operator ^=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opShlAssignS"), &Color3::operator <<=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opShrAssignS"), &Color3::operator >>=)
.Func<Color3 & (Color3::*)(void)>(_SC("opPreInc"), &Color3::operator ++)
.Func<Color3 & (Color3::*)(void)>(_SC("opPreDec"), &Color3::operator --)
.Func<Color3 (Color3::*)(int)>(_SC("opPostInc"), &Color3::operator ++)
.Func<Color3 (Color3::*)(int)>(_SC("opPostDec"), &Color3::operator --)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opAdd"), &Color3::operator +)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opSub"), &Color3::operator -)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opMul"), &Color3::operator *)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opDiv"), &Color3::operator /)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opMod"), &Color3::operator %)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opAnd"), &Color3::operator &)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opOr"), &Color3::operator |)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShl"), &Color3::operator ^)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShl"), &Color3::operator <<)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShr"), &Color3::operator >>)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opAddS"), &Color3::operator +)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opSubS"), &Color3::operator -)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opMulS"), &Color3::operator *)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opDivS"), &Color3::operator /)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opModS"), &Color3::operator %)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opAndS"), &Color3::operator &)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opOrS"), &Color3::operator |)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShlS"), &Color3::operator ^)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShlS"), &Color3::operator <<)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShrS"), &Color3::operator >>)
.Func<Color3 (Color3::*)(void) const>(_SC("opUnPlus"), &Color3::operator +)
.Func<Color3 (Color3::*)(void) const>(_SC("opUnMinus"), &Color3::operator -)
.Func<Color3 (Color3::*)(void) const>(_SC("opCom"), &Color3::operator ~)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opEqual"), &Color3::operator ==)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opNotEqual"), &Color3::operator !=)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessThan"), &Color3::operator <)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterThan"), &Color3::operator >)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessEqual"), &Color3::operator <=)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterEqual"), &Color3::operator >=)
);
LogDbg("Registration of <Color3> type was successful");
return true;
}
} // Namespace:: SqMod

145
source/Base/Color3.hpp Normal file
View File

@@ -0,0 +1,145 @@
#ifndef _BASE_COLOR3_HPP_
#define _BASE_COLOR3_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Color3
{
// --------------------------------------------------------------------------------------------
typedef Uint8 Value;
// --------------------------------------------------------------------------------------------
static const Color3 NIL;
static const Color3 MIN;
static const Color3 MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Value r, g, b;
// --------------------------------------------------------------------------------------------
Color3() noexcept;
Color3(Value s) noexcept;
Color3(Value r, Value g, Value b) noexcept;
// --------------------------------------------------------------------------------------------
Color3(const Color4 & c) noexcept;
// --------------------------------------------------------------------------------------------
Color3(const SQChar * name) noexcept;
Color3(const SQChar * str, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
Color3(const Color3 & c) noexcept;
Color3(Color3 && c) noexcept;
// --------------------------------------------------------------------------------------------
~Color3();
// --------------------------------------------------------------------------------------------
Color3 & operator = (const Color3 & c) noexcept;
Color3 & operator = (Color3 && c) noexcept;
// --------------------------------------------------------------------------------------------
Color3 & operator = (Value s) noexcept;
Color3 & operator = (const SQChar * name) noexcept;
Color3 & operator = (const Color4 & c) noexcept;
// --------------------------------------------------------------------------------------------
Color3 & operator += (const Color3 & c) noexcept;
Color3 & operator -= (const Color3 & c) noexcept;
Color3 & operator *= (const Color3 & c) noexcept;
Color3 & operator /= (const Color3 & c) noexcept;
Color3 & operator %= (const Color3 & c) noexcept;
Color3 & operator &= (const Color3 & c) noexcept;
Color3 & operator |= (const Color3 & c) noexcept;
Color3 & operator ^= (const Color3 & c) noexcept;
Color3 & operator <<= (const Color3 & c) noexcept;
Color3 & operator >>= (const Color3 & c) noexcept;
// --------------------------------------------------------------------------------------------
Color3 & operator += (Value s) noexcept;
Color3 & operator -= (Value s) noexcept;
Color3 & operator *= (Value s) noexcept;
Color3 & operator /= (Value s) noexcept;
Color3 & operator %= (Value s) noexcept;
Color3 & operator &= (Value s) noexcept;
Color3 & operator |= (Value s) noexcept;
Color3 & operator ^= (Value s) noexcept;
Color3 & operator <<= (Value s) noexcept;
Color3 & operator >>= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
Color3 & operator ++ () noexcept;
Color3 & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Color3 operator ++ (int) noexcept;
Color3 operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Color3 operator + (const Color3 & c) const noexcept;
Color3 operator - (const Color3 & c) const noexcept;
Color3 operator * (const Color3 & c) const noexcept;
Color3 operator / (const Color3 & c) const noexcept;
Color3 operator % (const Color3 & c) const noexcept;
Color3 operator & (const Color3 & c) const noexcept;
Color3 operator | (const Color3 & c) const noexcept;
Color3 operator ^ (const Color3 & c) const noexcept;
Color3 operator << (const Color3 & c) const noexcept;
Color3 operator >> (const Color3 & c) const noexcept;
// --------------------------------------------------------------------------------------------
Color3 operator + (Value s) const noexcept;
Color3 operator - (Value s) const noexcept;
Color3 operator * (Value s) const noexcept;
Color3 operator / (Value s) const noexcept;
Color3 operator % (Value s) const noexcept;
Color3 operator & (Value s) const noexcept;
Color3 operator | (Value s) const noexcept;
Color3 operator ^ (Value s) const noexcept;
Color3 operator << (Value s) const noexcept;
Color3 operator >> (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Color3 operator + () const noexcept;
Color3 operator - () const noexcept;
// --------------------------------------------------------------------------------------------
Color3 operator ~ () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Color3 & c) const noexcept;
bool operator != (const Color3 & c) const noexcept;
bool operator < (const Color3 & c) const noexcept;
bool operator > (const Color3 & c) const noexcept;
bool operator <= (const Color3 & c) const noexcept;
bool operator >= (const Color3 & c) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Color3 & c) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nr, Value ng, Value nb) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Color3 & c) noexcept;
void Set(const Color4 & c) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * str, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void SetCol(const SQChar * name) noexcept;
// --------------------------------------------------------------------------------------------
SQUint32 GetRGB() const noexcept;
void SetRGB(SQUint32 p) noexcept;
// --------------------------------------------------------------------------------------------
SQUint32 GetRGBA() const noexcept;
void SetRGBA(SQUint32 p) noexcept;
// --------------------------------------------------------------------------------------------
SQUint32 GetARGB() const noexcept;
void SetARGB(SQUint32 p) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max) noexcept;
void Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { r = 0, g = 0, b = 0; }
// --------------------------------------------------------------------------------------------
void Random() noexcept;
// --------------------------------------------------------------------------------------------
void Inverse() noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_COLOR3_HPP_

773
source/Base/Color4.cpp Normal file
View File

@@ -0,0 +1,773 @@
#include "Base/Color4.hpp"
#include "Base/Color3.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Color4 Color4::NIL = Color4();
const Color4 Color4::MIN = Color4(std::numeric_limits<Color4::Value>::min());
const Color4 Color4::MAX = Color4(std::numeric_limits<Color4::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Color4::Delim = ',';
// ------------------------------------------------------------------------------------------------
Color4::Color4() noexcept
: r(0), g(0), b(0), a(0)
{
}
Color4::Color4(Value s) noexcept
: r(s), g(s), b(s), a(s)
{
}
Color4::Color4(Value rv, Value gv, Value bv) noexcept
: r(rv), g(gv), b(bv), a(0)
{
}
Color4::Color4(Value rv, Value gv, Value bv, Value av) noexcept
: r(rv), g(gv), b(bv), a(av)
{
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(const Color3 & c) noexcept
: r(c.r), g(c.g), b(c.b), a(0)
{
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(const SQChar * name) noexcept
: Color4(GetColor(name))
{
}
Color4::Color4(const SQChar * str, SQChar delim) noexcept
: Color4(GetColor4(str, delim))
{
}
// ------------------------------------------------------------------------------------------------
Color4::Color4(const Color4 & c) noexcept
: r(c.r), g(c.g), b(c.b), a(c.a)
{
}
Color4::Color4(Color4 && c) noexcept
: r(c.r), g(c.g), b(c.b), a(c.a)
{
}
// ------------------------------------------------------------------------------------------------
Color4::~Color4()
{
}
// ------------------------------------------------------------------------------------------------
Color4 & Color4::operator = (const Color4 & c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
return *this;
}
Color4 & Color4::operator = (Color4 && c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color4 & Color4::operator = (Value s) noexcept
{
r = s;
g = s;
b = s;
a = s;
return *this;
}
Color4 & Color4::operator = (const SQChar * name) noexcept
{
Set(GetColor(name));
return *this;
}
Color4 & Color4::operator = (const Color3 & c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color4 & Color4::operator += (const Color4 & c) noexcept
{
r += c.r;
g += c.g;
b += c.b;
a += c.a;
return *this;
}
Color4 & Color4::operator -= (const Color4 & c) noexcept
{
r -= c.r;
g -= c.g;
b -= c.b;
a -= c.a;
return *this;
}
Color4 & Color4::operator *= (const Color4 & c) noexcept
{
r *= c.r;
g *= c.g;
b *= c.b;
a *= c.a;
return *this;
}
Color4 & Color4::operator /= (const Color4 & c) noexcept
{
r /= c.r;
g /= c.g;
b /= c.b;
a /= c.a;
return *this;
}
Color4 & Color4::operator %= (const Color4 & c) noexcept
{
r %= c.r;
g %= c.g;
b %= c.b;
a %= c.a;
return *this;
}
Color4 & Color4::operator &= (const Color4 & c) noexcept
{
r &= c.r;
g &= c.g;
b &= c.b;
a &= c.a;
return *this;
}
Color4 & Color4::operator |= (const Color4 & c) noexcept
{
r |= c.r;
g |= c.g;
b |= c.b;
a |= c.a;
return *this;
}
Color4 & Color4::operator ^= (const Color4 & c) noexcept
{
r ^= c.r;
g ^= c.g;
b ^= c.b;
a ^= c.a;
return *this;
}
Color4 & Color4::operator <<= (const Color4 & c) noexcept
{
r <<= c.r;
g <<= c.g;
b <<= c.b;
a <<= c.a;
return *this;
}
Color4 & Color4::operator >>= (const Color4 & c) noexcept
{
r >>= c.r;
g >>= c.g;
b >>= c.b;
a >>= c.a;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color4 & Color4::operator += (Value s) noexcept
{
r += s;
g += s;
b += s;
a += s;
return *this;
}
Color4 & Color4::operator -= (Value s) noexcept
{
r -= s;
g -= s;
b -= s;
a -= s;
return *this;
}
Color4 & Color4::operator *= (Value s) noexcept
{
r *= s;
g *= s;
b *= s;
a *= s;
return *this;
}
Color4 & Color4::operator /= (Value s) noexcept
{
r /= s;
g /= s;
b /= s;
a /= s;
return *this;
}
Color4 & Color4::operator %= (Value s) noexcept
{
r %= s;
g %= s;
b %= s;
a %= s;
return *this;
}
Color4 & Color4::operator &= (Value s) noexcept
{
r &= s;
g &= s;
b &= s;
a &= s;
return *this;
}
Color4 & Color4::operator |= (Value s) noexcept
{
r |= s;
g |= s;
b |= s;
a |= s;
return *this;
}
Color4 & Color4::operator ^= (Value s) noexcept
{
r ^= s;
g ^= s;
b ^= s;
a ^= s;
return *this;
}
Color4 & Color4::operator <<= (Value s) noexcept
{
r <<= s;
g <<= s;
b <<= s;
a <<= s;
return *this;
}
Color4 & Color4::operator >>= (Value s) noexcept
{
r >>= s;
g >>= s;
b >>= s;
a >>= s;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color4 & Color4::operator ++ () noexcept
{
++r;
++g;
++b;
++a;
return *this;
}
Color4 & Color4::operator -- () noexcept
{
--r;
--g;
--b;
--a;
return *this;
}
// ------------------------------------------------------------------------------------------------
Color4 Color4::operator ++ (int) noexcept
{
Color4 state(*this);
++r;
++g;
++b;
++a;
return state;
}
Color4 Color4::operator -- (int) noexcept
{
Color4 state(*this);
--r;
--g;
--b;
--a;
return state;
}
// ------------------------------------------------------------------------------------------------
Color4 Color4::operator + (const Color4 & c) const noexcept
{
return Color4(r + c.r, g + c.g, b + c.b, a + c.a);
}
Color4 Color4::operator - (const Color4 & c) const noexcept
{
return Color4(r - c.r, g - c.g, b - c.b, a - c.a);
}
Color4 Color4::operator * (const Color4 & c) const noexcept
{
return Color4(r * c.r, g * c.g, b * c.b, a * c.a);
}
Color4 Color4::operator / (const Color4 & c) const noexcept
{
return Color4(r / c.r, g / c.g, b / c.b, a / c.a);
}
Color4 Color4::operator % (const Color4 & c) const noexcept
{
return Color4(r % c.r, g % c.g, b % c.b, a % c.a);
}
Color4 Color4::operator & (const Color4 & c) const noexcept
{
return Color4(r & c.r, g & c.g, b & c.b, a & c.a);
}
Color4 Color4::operator | (const Color4 & c) const noexcept
{
return Color4(r | c.r, g | c.g, b | c.b, a | c.a);
}
Color4 Color4::operator ^ (const Color4 & c) const noexcept
{
return Color4(r ^ c.r, g ^ c.g, b ^ c.b, a ^ c.a);
}
Color4 Color4::operator << (const Color4 & c) const noexcept
{
return Color4(r << c.r, g << c.g, b << c.b, a << c.a);
}
Color4 Color4::operator >> (const Color4 & c) const noexcept
{
return Color4(r >> c.r, g >> c.g, b >> c.b, a >> c.a);
}
// ------------------------------------------------------------------------------------------------
Color4 Color4::operator + (Value s) const noexcept
{
return Color4(r + s, g + s, b + s, a + s);
}
Color4 Color4::operator - (Value s) const noexcept
{
return Color4(r - s, g - s, b - s, a - s);
}
Color4 Color4::operator * (Value s) const noexcept
{
return Color4(r * s, g * s, b * s, a * s);
}
Color4 Color4::operator / (Value s) const noexcept
{
return Color4(r / s, g / s, b / s, a / s);
}
Color4 Color4::operator % (Value s) const noexcept
{
return Color4(r % s, g % s, b % s, a % s);
}
Color4 Color4::operator & (Value s) const noexcept
{
return Color4(r & s, g & s, b & s, a & s);
}
Color4 Color4::operator | (Value s) const noexcept
{
return Color4(r | s, g | s, b | s, a | s);
}
Color4 Color4::operator ^ (Value s) const noexcept
{
return Color4(r ^ s, g ^ s, b ^ s, a ^ s);
}
Color4 Color4::operator << (Value s) const noexcept
{
return Color4(r << s, g << s, b << s, a << s);
}
Color4 Color4::operator >> (Value s) const noexcept
{
return Color4(r >> s, g >> s, b >> s, a >> s);
}
// ------------------------------------------------------------------------------------------------
Color4 Color4::operator + () const noexcept
{
return Color4(r, g, b, a);
}
Color4 Color4::operator - () const noexcept
{
return Color4(0, 0, 0, 0);
}
// ------------------------------------------------------------------------------------------------
Color4 Color4::operator ~ () const noexcept
{
return Color4(~r, ~g, ~b, ~a);
}
// ------------------------------------------------------------------------------------------------
bool Color4::operator == (const Color4 & c) const noexcept
{
return (r == c.r) && (g == c.g) && (b == c.b) && (a == c.a);
}
bool Color4::operator != (const Color4 & c) const noexcept
{
return (r != c.r) && (g != c.g) && (b != c.b) && (a != c.a);
}
bool Color4::operator < (const Color4 & c) const noexcept
{
return (r < c.r) && (g < c.g) && (b < c.b) && (a < c.a);
}
bool Color4::operator > (const Color4 & c) const noexcept
{
return (r > c.r) && (g > c.g) && (b > c.b) && (a > c.a);
}
bool Color4::operator <= (const Color4 & c) const noexcept
{
return (r <= c.r) && (g <= c.g) && (b <= c.b) && (a <= c.a);
}
bool Color4::operator >= (const Color4 & c) const noexcept
{
return (r >= c.r) && (g >= c.g) && (b >= c.b) && (a >= c.a);
}
// ------------------------------------------------------------------------------------------------
SQInteger Color4::Cmp(const Color4 & c) const noexcept
{
return *this == c ? 0 : (*this > c ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Color4::ToString() const noexcept
{
return ToStringF("%u,%u,%u,%u", r, g, b, a);
}
// ------------------------------------------------------------------------------------------------
void Color4::Set(Value ns) noexcept
{
r = ns;
g = ns;
b = ns;
a = ns;
}
void Color4::Set(Value nr, Value ng, Value nb) noexcept
{
r = nr;
g = ng;
b = nb;
}
void Color4::Set(Value nr, Value ng, Value nb, Value na) noexcept
{
r = nr;
g = ng;
b = nb;
a = na;
}
// ------------------------------------------------------------------------------------------------
void Color4::Set(const Color4 & c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
}
void Color4::Set(const Color3 & c) noexcept
{
r = c.r;
g = c.g;
b = c.b;
a = 0;
}
// ------------------------------------------------------------------------------------------------
void Color4::Set(const SQChar * str, SQChar delim) noexcept
{
Set(GetColor4(str, delim));
}
// ------------------------------------------------------------------------------------------------
void Color4::SetCol(const SQChar * name) noexcept
{
Set(GetColor(name));
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color4::GetRGB() const noexcept
{
return static_cast<SQUint32>(r << 16 | g << 8 | b);
}
void Color4::SetRGB(SQUint32 p) noexcept
{
r = static_cast<Value>((p >> 16) & 0xFF);
g = static_cast<Value>((p >> 8) & 0xFF);
b = static_cast<Value>((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color4::GetRGBA() const noexcept
{
return static_cast<SQUint32>(r << 24 | g << 16 | b << 8 | a);
}
void Color4::SetRGBA(SQUint32 p) noexcept
{
r = static_cast<Value>((p >> 24) & 0xFF);
g = static_cast<Value>((p >> 16) & 0xFF);
b = static_cast<Value>((p >> 8) & 0xFF);
a = static_cast<Value>((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
SQUint32 Color4::GetARGB() const noexcept
{
return static_cast<SQUint32>(a << 24 | r << 16 | g << 8 | b);
}
void Color4::SetARGB(SQUint32 p) noexcept
{
a = static_cast<Value>((p >> 24) & 0xFF);
r = static_cast<Value>((p >> 16) & 0xFF);
g = static_cast<Value>((p >> 8) & 0xFF);
b = static_cast<Value>((p) & 0xFF);
}
// ------------------------------------------------------------------------------------------------
void Color4::Generate() noexcept
{
r = RandomVal<Value>::Get();
g = RandomVal<Value>::Get();
b = RandomVal<Value>::Get();
a = RandomVal<Value>::Get();
}
void Color4::Generate(Value min, Value max) noexcept
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
r = RandomVal<Value>::Get(min, max);
g = RandomVal<Value>::Get(min, max);
b = RandomVal<Value>::Get(min, max);
a = RandomVal<Value>::Get(min, max);
}
}
void Color4::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax, Value amin, Value amax) noexcept
{
if (rmax < rmin || gmax < gmin || bmax < bmin || amax < amin)
{
LogErr("max value is lower than min value");
}
else
{
r = RandomVal<Value>::Get(rmin, rmax);
g = RandomVal<Value>::Get(gmin, gmax);
b = RandomVal<Value>::Get(bmin, bmax);
a = RandomVal<Value>::Get(bmin, bmax);
}
}
// ------------------------------------------------------------------------------------------------
void Color4::Random() noexcept
{
Set(GetRandomColor());
}
// ------------------------------------------------------------------------------------------------
void Color4::Inverse() noexcept
{
r = static_cast<Value>(~r);
g = static_cast<Value>(~g);
b = static_cast<Value>(~b);
a = static_cast<Value>(~a);
}
// ================================================================================================
bool Register_Color4(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Color4> type");
typedef Color4::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Color4"), Sqrat::Class<Color4>(vm, _SC("Color4"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<Val, Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Color4::Delim)
.Var(_SC("r"), &Color4::r)
.Var(_SC("g"), &Color4::g)
.Var(_SC("b"), &Color4::b)
.Var(_SC("a"), &Color4::a)
.Prop(_SC("rgb"), &Color4::GetRGB, &Color4::SetRGB)
.Prop(_SC("rgba"), &Color4::GetRGBA, &Color4::SetRGBA)
.Prop(_SC("argb"), &Color4::GetARGB, &Color4::SetARGB)
.Prop(_SC("str"), &Color4::SetCol)
.Func(_SC("_tostring"), &Color4::ToString)
.Func(_SC("_cmp"), &Color4::Cmp)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_add"), &Color4::operator +)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_sub"), &Color4::operator -)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_mul"), &Color4::operator *)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_div"), &Color4::operator /)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_modulo"), &Color4::operator %)
.Func<Color4 (Color4::*)(void) const>(_SC("_unm"), &Color4::operator -)
.Overload<void (Color4::*)(Val)>(_SC("set"), &Color4::Set)
.Overload<void (Color4::*)(Val, Val, Val)>(_SC("set"), &Color4::Set)
.Overload<void (Color4::*)(Val, Val, Val, Val)>(_SC("set"), &Color4::Set)
.Overload<void (Color4::*)(const Color4 &)>(_SC("set_col4"), &Color4::Set)
.Overload<void (Color4::*)(const Color3 &)>(_SC("set_col3"), &Color4::Set)
.Overload<void (Color4::*)(const SQChar *, SQChar)>(_SC("set_str"), &Color4::Set)
.Overload<void (Color4::*)(void)>(_SC("generate"), &Color4::Generate)
.Overload<void (Color4::*)(Val, Val)>(_SC("generate"), &Color4::Generate)
.Overload<void (Color4::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("generate"), &Color4::Generate)
.Func(_SC("clear"), &Color4::Clear)
.Func(_SC("random"), &Color4::Random)
.Func(_SC("inverse"), &Color4::Inverse)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opAddAssign"), &Color4::operator +=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opSubAssign"), &Color4::operator -=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opMulAssign"), &Color4::operator *=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opDivAssign"), &Color4::operator /=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opModAssign"), &Color4::operator %=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opAndAssign"), &Color4::operator &=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opOrAssign"), &Color4::operator |=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opXorAssign"), &Color4::operator ^=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opShlAssign"), &Color4::operator <<=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opShrAssign"), &Color4::operator >>=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opAddAssignS"), &Color4::operator +=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opSubAssignS"), &Color4::operator -=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opMulAssignS"), &Color4::operator *=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opDivAssignS"), &Color4::operator /=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opModAssignS"), &Color4::operator %=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opAndAssignS"), &Color4::operator &=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opOrAssignS"), &Color4::operator |=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opXorAssignS"), &Color4::operator ^=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opShlAssignS"), &Color4::operator <<=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opShrAssignS"), &Color4::operator >>=)
.Func<Color4 & (Color4::*)(void)>(_SC("opPreInc"), &Color4::operator ++)
.Func<Color4 & (Color4::*)(void)>(_SC("opPreDec"), &Color4::operator --)
.Func<Color4 (Color4::*)(int)>(_SC("opPostInc"), &Color4::operator ++)
.Func<Color4 (Color4::*)(int)>(_SC("opPostDec"), &Color4::operator --)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opAdd"), &Color4::operator +)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opSub"), &Color4::operator -)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opMul"), &Color4::operator *)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opDiv"), &Color4::operator /)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opMod"), &Color4::operator %)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opAnd"), &Color4::operator &)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opOr"), &Color4::operator |)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShl"), &Color4::operator ^)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShl"), &Color4::operator <<)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShr"), &Color4::operator >>)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opAddS"), &Color4::operator +)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opSubS"), &Color4::operator -)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opMulS"), &Color4::operator *)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opDivS"), &Color4::operator /)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opModS"), &Color4::operator %)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opAndS"), &Color4::operator &)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opOrS"), &Color4::operator |)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShlS"), &Color4::operator ^)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShlS"), &Color4::operator <<)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShrS"), &Color4::operator >>)
.Func<Color4 (Color4::*)(void) const>(_SC("opUnPlus"), &Color4::operator +)
.Func<Color4 (Color4::*)(void) const>(_SC("opUnMinus"), &Color4::operator -)
.Func<Color4 (Color4::*)(void) const>(_SC("opCom"), &Color4::operator ~)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opEqual"), &Color4::operator ==)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opNotEqual"), &Color4::operator !=)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opLessThan"), &Color4::operator <)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterThan"), &Color4::operator >)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opLessEqual"), &Color4::operator <=)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterEqual"), &Color4::operator >=)
);
LogDbg("Registration of <Color4> type was successful");
return true;
}
} // Namespace:: SqMod

147
source/Base/Color4.hpp Normal file
View File

@@ -0,0 +1,147 @@
#ifndef _BASE_COLOR4_HPP_
#define _BASE_COLOR4_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Color4
{
// --------------------------------------------------------------------------------------------
typedef Uint8 Value;
// --------------------------------------------------------------------------------------------
static const Color4 NIL;
static const Color4 MIN;
static const Color4 MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Value r, g, b, a;
// --------------------------------------------------------------------------------------------
Color4() noexcept;
Color4(Value s) noexcept;
Color4(Value r, Value g, Value b) noexcept;
Color4(Value r, Value g, Value b, Value a) noexcept;
// --------------------------------------------------------------------------------------------
Color4(const Color3 & c) noexcept;
// --------------------------------------------------------------------------------------------
Color4(const SQChar * name) noexcept;
Color4(const SQChar * str, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
Color4(const Color4 & c) noexcept;
Color4(Color4 && c) noexcept;
// --------------------------------------------------------------------------------------------
~Color4();
// --------------------------------------------------------------------------------------------
Color4 & operator = (const Color4 & c) noexcept;
Color4 & operator = (Color4 && c) noexcept;
// --------------------------------------------------------------------------------------------
Color4 & operator = (Value s) noexcept;
Color4 & operator = (const SQChar * name) noexcept;
Color4 & operator = (const Color3 & c) noexcept;
// --------------------------------------------------------------------------------------------
Color4 & operator += (const Color4 & c) noexcept;
Color4 & operator -= (const Color4 & c) noexcept;
Color4 & operator *= (const Color4 & c) noexcept;
Color4 & operator /= (const Color4 & c) noexcept;
Color4 & operator %= (const Color4 & c) noexcept;
Color4 & operator &= (const Color4 & c) noexcept;
Color4 & operator |= (const Color4 & c) noexcept;
Color4 & operator ^= (const Color4 & c) noexcept;
Color4 & operator <<= (const Color4 & c) noexcept;
Color4 & operator >>= (const Color4 & c) noexcept;
// --------------------------------------------------------------------------------------------
Color4 & operator += (Value s) noexcept;
Color4 & operator -= (Value s) noexcept;
Color4 & operator *= (Value s) noexcept;
Color4 & operator /= (Value s) noexcept;
Color4 & operator %= (Value s) noexcept;
Color4 & operator &= (Value s) noexcept;
Color4 & operator |= (Value s) noexcept;
Color4 & operator ^= (Value s) noexcept;
Color4 & operator <<= (Value s) noexcept;
Color4 & operator >>= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
Color4 & operator ++ () noexcept;
Color4 & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Color4 operator ++ (int) noexcept;
Color4 operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Color4 operator + (const Color4 & c) const noexcept;
Color4 operator - (const Color4 & c) const noexcept;
Color4 operator * (const Color4 & c) const noexcept;
Color4 operator / (const Color4 & c) const noexcept;
Color4 operator % (const Color4 & c) const noexcept;
Color4 operator & (const Color4 & c) const noexcept;
Color4 operator | (const Color4 & c) const noexcept;
Color4 operator ^ (const Color4 & c) const noexcept;
Color4 operator << (const Color4 & c) const noexcept;
Color4 operator >> (const Color4 & c) const noexcept;
// --------------------------------------------------------------------------------------------
Color4 operator + (Value s) const noexcept;
Color4 operator - (Value s) const noexcept;
Color4 operator * (Value s) const noexcept;
Color4 operator / (Value s) const noexcept;
Color4 operator % (Value s) const noexcept;
Color4 operator & (Value s) const noexcept;
Color4 operator | (Value s) const noexcept;
Color4 operator ^ (Value s) const noexcept;
Color4 operator << (Value s) const noexcept;
Color4 operator >> (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Color4 operator + () const noexcept;
Color4 operator - () const noexcept;
// --------------------------------------------------------------------------------------------
Color4 operator ~ () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Color4 & c) const noexcept;
bool operator != (const Color4 & c) const noexcept;
bool operator < (const Color4 & c) const noexcept;
bool operator > (const Color4 & c) const noexcept;
bool operator <= (const Color4 & c) const noexcept;
bool operator >= (const Color4 & c) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Color4 & c) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nr, Value ng, Value nb) noexcept;
void Set(Value nr, Value ng, Value nb, Value na) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Color4 & c) noexcept;
void Set(const Color3 & c) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * name, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void SetCol(const SQChar * name) noexcept;
// --------------------------------------------------------------------------------------------
SQUint32 GetRGB() const noexcept;
void SetRGB(SQUint32 p) noexcept;
// --------------------------------------------------------------------------------------------
SQUint32 GetRGBA() const noexcept;
void SetRGBA(SQUint32 p) noexcept;
// --------------------------------------------------------------------------------------------
SQUint32 GetARGB() const noexcept;
void SetARGB(SQUint32 p) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max) noexcept;
void Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax, Value amin, Value amax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { r = 0, g = 0, b = 0, a = 0; }
// --------------------------------------------------------------------------------------------
void Random() noexcept;
// --------------------------------------------------------------------------------------------
void Inverse() noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_COLOR4_HPP_

562
source/Base/Quaternion.cpp Normal file
View File

@@ -0,0 +1,562 @@
#include "Base/Quaternion.hpp"
#include "Base/Vector3.hpp"
#include "Base/Vector4.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Quaternion Quaternion::NIL = Quaternion(0);
const Quaternion Quaternion::MIN = Quaternion(std::numeric_limits<Quaternion::Value>::min());
const Quaternion Quaternion::MAX = Quaternion(std::numeric_limits<Quaternion::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Quaternion::Delim = ',';
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion() noexcept
: x(0.0), y(0.0), z(0.0), w(0.0)
{
}
Quaternion::Quaternion(Value s) noexcept
: x(s), y(s), z(s), w(s)
{
}
Quaternion::Quaternion(Value xv, Value yv, Value zv) noexcept
: x(xv), y(yv), z(zv), w(0.0)
{
}
Quaternion::Quaternion(Value xv, Value yv, Value zv, Value wv) noexcept
: x(xv), y(yv), z(zv), w(wv)
{
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(const Vector3 & v) noexcept
: x(v.x), y(v.y), z(v.z), w(0.0)
{
}
Quaternion::Quaternion(const Vector4 & v) noexcept
: x(v.x), y(v.y), z(v.z), w(v.w)
{
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(const SQChar * values, SQChar delim) noexcept
: Quaternion(GetQuaternion(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Quaternion::Quaternion(const Quaternion & q) noexcept
: x(q.x), y(q.y), z(q.z), w(q.w)
{
}
Quaternion::Quaternion(Quaternion && q) noexcept
: x(q.x), y(q.y), z(q.z), w(q.w)
{
}
// ------------------------------------------------------------------------------------------------
Quaternion::~Quaternion()
{
}
// ------------------------------------------------------------------------------------------------
Quaternion & Quaternion::operator = (const Quaternion & q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
return *this;
}
Quaternion & Quaternion::operator = (Quaternion && q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
return *this;
}
// ------------------------------------------------------------------------------------------------
Quaternion & Quaternion::operator = (Value s) noexcept
{
x = s;
y = s;
z = s;
w = s;
return *this;
}
Quaternion & Quaternion::operator = (const Vector3 & q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
w = 0.0;
return *this;
}
Quaternion & Quaternion::operator = (const Vector4 & q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
return *this;
}
// ------------------------------------------------------------------------------------------------
Quaternion & Quaternion::operator += (const Quaternion & q) noexcept
{
x += q.x;
y += q.y;
z += q.z;
w += q.w;
return *this;
}
Quaternion & Quaternion::operator -= (const Quaternion & q) noexcept
{
x -= q.x;
y -= q.y;
z -= q.z;
w -= q.w;
return *this;
}
Quaternion & Quaternion::operator *= (const Quaternion & q) noexcept
{
x *= q.x;
y *= q.y;
z *= q.z;
w *= q.w;
return *this;
}
Quaternion & Quaternion::operator /= (const Quaternion & q) noexcept
{
x /= q.x;
y /= q.y;
z /= q.z;
w /= q.w;
return *this;
}
Quaternion & Quaternion::operator %= (const Quaternion & q) noexcept
{
x = std::fmod(x, q.x);
y = std::fmod(y, q.y);
z = std::fmod(z, q.z);
w = std::fmod(w, q.w);
return *this;
}
// ------------------------------------------------------------------------------------------------
Quaternion & Quaternion::operator += (Value s) noexcept
{
x += s;
y += s;
z += s;
w += s;
return *this;
}
Quaternion & Quaternion::operator -= (Value s) noexcept
{
x -= s;
y -= s;
z -= s;
w -= s;
return *this;
}
Quaternion & Quaternion::operator *= (Value s) noexcept
{
x *= s;
y *= s;
z *= s;
w *= s;
return *this;
}
Quaternion & Quaternion::operator /= (Value s) noexcept
{
x /= s;
y /= s;
z /= s;
w /= s;
return *this;
}
Quaternion & Quaternion::operator %= (Value s) noexcept
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
w = std::fmod(w, s);
return *this;
}
// ------------------------------------------------------------------------------------------------
Quaternion & Quaternion::operator ++ () noexcept
{
++x;
++y;
++z;
++w;
return *this;
}
Quaternion & Quaternion::operator -- () noexcept
{
--x;
--y;
--z;
--w;
return *this;
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator ++ (int) noexcept
{
Quaternion state(*this);
++x;
++y;
++z;
++w;
return state;
}
Quaternion Quaternion::operator -- (int) noexcept
{
Quaternion state(*this);
--x;
--y;
--z;
--w;
return state;
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator + (const Quaternion & q) const noexcept
{
return Quaternion(x + q.x, y + q.y, z + q.z, w + q.w);
}
Quaternion Quaternion::operator + (Value s) const noexcept
{
return Quaternion(x + s, y + s, z + s, w + s);
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator - (const Quaternion & q) const noexcept
{
return Quaternion(x - q.x, y - q.y, z - q.z, w - q.w);
}
Quaternion Quaternion::operator - (Value s) const noexcept
{
return Quaternion(x - s, y - s, z - s, w - s);
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator * (const Quaternion & q) const noexcept
{
return Quaternion(x * q.x, y * q.y, z * q.z, w * q.w);
}
Quaternion Quaternion::operator * (Value s) const noexcept
{
return Quaternion(x * s, y * s, z * s, w * s);
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator / (const Quaternion & q) const noexcept
{
return Quaternion(x / q.x, y / q.y, z / q.z, w / q.w);
}
Quaternion Quaternion::operator / (Value s) const noexcept
{
return Quaternion(x / s, y / s, z / s, w / s);
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator % (const Quaternion & q) const noexcept
{
return Quaternion(std::fmod(x, q.x), std::fmod(y, q.y), std::fmod(z, q.z), std::fmod(w, q.w));
}
Quaternion Quaternion::operator % (Value s) const noexcept
{
return Quaternion(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator + () const noexcept
{
return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
}
Quaternion Quaternion::operator - () const noexcept
{
return Quaternion(-x, -y, -z, -w);
}
// ------------------------------------------------------------------------------------------------
bool Quaternion::operator == (const Quaternion & q) const noexcept
{
return EpsEq(x, q.x) && EpsEq(y, q.y) && EpsEq(z, q.z) && EpsEq(w, q.w);
}
bool Quaternion::operator != (const Quaternion & q) const noexcept
{
return !EpsEq(x, q.x) && !EpsEq(y, q.y) && !EpsEq(z, q.z) && !EpsEq(w, q.w);
}
bool Quaternion::operator < (const Quaternion & q) const noexcept
{
return std::isless(x, q.x) && std::isless(y, q.y) && std::isless(z, q.z) && std::isless(w, q.w);
}
bool Quaternion::operator > (const Quaternion & q) const noexcept
{
return std::isgreater(x, q.x) && std::isgreater(y, q.y) && std::isgreater(z, q.z) && std::isgreater(w, q.w);
}
bool Quaternion::operator <= (const Quaternion & q) const noexcept
{
return std::islessequal(x, q.x) && std::islessequal(y, q.y) && std::islessequal(z, q.z) && std::islessequal(w, q.w);
}
bool Quaternion::operator >= (const Quaternion & q) const noexcept
{
return std::isgreaterequal(x, q.x) && std::isgreaterequal(y, q.y) && std::isgreaterequal(z, q.z) && std::isgreaterequal(w, q.w);
}
// ------------------------------------------------------------------------------------------------
SQInteger Quaternion::Cmp(const Quaternion & q) const noexcept
{
return *this == q ? 0 : (*this > q ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Quaternion::ToString() const noexcept
{
return ToStringF("%f,%f,%f,%f", x, y, z, w);
}
// ------------------------------------------------------------------------------------------------
void Quaternion::Set(Value ns) noexcept
{
x = ns;
y = ns;
z = ns;
w = ns;
}
void Quaternion::Set(Value nx, Value ny, Value nz) noexcept
{
x = nx;
y = ny;
z = nz;
}
void Quaternion::Set(Value nx, Value ny, Value nz, Value nw) noexcept
{
x = nx;
y = ny;
z = nz;
w = nw;
}
// ------------------------------------------------------------------------------------------------
void Quaternion::Set(const Quaternion & q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
}
void Quaternion::Set(const Vector3 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
w = 0.0;
}
void Quaternion::Set(const Vector4 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
w = v.w;
}
// ------------------------------------------------------------------------------------------------
void Quaternion::Set(const SQChar * values, SQChar delim) noexcept
{
Set(GetQuaternion(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Quaternion::Generate() noexcept
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
z = RandomVal<Value>::Get();
w = RandomVal<Value>::Get();
}
void Quaternion::Generate(Value min, Value max) noexcept
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
z = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
}
}
void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax) noexcept
{
if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin) || std::isless(wmax, wmin))
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(xmin, xmax);
y = RandomVal<Value>::Get(ymin, ymax);
z = RandomVal<Value>::Get(zmin, zmax);
y = RandomVal<Value>::Get(ymin, ymax);
}
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::Abs() const noexcept
{
return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
}
// ================================================================================================
bool Register_Quaternion(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Quaternion> type");
typedef Quaternion::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Quaternion"), Sqrat::Class<Quaternion>(vm, _SC("Quaternion"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<Val, Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Quaternion::Delim)
.Var(_SC("x"), &Quaternion::x)
.Var(_SC("y"), &Quaternion::y)
.Var(_SC("z"), &Quaternion::z)
.Var(_SC("w"), &Quaternion::w)
.Prop(_SC("abs"), &Quaternion::Abs)
.Func(_SC("_tostring"), &Quaternion::ToString)
.Func(_SC("_cmp"), &Quaternion::Cmp)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_add"), &Quaternion::operator +)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_sub"), &Quaternion::operator -)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_mul"), &Quaternion::operator *)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_div"), &Quaternion::operator /)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_modulo"), &Quaternion::operator %)
.Func<Quaternion (Quaternion::*)(void) const>(_SC("_unm"), &Quaternion::operator -)
.Overload<void (Quaternion::*)(Val)>(_SC("set"), &Quaternion::Set)
.Overload<void (Quaternion::*)(Val, Val, Val)>(_SC("set"), &Quaternion::Set)
.Overload<void (Quaternion::*)(Val, Val, Val, Val)>(_SC("set"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const Quaternion &)>(_SC("set_quat"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const Vector3 &)>(_SC("set_vec3"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const Vector4 &)>(_SC("set_vec4"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const SQChar *, SQChar)>(_SC("set_str"), &Quaternion::Set)
.Overload<void (Quaternion::*)(void)>(_SC("generate"), &Quaternion::Generate)
.Overload<void (Quaternion::*)(Val, Val)>(_SC("generate"), &Quaternion::Generate)
.Overload<void (Quaternion::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("generate"), &Quaternion::Generate)
.Func(_SC("clear"), &Quaternion::Clear)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opAddAssign"), &Quaternion::operator +=)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opSubAssign"), &Quaternion::operator -=)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opMulAssign"), &Quaternion::operator *=)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opDivAssign"), &Quaternion::operator /=)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opModAssign"), &Quaternion::operator %=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opAddAssignS"), &Quaternion::operator +=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opSubAssignS"), &Quaternion::operator -=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opMulAssignS"), &Quaternion::operator *=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opDivAssignS"), &Quaternion::operator /=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opModAssignS"), &Quaternion::operator %=)
.Func<Quaternion & (Quaternion::*)(void)>(_SC("opPreInc"), &Quaternion::operator ++)
.Func<Quaternion & (Quaternion::*)(void)>(_SC("opPreDec"), &Quaternion::operator --)
.Func<Quaternion (Quaternion::*)(int)>(_SC("opPostInc"), &Quaternion::operator ++)
.Func<Quaternion (Quaternion::*)(int)>(_SC("opPostDec"), &Quaternion::operator --)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opAdd"), &Quaternion::operator +)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opSub"), &Quaternion::operator -)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opMul"), &Quaternion::operator *)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opDiv"), &Quaternion::operator /)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opMod"), &Quaternion::operator %)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opAddS"), &Quaternion::operator +)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opSubS"), &Quaternion::operator -)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opMulS"), &Quaternion::operator *)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opDivS"), &Quaternion::operator /)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opModS"), &Quaternion::operator %)
.Func<Quaternion (Quaternion::*)(void) const>(_SC("opUnPlus"), &Quaternion::operator +)
.Func<Quaternion (Quaternion::*)(void) const>(_SC("opUnMinus"), &Quaternion::operator -)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opEqual"), &Quaternion::operator ==)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opNotEqual"), &Quaternion::operator !=)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opLessThan"), &Quaternion::operator <)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterThan"), &Quaternion::operator >)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opLessEqual"), &Quaternion::operator <=)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterEqual"), &Quaternion::operator >=)
);
LogDbg("Registration of <Quaternion> type was successful");
return true;
}
} // Namespace:: SqMod

113
source/Base/Quaternion.hpp Normal file
View File

@@ -0,0 +1,113 @@
#ifndef _BASE_QUATERNION_HPP_
#define _BASE_QUATERNION_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Quaternion
{
// --------------------------------------------------------------------------------------------
typedef SQFloat Value;
// --------------------------------------------------------------------------------------------
static const Quaternion NIL;
static const Quaternion MIN;
static const Quaternion MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Value x, y, z, w;
// --------------------------------------------------------------------------------------------
Quaternion() noexcept;
Quaternion(Value s) noexcept;
Quaternion(Value xv, Value yv, Value zv) noexcept;
Quaternion(Value xv, Value yv, Value zv, Value wv) noexcept;
// --------------------------------------------------------------------------------------------
Quaternion(const Vector3 & v) noexcept;
Quaternion(const Vector4 & v) noexcept;
// --------------------------------------------------------------------------------------------
Quaternion(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
Quaternion(const Quaternion & q) noexcept;
Quaternion(Quaternion && q) noexcept;
// --------------------------------------------------------------------------------------------
~Quaternion();
// --------------------------------------------------------------------------------------------
Quaternion & operator = (const Quaternion & q) noexcept;
Quaternion & operator = (Quaternion && q) noexcept;
// --------------------------------------------------------------------------------------------
Quaternion & operator = (Value s) noexcept;
Quaternion & operator = (const Vector3 & q) noexcept;
Quaternion & operator = (const Vector4 & q) noexcept;
// --------------------------------------------------------------------------------------------
Quaternion & operator += (const Quaternion & q) noexcept;
Quaternion & operator -= (const Quaternion & q) noexcept;
Quaternion & operator *= (const Quaternion & q) noexcept;
Quaternion & operator /= (const Quaternion & q) noexcept;
Quaternion & operator %= (const Quaternion & q) noexcept;
// --------------------------------------------------------------------------------------------
Quaternion & operator += (Value s) noexcept;
Quaternion & operator -= (Value s) noexcept;
Quaternion & operator *= (Value s) noexcept;
Quaternion & operator /= (Value s) noexcept;
Quaternion & operator %= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
Quaternion & operator ++ () noexcept;
Quaternion & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Quaternion operator ++ (int) noexcept;
Quaternion operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Quaternion operator + (const Quaternion & q) const noexcept;
Quaternion operator - (const Quaternion & q) const noexcept;
Quaternion operator * (const Quaternion & q) const noexcept;
Quaternion operator / (const Quaternion & q) const noexcept;
Quaternion operator % (const Quaternion & q) const noexcept;
// --------------------------------------------------------------------------------------------
Quaternion operator + (Value s) const noexcept;
Quaternion operator - (Value s) const noexcept;
Quaternion operator * (Value s) const noexcept;
Quaternion operator / (Value s) const noexcept;
Quaternion operator % (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Quaternion operator + () const noexcept;
Quaternion operator - () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Quaternion & q) const noexcept;
bool operator != (const Quaternion & q) const noexcept;
bool operator < (const Quaternion & q) const noexcept;
bool operator > (const Quaternion & q) const noexcept;
bool operator <= (const Quaternion & q) const noexcept;
bool operator >= (const Quaternion & q) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Quaternion & q) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nx, Value ny, Value nz) noexcept;
void Set(Value nx, Value ny, Value nz, Value nw) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Quaternion & q) noexcept;
void Set(const Vector3 & v) noexcept;
void Set(const Vector4 & v) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { x = 0.0, y = 0.0, z = 0.0, w = 0.0; }
// --------------------------------------------------------------------------------------------
Quaternion Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_QUATERNION_HPP_

1848
source/Base/Shared.cpp Normal file

File diff suppressed because it is too large Load Diff

400
source/Base/Shared.hpp Normal file
View File

@@ -0,0 +1,400 @@
#ifndef _BASE_SHARED_HPP_
#define _BASE_SHARED_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
#include <cmath>
#include <limits>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <type_traits>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
#ifdef PI
#undef PI
#endif
// ------------------------------------------------------------------------------------------------
const Float32 PI = 3.14159265359f;
const Float32 RECIPROCAL_PI = 1.0f/PI;
const Float32 HALF_PI = PI/2.0f;
// ------------------------------------------------------------------------------------------------
#ifdef PI64
#undef PI64
#endif
// ------------------------------------------------------------------------------------------------
const Float64 PI64 = 3.1415926535897932384626433832795028841971693993751;
const Float64 RECIPROCAL_PI64 = 1.0/PI64;
// ------------------------------------------------------------------------------------------------
const Float32 DEGTORAD = PI / 180.0f;
const Float32 RADTODEG = 180.0f / PI;
const Float64 DEGTORAD64 = PI64 / 180.0;
const Float64 RADTODEG64 = 180.0 / PI64;
/* ------------------------------------------------------------------------------------------------
* ...
*/
template< typename T > inline bool EpsEq(const T a, const T b) noexcept
{
return abs(a - b) <= std::numeric_limits<T>::epsilon();
}
template <> inline bool EpsEq(const Float32 a, const Float32 b) noexcept
{
return fabs(a - b) <= 0.000001f;
}
template <> inline bool EpsEq(const Float64 a, const Float64 b) noexcept
{
return fabs(a - b) <= 0.000000001d;
}
/* ------------------------------------------------------------------------------------------------
* ...
*/
template< typename T > inline T Clamp(T val, T min, T max) noexcept
{
return val < min ? min : (val > max ? max : val);
}
template<> inline Float32 Clamp(const Float32 val, const Float32 min, const Float32 max) noexcept
{
return std::isless(val, min) ? min : (std::isgreater(val, max) ? max : val);
}
template<> inline Float64 Clamp(const Float64 val, const Float64 min, const Float64 max) noexcept
{
return std::isless(val, min) ? min : (std::isgreater(val, max) ? max : val);
}
/* ------------------------------------------------------------------------------------------------
* Simple functions to quickly forward logging messages without including the logging system
*/
void LogDbg(const char * fmt, ...) noexcept;
void LogMsg(const char * fmt, ...) noexcept;
void LogScs(const char * fmt, ...) noexcept;
void LogInf(const char * fmt, ...) noexcept;
void LogWrn(const char * fmt, ...) noexcept;
void LogErr(const char * fmt, ...) noexcept;
void LogFtl(const char * fmt, ...) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToStringF(const char * fmt, ...) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
void InitMTRG64() noexcept;
void InitMTRG64() noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Int8 GetRandomInt8() noexcept;
Int8 GetRandomInt8(Int8 min, Int8 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Uint8 GetRandomUint8() noexcept;
Uint8 GetRandomUint8(Uint8 min, Uint8 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Int16 GetRandomInt16() noexcept;
Int16 GetRandomInt16(Int16 min, Int16 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Uint16 GetRandomUint16() noexcept;
Uint16 GetRandomUint16(Uint16 min, Uint16 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Int32 GetRandomInt32() noexcept;
Int32 GetRandomInt32(Int32 min, Int32 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Uint32 GetRandomUint32() noexcept;
Uint32 GetRandomUint32(Uint32 min, Uint32 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Int64 GetRandomInt64() noexcept;
Int64 GetRandomInt64(Int64 min, Int64 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Uint64 GetRandomUint64() noexcept;
Uint64 GetRandomUint64(Uint64 min, Uint64 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Float32 GetRandomFloat32() noexcept;
Float32 GetRandomFloat32(Float32 min, Float32 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Float64 GetRandomFloat64() noexcept;
Float64 GetRandomFloat64(Float64 min, Float64 max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
String GetRandomString(String::size_type len) noexcept;
String GetRandomString(String::size_type len, String::value_type min, String::value_type max) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
bool GetRandomBool() noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <typename T> struct RandomVal
{ /* ... */ };
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Int8>
{
static inline Int8 Get() noexcept { return GetRandomInt8(); }
static inline Int8 Get(Int8 min, Int8 max) noexcept { return GetRandomInt8(min, max); }
};
template <> struct RandomVal<Uint8>
{
static inline Uint8 Get() noexcept { return GetRandomUint8(); }
static inline Uint8 Get(Uint8 min, Uint8 max) noexcept { return GetRandomUint8(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Int16>
{
static inline Int16 Get() noexcept { return GetRandomInt16(); }
static inline Int16 Get(Int16 min, Int16 max) noexcept { return GetRandomInt16(min, max); }
};
template <> struct RandomVal<Uint16>
{
static inline Uint16 Get() noexcept { return GetRandomUint16(); }
static inline Uint16 Get(Uint16 min, Uint16 max) noexcept { return GetRandomUint16(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Int32>
{
static inline Int32 Get() noexcept { return GetRandomInt32(); }
static inline Int32 Get(Int32 min, Int32 max) noexcept { return GetRandomInt32(min, max); }
};
template <> struct RandomVal<Uint32>
{
static inline Uint32 Get() noexcept { return GetRandomUint32(); }
static inline Uint32 Get(Uint32 min, Uint32 max) noexcept { return GetRandomUint32(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Int64>
{
static inline Int64 Get() noexcept { return GetRandomInt64(); }
static inline Int64 Get(Int64 min, Int64 max) noexcept { return GetRandomInt64(min, max); }
};
template <> struct RandomVal<Uint64>
{
static inline Uint64 Get() noexcept { return GetRandomUint64(); }
static inline Uint64 Get(Uint64 min, Uint64 max) noexcept { return GetRandomUint64(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<Float32>
{
static inline Float32 Get() noexcept { return GetRandomFloat32(); }
static inline Float32 Get(Float32 min, Float32 max) noexcept { return GetRandomFloat32(min, max); }
};
template <> struct RandomVal<Float64>
{
static inline Float64 Get() noexcept { return GetRandomFloat64(); }
static inline Float64 Get(Float64 min, Float64 max) noexcept { return GetRandomFloat64(min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<String>
{
static inline String Get(String::size_type len) noexcept { return GetRandomString(len); }
static inline String Get(String::size_type len, String::value_type min, String::value_type max) noexcept
{ return GetRandomString(len, min, max); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
template <> struct RandomVal<bool>
{
static inline bool Get() noexcept { return GetRandomBool(); }
};
/* ------------------------------------------------------------------------------------------------
* ...
*/
const Color3 & GetRandomColor() noexcept;
/* ------------------------------------------------------------------------------------------------
* Simple function to check whether the specified string can be considered as a boolean value
*/
bool SToB(const SQChar * str) noexcept;
/* ------------------------------------------------------------------------------------------------
* Utility used to unify the string converstion functions under one name.
*/
template < typename T > struct SToI { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template < typename T > struct SToF { static constexpr auto Fn = static_cast< float(*)(const String &, std::size_t*) >(std::stof); };
// ------------------------------------------------------------------------------------------------
template <> struct SToI < char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < signed char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < unsigned char > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < short > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < unsigned short > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < int > { static constexpr auto Fn = static_cast< int(*)(const String &, std::size_t*, int) >(std::stoi); };
template <> struct SToI < unsigned int > { static constexpr auto Fn = static_cast< unsigned long(*)(const String &, std::size_t*, int) >(std::stoul); };
template <> struct SToI < long > { static constexpr auto Fn = static_cast< long(*)(const String &, std::size_t*, int) >(std::stol); };
template <> struct SToI < unsigned long > { static constexpr auto Fn = static_cast< unsigned long(*)(const String &, std::size_t*, int) >(std::stoul); };
template <> struct SToI < long long > { static constexpr auto Fn = static_cast< long long(*)(const String &, std::size_t*, int b) >(std::stoll); };
template <> struct SToI < unsigned long long > { static constexpr auto Fn = static_cast< unsigned long long(*)(const String &, std::size_t*, int) >(std::stoull); };
template <> struct SToF < float > { static constexpr auto Fn = static_cast< float(*)(const String &, std::size_t*) >(std::stof); };
template <> struct SToF < double > { static constexpr auto Fn = static_cast< double(*)(const String &, std::size_t*) >(std::stod); };
template <> struct SToF < long double > { static constexpr auto Fn = static_cast< long double(*)(const String &, std::size_t*) >(std::stold); };
// ------------------------------------------------------------------------------------------------
template < typename T > inline String NToS(T n) noexcept { return std::to_string(n); }
template < typename T > inline const SQChar * NToCS(T n) noexcept { return std::to_string(n).c_str(); }
/* ------------------------------------------------------------------------------------------------
* ...
*/
Color3 GetColor(const SQChar * name) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Circle GetCircle(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
AABB GetAABB(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Color3 GetColor3(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Color4 GetColor4(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Quaternion GetQuaternion(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Sphere GetSphere(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector2f GetVector2f(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector2i GetVector2i(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector2u GetVector2u(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector3 GetVector3(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* ...
*/
Vector4 GetVector4(const SQChar * str, SQChar delim) noexcept;
/* ------------------------------------------------------------------------------------------------
* Fake deleter meant for classes that should not be deleted by smart pointers
*/
template <typename T> struct FakeDeleter
{
void operator () (T * /* ptr */) const noexcept { /* Ignored... */ }
};
/* ------------------------------------------------------------------------------------------------
* Utility used to generate a string with an arbitrary text surrounded by a specific character
*/
const SQChar * LeftStr(const SQChar * t, SQChar f, SQUint32 w = 72) noexcept;
const SQChar * LeftStr(const SQChar * t, SQChar f, SQUint32 w = 72, SQUint32 o = 0) noexcept;
const SQChar * RightStr(const SQChar * t, SQChar f, SQUint32 w = 72) noexcept;
const SQChar * RightStr(const SQChar * t, SQChar f, SQUint32 w = 72, SQUint32 o = 0) noexcept;
const SQChar * CenterStr(const SQChar * t, SQChar f, SQUint32 w = 72) noexcept;
/* ------------------------------------------------------------------------------------------------
* Function used insert arbitrary text at certain positions within a string
*/
const SQChar * InsertStr(const SQChar * f, const std::vector< const SQChar * > & a) noexcept;
// Utility for the <InsertStr> function
const SQChar * InsStr(const SQChar * f) noexcept;
template < typename... Args > const SQChar * InsStr(const SQChar * f, Args... args) noexcept
{
return InsertStr(f, {{args...}});
}
} // Namespace:: SqMod
#endif // _BASE_SHARED_HPP_

542
source/Base/Sphere.cpp Normal file
View File

@@ -0,0 +1,542 @@
#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<Sphere::Value>::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<Value>::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<Value>::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<Value>::Get(rmin, rmax);
}
}
// ------------------------------------------------------------------------------------------------
Sphere Sphere::Abs() const noexcept
{
return Sphere(pos.Abs(), std::fabs(rad));
}
// ------------------------------------------------------------------------------------------------
bool Register_Sphere(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Sphere> type");
typedef Sphere::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Sphere"), Sqrat::Class<Sphere>(vm, _SC("Sphere"))
.Ctor()
.Ctor<Val>()
.Ctor<const Vector3 &, Val>()
.Ctor<Val, Val, Val, Val>()
.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<Sphere (Sphere::*)(const Sphere &) const>(_SC("_add"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_sub"), &Sphere::operator -)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_mul"), &Sphere::operator *)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_div"), &Sphere::operator /)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_modulo"), &Sphere::operator %)
.Func<Sphere (Sphere::*)(void) const>(_SC("_unm"), &Sphere::operator -)
.Overload<void (Sphere::*)(const Sphere &)>(_SC("set"), &Sphere::Set)
.Overload<void (Sphere::*)(const Vector3 &, Val)>(_SC("set"), &Sphere::Set)
.Overload<void (Sphere::*)(Val, Val, Val, Val)>(_SC("set"), &Sphere::Set)
.Overload<void (Sphere::*)(Val)>(_SC("set_rad"), &Sphere::Set)
.Overload<void (Sphere::*)(const Vector3 &)>(_SC("set_vec3"), &Sphere::Set)
.Overload<void (Sphere::*)(Val, Val, Val)>(_SC("set_vec3"), &Sphere::Set)
.Overload<void (Sphere::*)(const SQChar *, SQChar)>(_SC("set_str"), &Sphere::Set)
.Func(_SC("clear"), &Sphere::Clear)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opAddAssign"), &Sphere::operator +=)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opSubAssign"), &Sphere::operator -=)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opMulAssign"), &Sphere::operator *=)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opDivAssign"), &Sphere::operator /=)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opModAssign"), &Sphere::operator %=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opAddAssignR"), &Sphere::operator +=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opSubAssignR"), &Sphere::operator -=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opMulAssignR"), &Sphere::operator *=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opDivAssignR"), &Sphere::operator /=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opModAssignR"), &Sphere::operator %=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opAddAssignP"), &Sphere::operator +=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opSubAssignP"), &Sphere::operator -=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opMulAssignP"), &Sphere::operator *=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opDivAssignP"), &Sphere::operator /=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opModAssignP"), &Sphere::operator %=)
.Func<Sphere & (Sphere::*)(void)>(_SC("opPreInc"), &Sphere::operator ++)
.Func<Sphere & (Sphere::*)(void)>(_SC("opPreDec"), &Sphere::operator --)
.Func<Sphere (Sphere::*)(int)>(_SC("opPostInc"), &Sphere::operator ++)
.Func<Sphere (Sphere::*)(int)>(_SC("opPostDec"), &Sphere::operator --)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opAdd"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opSub"), &Sphere::operator -)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opMul"), &Sphere::operator *)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opDiv"), &Sphere::operator /)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opMod"), &Sphere::operator %)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opAddR"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opSubR"), &Sphere::operator -)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opMulR"), &Sphere::operator *)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opDivR"), &Sphere::operator /)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opModR"), &Sphere::operator %)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opAddP"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opSubP"), &Sphere::operator -)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opMulP"), &Sphere::operator *)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opDivP"), &Sphere::operator /)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opModP"), &Sphere::operator %)
.Func<Sphere (Sphere::*)(void) const>(_SC("opUnPlus"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(void) const>(_SC("opUnMinus"), &Sphere::operator -)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opEqual"), &Sphere::operator ==)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opNotEqual"), &Sphere::operator !=)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opLessThan"), &Sphere::operator <)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterThan"), &Sphere::operator >)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opLessEqual"), &Sphere::operator <=)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterEqual"), &Sphere::operator >=)
);
LogDbg("Registration of <Sphere> type was successful");
return true;
}
} // Namespace:: SqMod

123
source/Base/Sphere.hpp Normal file
View File

@@ -0,0 +1,123 @@
#ifndef _BASE_SPHERE_HPP_
#define _BASE_SPHERE_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
#include "Base/Vector3.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Sphere
{
// --------------------------------------------------------------------------------------------
typedef SQFloat Value;
// --------------------------------------------------------------------------------------------
static const Sphere NIL;
static const Sphere MIN;
static const Sphere MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Vector3 pos;
Value rad;
// --------------------------------------------------------------------------------------------
Sphere() noexcept;
Sphere(Value r) noexcept;
Sphere(const Vector3 & p) noexcept;
Sphere(const Vector3 & p, Value r) noexcept;
Sphere(Value x, Value y, Value z, Value r) noexcept;
// --------------------------------------------------------------------------------------------
Sphere(const Sphere & s) noexcept;
Sphere(Sphere && s) noexcept;
// --------------------------------------------------------------------------------------------
~Sphere();
// --------------------------------------------------------------------------------------------
Sphere & operator = (const Sphere & s) noexcept;
Sphere & operator = (Sphere && s) noexcept;
// --------------------------------------------------------------------------------------------
Sphere & operator = (Value r) noexcept;
Sphere & operator = (const Vector3 & p) noexcept;
// --------------------------------------------------------------------------------------------
Sphere & operator += (const Sphere & s) noexcept;
Sphere & operator -= (const Sphere & s) noexcept;
Sphere & operator *= (const Sphere & s) noexcept;
Sphere & operator /= (const Sphere & s) noexcept;
Sphere & operator %= (const Sphere & s) noexcept;
// --------------------------------------------------------------------------------------------
Sphere & operator += (Value r) noexcept;
Sphere & operator -= (Value r) noexcept;
Sphere & operator *= (Value r) noexcept;
Sphere & operator /= (Value r) noexcept;
Sphere & operator %= (Value r) noexcept;
// --------------------------------------------------------------------------------------------
Sphere & operator += (const Vector3 & p) noexcept;
Sphere & operator -= (const Vector3 & p) noexcept;
Sphere & operator *= (const Vector3 & p) noexcept;
Sphere & operator /= (const Vector3 & p) noexcept;
Sphere & operator %= (const Vector3 & p) noexcept;
// --------------------------------------------------------------------------------------------
Sphere & operator ++ () noexcept;
Sphere & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Sphere operator ++ (int) noexcept;
Sphere operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Sphere operator + (const Sphere & s) const noexcept;
Sphere operator - (const Sphere & s) const noexcept;
Sphere operator * (const Sphere & s) const noexcept;
Sphere operator / (const Sphere & s) const noexcept;
Sphere operator % (const Sphere & s) const noexcept;
// --------------------------------------------------------------------------------------------
Sphere operator + (Value r) const noexcept;
Sphere operator - (Value r) const noexcept;
Sphere operator * (Value r) const noexcept;
Sphere operator / (Value r) const noexcept;
Sphere operator % (Value r) const noexcept;
// --------------------------------------------------------------------------------------------
Sphere operator + (const Vector3 & p) const noexcept;
Sphere operator - (const Vector3 & p) const noexcept;
Sphere operator * (const Vector3 & p) const noexcept;
Sphere operator / (const Vector3 & p) const noexcept;
Sphere operator % (const Vector3 & p) const noexcept;
// --------------------------------------------------------------------------------------------
Sphere operator + () const noexcept;
Sphere operator - () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Sphere & s) const noexcept;
bool operator != (const Sphere & s) const noexcept;
bool operator < (const Sphere & s) const noexcept;
bool operator > (const Sphere & s) const noexcept;
bool operator <= (const Sphere & s) const noexcept;
bool operator >= (const Sphere & s) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Sphere & s) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value nr) noexcept;
void Set(const Sphere & ns) noexcept;
void Set(const Vector3 & np) noexcept;
void Set(const Vector3 & np, Value nr) noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value nx, Value ny, Value nz) noexcept;
void Set(Value nx, Value ny, Value nz, Value nr) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max, bool r) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value rmin, Value rmax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { pos.Clear(); rad = 0.0; }
// --------------------------------------------------------------------------------------------
Sphere Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_SPHERE_HPP_

493
source/Base/Vector2f.cpp Normal file
View File

@@ -0,0 +1,493 @@
#include "Base/Vector2f.hpp"
#include "Base/Vector2i.hpp"
#include "Base/Vector2u.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector2f Vector2f::NIL = Vector2f(0);
const Vector2f Vector2f::MIN = Vector2f(std::numeric_limits<Vector2f::Value>::min());
const Vector2f Vector2f::MAX = Vector2f(std::numeric_limits<Vector2f::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Vector2f::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector2f::Vector2f() noexcept
: x(0.0), y(0.0)
{
}
Vector2f::Vector2f(Value s) noexcept
: x(s), y(s)
{
}
Vector2f::Vector2f(Value xv, Value yv) noexcept
: x(xv), y(yv)
{
}
// ------------------------------------------------------------------------------------------------
Vector2f::Vector2f(const Vector2i & v) noexcept
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
Vector2f::Vector2f(const Vector2u & v) noexcept
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
// ------------------------------------------------------------------------------------------------
Vector2f::Vector2f(const SQChar * values, SQChar delim) noexcept
: Vector2f(GetVector2f(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector2f::Vector2f(const Vector2f & v) noexcept
: x(v.x), y(v.y)
{
}
Vector2f::Vector2f(Vector2f && v) noexcept
: x(v.x), y(v.y)
{
}
// ------------------------------------------------------------------------------------------------
Vector2f::~Vector2f()
{
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator = (const Vector2f & v) noexcept
{
x = v.x;
y = v.y;
return *this;
}
Vector2f & Vector2f::operator = (Vector2f && v) noexcept
{
x = v.x;
y = v.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator = (Value s) noexcept
{
x = s;
y = s;
return *this;
}
Vector2f & Vector2f::operator = (const SQChar * values) noexcept
{
Set(GetVector2f(values, Delim));
return *this;
}
Vector2f & Vector2f::operator = (const Vector2i & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
Vector2f & Vector2f::operator = (const Vector2u & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator += (const Vector2f & v) noexcept
{
x += v.x;
y += v.y;
return *this;
}
Vector2f & Vector2f::operator -= (const Vector2f & v) noexcept
{
x -= v.x;
y -= v.y;
return *this;
}
Vector2f & Vector2f::operator *= (const Vector2f & v) noexcept
{
x *= v.x;
y *= v.y;
return *this;
}
Vector2f & Vector2f::operator /= (const Vector2f & v) noexcept
{
x /= v.x;
y /= v.y;
return *this;
}
Vector2f & Vector2f::operator %= (const Vector2f & v) noexcept
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator += (Value s) noexcept
{
x += s;
y += s;
return *this;
}
Vector2f & Vector2f::operator -= (Value s) noexcept
{
x -= s;
y -= s;
return *this;
}
Vector2f & Vector2f::operator *= (Value s) noexcept
{
x *= s;
y *= s;
return *this;
}
Vector2f & Vector2f::operator /= (Value s) noexcept
{
x /= s;
y /= s;
return *this;
}
Vector2f & Vector2f::operator %= (Value s) noexcept
{
x = std::fmod(x, s);
y = std::fmod(y, s);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f & Vector2f::operator ++ () noexcept
{
++x;
++y;
return *this;
}
Vector2f & Vector2f::operator -- () noexcept
{
--x;
--y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::operator ++ (int) noexcept
{
Vector2f state(*this);
++x;
++y;
return state;
}
Vector2f Vector2f::operator -- (int) noexcept
{
Vector2f state(*this);
--x;
--y;
return state;
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::operator + (const Vector2f & v) const noexcept
{
return Vector2f(x + v.x, y + v.y);
}
Vector2f Vector2f::operator - (const Vector2f & v) const noexcept
{
return Vector2f(x - v.x, y - v.y);
}
Vector2f Vector2f::operator * (const Vector2f & v) const noexcept
{
return Vector2f(x * v.x, y * v.y);
}
Vector2f Vector2f::operator / (const Vector2f & v) const noexcept
{
return Vector2f(x / v.x, y / v.y);
}
Vector2f Vector2f::operator % (const Vector2f & v) const noexcept
{
return Vector2f(std::fmod(x, v.x), std::fmod(y, v.y));
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::operator + (Value s) const noexcept
{
return Vector2f(x + s, y + s);
}
Vector2f Vector2f::operator - (Value s) const noexcept
{
return Vector2f(x - s, y - s);
}
Vector2f Vector2f::operator * (Value s) const noexcept
{
return Vector2f(x * s, y * s);
}
Vector2f Vector2f::operator / (Value s) const noexcept
{
return Vector2f(x / s, y / s);
}
Vector2f Vector2f::operator % (Value s) const noexcept
{
return Vector2f(std::fmod(x, s), std::fmod(y, s));
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::operator + () const noexcept
{
return Vector2f(std::fabs(x), std::fabs(y));
}
Vector2f Vector2f::operator - () const noexcept
{
return Vector2f(-x, -y);
}
// ------------------------------------------------------------------------------------------------
bool Vector2f::operator == (const Vector2f & v) const noexcept
{
return EpsEq(x, v.x) && EpsEq(y, v.y);
}
bool Vector2f::operator != (const Vector2f & v) const noexcept
{
return !EpsEq(x, v.x) && !EpsEq(y, v.y);
}
bool Vector2f::operator < (const Vector2f & v) const noexcept
{
return std::isless(x, v.x) && std::isless(y, v.y);
}
bool Vector2f::operator > (const Vector2f & v) const noexcept
{
return std::isgreater(x, v.x) && std::isgreater(y, v.y);
}
bool Vector2f::operator <= (const Vector2f & v) const noexcept
{
return std::islessequal(x, v.x) && std::islessequal(y, v.y);
}
bool Vector2f::operator >= (const Vector2f & v) const noexcept
{
return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector2f::Cmp(const Vector2f & v) const noexcept
{
return *this == v ? 0 : (*this > v ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector2f::ToString() const noexcept
{
return ToStringF("%f,%f", x, y);
}
// ------------------------------------------------------------------------------------------------
void Vector2f::Set(Value ns) noexcept
{
x = ns;
y = ns;
}
void Vector2f::Set(Value nx, Value ny) noexcept
{
x = nx;
y = ny;
}
// ------------------------------------------------------------------------------------------------
void Vector2f::Set(const Vector2f & v) noexcept
{
x = v.x;
y = v.y;
}
void Vector2f::Set(const Vector2i & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
}
void Vector2f::Set(const Vector2u & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2f::Set(const SQChar * values, SQChar delim) noexcept
{
Set(GetVector2f(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Vector2f::Generate() noexcept
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
}
void Vector2f::Generate(Value min, Value max) noexcept
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
}
}
void Vector2f::Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept
{
if (xmax < xmin || ymax < ymin)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(ymin, ymax);
y = RandomVal<Value>::Get(xmin, xmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector2f Vector2f::Abs() const noexcept
{
return Vector2f(std::fabs(x), std::fabs(y));
}
// ================================================================================================
bool Register_Vector2f(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector2f> type");
typedef Vector2f::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector2f"), Sqrat::Class<Vector2f>(vm, _SC("Vector2f"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val>()
.SetStaticValue(_SC("delim"), &Vector2f::Delim)
.Var(_SC("x"), &Vector2f::x)
.Var(_SC("y"), &Vector2f::y)
.Prop(_SC("abs"), &Vector2f::Abs)
.Func(_SC("_tostring"), &Vector2f::ToString)
.Func(_SC("_cmp"), &Vector2f::Cmp)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_add"), &Vector2f::operator +)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_sub"), &Vector2f::operator -)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_mul"), &Vector2f::operator *)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_div"), &Vector2f::operator /)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("_modulo"), &Vector2f::operator %)
.Func<Vector2f (Vector2f::*)(void) const>(_SC("_unm"), &Vector2f::operator -)
.Overload<void (Vector2f::*)(Val)>(_SC("set"), &Vector2f::Set)
.Overload<void (Vector2f::*)(Val, Val)>(_SC("set"), &Vector2f::Set)
.Overload<void (Vector2f::*)(const Vector2f &)>(_SC("set_vec2f"), &Vector2f::Set)
.Overload<void (Vector2f::*)(const Vector2i &)>(_SC("set_vec2i"), &Vector2f::Set)
.Overload<void (Vector2f::*)(const Vector2u &)>(_SC("set_vec2u"), &Vector2f::Set)
.Overload<void (Vector2f::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector2f::Set)
.Overload<void (Vector2f::*)(void)>(_SC("generate"), &Vector2f::Generate)
.Overload<void (Vector2f::*)(Val, Val)>(_SC("generate"), &Vector2f::Generate)
.Overload<void (Vector2f::*)(Val, Val, Val, Val)>(_SC("generate"), &Vector2f::Generate)
.Func(_SC("clear"), &Vector2f::Clear)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opAddAssign"), &Vector2f::operator +=)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opSubAssign"), &Vector2f::operator -=)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opMulAssign"), &Vector2f::operator *=)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opDivAssign"), &Vector2f::operator /=)
.Func<Vector2f & (Vector2f::*)(const Vector2f &)>(_SC("opModAssign"), &Vector2f::operator %=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opAddAssignS"), &Vector2f::operator +=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opSubAssignS"), &Vector2f::operator -=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opMulAssignS"), &Vector2f::operator *=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opDivAssignS"), &Vector2f::operator /=)
.Func<Vector2f & (Vector2f::*)(Vector2f::Value)>(_SC("opModAssignS"), &Vector2f::operator %=)
.Func<Vector2f & (Vector2f::*)(void)>(_SC("opPreInc"), &Vector2f::operator ++)
.Func<Vector2f & (Vector2f::*)(void)>(_SC("opPreDec"), &Vector2f::operator --)
.Func<Vector2f (Vector2f::*)(int)>(_SC("opPostInc"), &Vector2f::operator ++)
.Func<Vector2f (Vector2f::*)(int)>(_SC("opPostDec"), &Vector2f::operator --)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opAdd"), &Vector2f::operator +)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opSub"), &Vector2f::operator -)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opMul"), &Vector2f::operator *)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opDiv"), &Vector2f::operator /)
.Func<Vector2f (Vector2f::*)(const Vector2f &) const>(_SC("opMod"), &Vector2f::operator %)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opAddS"), &Vector2f::operator +)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opSubS"), &Vector2f::operator -)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opMulS"), &Vector2f::operator *)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opDivS"), &Vector2f::operator /)
.Func<Vector2f (Vector2f::*)(Vector2f::Value) const>(_SC("opModS"), &Vector2f::operator %)
.Func<Vector2f (Vector2f::*)(void) const>(_SC("opUnPlus"), &Vector2f::operator +)
.Func<Vector2f (Vector2f::*)(void) const>(_SC("opUnMinus"), &Vector2f::operator -)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opEqual"), &Vector2f::operator ==)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opNotEqual"), &Vector2f::operator !=)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opLessThan"), &Vector2f::operator <)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opGreaterThan"), &Vector2f::operator >)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opLessEqual"), &Vector2f::operator <=)
.Func<bool (Vector2f::*)(const Vector2f &) const>(_SC("opGreaterEqual"), &Vector2f::operator >=)
);
LogDbg("Registration of <Vector2f> type was successful");
return true;
}
} // Namespace:: SqMod

112
source/Base/Vector2f.hpp Normal file
View File

@@ -0,0 +1,112 @@
#ifndef _BASE_VECTOR2F_HPP_
#define _BASE_VECTOR2F_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Vector2f
{
// --------------------------------------------------------------------------------------------
typedef SQFloat Value;
// --------------------------------------------------------------------------------------------
static const Vector2f NIL;
static const Vector2f MIN;
static const Vector2f MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Value x, y;
// --------------------------------------------------------------------------------------------
Vector2f() noexcept;
Vector2f(Value s) noexcept;
Vector2f(Value xv, Value yv) noexcept;
// --------------------------------------------------------------------------------------------
Vector2f(const Vector2i & v) noexcept;
Vector2f(const Vector2u & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2f(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
Vector2f(const Vector2f & v) noexcept;
Vector2f(Vector2f && v) noexcept;
// --------------------------------------------------------------------------------------------
~Vector2f();
// --------------------------------------------------------------------------------------------
Vector2f & operator = (const Vector2f & v) noexcept;
Vector2f & operator = (Vector2f && v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2f & operator = (Value s) noexcept;
Vector2f & operator = (const SQChar * values) noexcept;
Vector2f & operator = (const Vector2i & v) noexcept;
Vector2f & operator = (const Vector2u & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2f & operator += (const Vector2f & v) noexcept;
Vector2f & operator -= (const Vector2f & v) noexcept;
Vector2f & operator *= (const Vector2f & v) noexcept;
Vector2f & operator /= (const Vector2f & v) noexcept;
Vector2f & operator %= (const Vector2f & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2f & operator += (Value s) noexcept;
Vector2f & operator -= (Value s) noexcept;
Vector2f & operator *= (Value s) noexcept;
Vector2f & operator /= (Value s) noexcept;
Vector2f & operator %= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
Vector2f & operator ++ () noexcept;
Vector2f & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Vector2f operator ++ (int) noexcept;
Vector2f operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Vector2f operator + (const Vector2f & v) const noexcept;
Vector2f operator - (const Vector2f & v) const noexcept;
Vector2f operator * (const Vector2f & v) const noexcept;
Vector2f operator / (const Vector2f & v) const noexcept;
Vector2f operator % (const Vector2f & v) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2f operator + (Value s) const noexcept;
Vector2f operator - (Value s) const noexcept;
Vector2f operator * (Value s) const noexcept;
Vector2f operator / (Value s) const noexcept;
Vector2f operator % (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2f operator + () const noexcept;
Vector2f operator - () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Vector2f & v) const noexcept;
bool operator != (const Vector2f & v) const noexcept;
bool operator < (const Vector2f & v) const noexcept;
bool operator > (const Vector2f & v) const noexcept;
bool operator <= (const Vector2f & v) const noexcept;
bool operator >= (const Vector2f & v) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Vector2f & v) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nx, Value ny) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Vector2f & v) noexcept;
void Set(const Vector2i & v) noexcept;
void Set(const Vector2u & v) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { x = 0.0, y = 0.0; }
// --------------------------------------------------------------------------------------------
Vector2f Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_VECTOR2F_HPP_

640
source/Base/Vector2i.cpp Normal file
View File

@@ -0,0 +1,640 @@
#include "Base/Vector2i.hpp"
#include "Base/Vector2u.hpp"
#include "Base/Vector2f.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector2i Vector2i::NIL = Vector2i(0);
const Vector2i Vector2i::MIN = Vector2i(std::numeric_limits<Vector2i::Value>::min());
const Vector2i Vector2i::MAX = Vector2i(std::numeric_limits<Vector2i::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Vector2i::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i() noexcept
: x(0), y(0)
{
}
Vector2i::Vector2i(Value s) noexcept
: x(s), y(s)
{
}
Vector2i::Vector2i(Value xv, Value yv) noexcept
: x(xv), y(yv)
{
}
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(const Vector2u & v) noexcept
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
Vector2i::Vector2i(const Vector2f & v) noexcept
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(const SQChar * values, SQChar delim) noexcept
: Vector2i(GetVector2i(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector2i::Vector2i(const Vector2i & v) noexcept
: x(v.x), y(v.y)
{
}
Vector2i::Vector2i(Vector2i && v) noexcept
: x(v.x), y(v.y)
{
}
// ------------------------------------------------------------------------------------------------
Vector2i::~Vector2i()
{
}
// ------------------------------------------------------------------------------------------------
Vector2i & Vector2i::operator = (const Vector2i & v) noexcept
{
x = v.x;
y = v.y;
return *this;
}
Vector2i & Vector2i::operator = (Vector2i && v) noexcept
{
x = v.x;
y = v.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2i & Vector2i::operator = (Value s) noexcept
{
x = s;
y = s;
return *this;
}
Vector2i & Vector2i::operator = (const SQChar * values) noexcept
{
Set(GetVector2i(values, Delim));
return *this;
}
Vector2i & Vector2i::operator = (const Vector2u & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
Vector2i & Vector2i::operator = (const Vector2f & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2i & Vector2i::operator += (const Vector2i & v) noexcept
{
x += v.x;
y += v.y;
return *this;
}
Vector2i & Vector2i::operator -= (const Vector2i & v) noexcept
{
x -= v.x;
y -= v.y;
return *this;
}
Vector2i & Vector2i::operator *= (const Vector2i & v) noexcept
{
x *= v.x;
y *= v.y;
return *this;
}
Vector2i & Vector2i::operator /= (const Vector2i & v) noexcept
{
x /= v.x;
y /= v.y;
return *this;
}
Vector2i & Vector2i::operator %= (const Vector2i & v) noexcept
{
x %= v.x;
y %= v.y;
return *this;
}
Vector2i & Vector2i::operator &= (const Vector2i & v) noexcept
{
x &= v.x;
y &= v.y;
return *this;
}
Vector2i & Vector2i::operator |= (const Vector2i & v) noexcept
{
x |= v.x;
y |= v.y;
return *this;
}
Vector2i & Vector2i::operator ^= (const Vector2i & v) noexcept
{
x ^= v.x;
y ^= v.y;
return *this;
}
Vector2i & Vector2i::operator <<= (const Vector2i & v) noexcept
{
x <<= v.x;
y <<= v.y;
return *this;
}
Vector2i & Vector2i::operator >>= (const Vector2i & v) noexcept
{
x >>= v.x;
y >>= v.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2i & Vector2i::operator += (Value s) noexcept
{
x += s;
y += s;
return *this;
}
Vector2i & Vector2i::operator -= (Value s) noexcept
{
x -= s;
y -= s;
return *this;
}
Vector2i & Vector2i::operator *= (Value s) noexcept
{
x *= s;
y *= s;
return *this;
}
Vector2i & Vector2i::operator /= (Value s) noexcept
{
x /= s;
y /= s;
return *this;
}
Vector2i & Vector2i::operator %= (Value s) noexcept
{
x %= s;
y %= s;
return *this;
}
Vector2i & Vector2i::operator &= (Value s) noexcept
{
x &= s;
y &= s;
return *this;
}
Vector2i & Vector2i::operator |= (Value s) noexcept
{
x |= s;
y |= s;
return *this;
}
Vector2i & Vector2i::operator ^= (Value s) noexcept
{
x += s;
y += s;
return *this;
}
Vector2i & Vector2i::operator <<= (Value s) noexcept
{
x <<= s;
y <<= s;
return *this;
}
Vector2i & Vector2i::operator >>= (Value s) noexcept
{
x >>= s;
y >>= s;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2i & Vector2i::operator ++ () noexcept
{
++x;
++y;
return *this;
}
Vector2i & Vector2i::operator -- () noexcept
{
--x;
--y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::operator ++ (int) noexcept
{
Vector2i state(*this);
++x;
++y;
return state;
}
Vector2i Vector2i::operator -- (int) noexcept
{
Vector2i state(*this);
--x;
--y;
return state;
}
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::operator + (const Vector2i & v) const noexcept
{
return Vector2i(x + v.x, y + v.y);
}
Vector2i Vector2i::operator - (const Vector2i & v) const noexcept
{
return Vector2i(x - v.x, y - v.y);
}
Vector2i Vector2i::operator * (const Vector2i & v) const noexcept
{
return Vector2i(x * v.x, y * v.y);
}
Vector2i Vector2i::operator / (const Vector2i & v) const noexcept
{
return Vector2i(x / v.x, y / v.y);
}
Vector2i Vector2i::operator % (const Vector2i & v) const noexcept
{
return Vector2i(x % v.x, y % v.y);
}
Vector2i Vector2i::operator & (const Vector2i & v) const noexcept
{
return Vector2i(x & v.x, y & v.y);
}
Vector2i Vector2i::operator | (const Vector2i & v) const noexcept
{
return Vector2i(x | v.x, y | v.y);
}
Vector2i Vector2i::operator ^ (const Vector2i & v) const noexcept
{
return Vector2i(x ^ v.x, y ^ v.y);
}
Vector2i Vector2i::operator << (const Vector2i & v) const noexcept
{
return Vector2i(x << v.x, y << v.y);
}
Vector2i Vector2i::operator >> (const Vector2i & v) const noexcept
{
return Vector2i(x >> v.x, y >> v.y);
}
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::operator + (Value s) const noexcept
{
return Vector2i(x + s, y + s);
}
Vector2i Vector2i::operator - (Value s) const noexcept
{
return Vector2i(x - s, y - s);
}
Vector2i Vector2i::operator * (Value s) const noexcept
{
return Vector2i(x * s, y * s);
}
Vector2i Vector2i::operator / (Value s) const noexcept
{
return Vector2i(x / s, y / s);
}
Vector2i Vector2i::operator % (Value s) const noexcept
{
return Vector2i(x % s, y % s);
}
Vector2i Vector2i::operator & (Value s) const noexcept
{
return Vector2i(x & s, y & s);
}
Vector2i Vector2i::operator | (Value s) const noexcept
{
return Vector2i(x | s, y | s);
}
Vector2i Vector2i::operator ^ (Value s) const noexcept
{
return Vector2i(x ^ s, y ^ s);
}
Vector2i Vector2i::operator << (Value s) const noexcept
{
return Vector2i(x < s, y < s);
}
Vector2i Vector2i::operator >> (Value s) const noexcept
{
return Vector2i(x >> s, y >> s);
}
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::operator + () const noexcept
{
return Vector2i(std::abs(x), std::abs(y));
}
Vector2i Vector2i::operator - () const noexcept
{
return Vector2i(-x, -y);
}
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::operator ~ () const noexcept
{
return Vector2i(~x, ~y);
}
// ------------------------------------------------------------------------------------------------
bool Vector2i::operator == (const Vector2i & v) const noexcept
{
return (x == v.x) && (y == v.y);
}
bool Vector2i::operator != (const Vector2i & v) const noexcept
{
return (x != v.x) && (y != v.y);
}
bool Vector2i::operator < (const Vector2i & v) const noexcept
{
return (x < v.x) && (y < v.y);
}
bool Vector2i::operator > (const Vector2i & v) const noexcept
{
return (x > v.x) && (y > v.y);
}
bool Vector2i::operator <= (const Vector2i & v) const noexcept
{
return (x <= v.x) && (y <= v.y);
}
bool Vector2i::operator >= (const Vector2i & v) const noexcept
{
return (x >= v.x) && (y >= v.y);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector2i::Cmp(const Vector2i & v) const noexcept
{
return *this == v ? 0 : (*this > v ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector2i::ToString() const noexcept
{
return ToStringF("%d,%d", x, y);
}
// ------------------------------------------------------------------------------------------------
void Vector2i::Set(Value ns) noexcept
{
x = ns;
y = ns;
}
void Vector2i::Set(Value nx, Value ny) noexcept
{
x = nx;
y = ny;
}
// ------------------------------------------------------------------------------------------------
void Vector2i::Set(const Vector2i & v) noexcept
{
x = v.x;
y = v.y;
}
void Vector2i::Set(const Vector2u & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
}
void Vector2i::Set(const Vector2f & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2i::Set(const SQChar * values, SQChar delim) noexcept
{
Set(GetVector2i(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Vector2i::Generate() noexcept
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
}
void Vector2i::Generate(Value min, Value max) noexcept
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
}
}
void Vector2i::Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept
{
if (xmax < xmin || ymax < ymin)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(ymin, ymax);
y = RandomVal<Value>::Get(xmin, xmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::Abs() const noexcept
{
return Vector2i(std::abs(x), std::abs(y));
}
// ================================================================================================
bool Register_Vector2i(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector2i> type");
typedef Vector2i::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector2i"), Sqrat::Class<Vector2i>(vm, _SC("Vector2i"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val>()
.SetStaticValue(_SC("delim"), &Vector2i::Delim)
.Var(_SC("x"), &Vector2i::x)
.Var(_SC("y"), &Vector2i::y)
.Prop(_SC("abs"), &Vector2i::Abs)
.Func(_SC("_tostring"), &Vector2i::ToString)
.Func(_SC("_cmp"), &Vector2i::Cmp)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_add"), &Vector2i::operator +)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_sub"), &Vector2i::operator -)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_mul"), &Vector2i::operator *)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_div"), &Vector2i::operator /)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_modulo"), &Vector2i::operator %)
.Func<Vector2i (Vector2i::*)(void) const>(_SC("_unm"), &Vector2i::operator -)
.Overload<void (Vector2i::*)(Val)>(_SC("set"), &Vector2i::Set)
.Overload<void (Vector2i::*)(Val, Val)>(_SC("set"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const Vector2i &)>(_SC("set_vec2i"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const Vector2u &)>(_SC("set_vec2u"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const Vector2f &)>(_SC("set_vec2f"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector2i::Set)
.Overload<void (Vector2i::*)(void)>(_SC("generate"), &Vector2i::Generate)
.Overload<void (Vector2i::*)(Val, Val)>(_SC("generate"), &Vector2i::Generate)
.Overload<void (Vector2i::*)(Val, Val, Val, Val)>(_SC("generate"), &Vector2i::Generate)
.Func(_SC("clear"), &Vector2i::Clear)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opAddAssign"), &Vector2i::operator +=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opSubAssign"), &Vector2i::operator -=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opMulAssign"), &Vector2i::operator *=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opDivAssign"), &Vector2i::operator /=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opModAssign"), &Vector2i::operator %=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opAndAssign"), &Vector2i::operator &=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opOrAssign"), &Vector2i::operator |=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opXorAssign"), &Vector2i::operator ^=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opShlAssign"), &Vector2i::operator <<=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opShrAssign"), &Vector2i::operator >>=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opAddAssignS"), &Vector2i::operator +=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opSubAssignS"), &Vector2i::operator -=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opMulAssignS"), &Vector2i::operator *=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opDivAssignS"), &Vector2i::operator /=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opModAssignS"), &Vector2i::operator %=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opAndAssignS"), &Vector2i::operator &=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opOrAssignS"), &Vector2i::operator |=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opXorAssignS"), &Vector2i::operator ^=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opShlAssignS"), &Vector2i::operator <<=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opShrAssignS"), &Vector2i::operator >>=)
.Func<Vector2i & (Vector2i::*)(void)>(_SC("opPreInc"), &Vector2i::operator ++)
.Func<Vector2i & (Vector2i::*)(void)>(_SC("opPreDec"), &Vector2i::operator --)
.Func<Vector2i (Vector2i::*)(int)>(_SC("opPostInc"), &Vector2i::operator ++)
.Func<Vector2i (Vector2i::*)(int)>(_SC("opPostDec"), &Vector2i::operator --)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opAdd"), &Vector2i::operator +)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opSub"), &Vector2i::operator -)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opMul"), &Vector2i::operator *)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opDiv"), &Vector2i::operator /)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opMod"), &Vector2i::operator %)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opAnd"), &Vector2i::operator &)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opOr"), &Vector2i::operator |)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShl"), &Vector2i::operator ^)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShl"), &Vector2i::operator <<)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShr"), &Vector2i::operator >>)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opAddS"), &Vector2i::operator +)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opSubS"), &Vector2i::operator -)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opMulS"), &Vector2i::operator *)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opDivS"), &Vector2i::operator /)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opModS"), &Vector2i::operator %)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opAndS"), &Vector2i::operator &)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opOrS"), &Vector2i::operator |)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShlS"), &Vector2i::operator ^)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShlS"), &Vector2i::operator <<)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShrS"), &Vector2i::operator >>)
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opUnPlus"), &Vector2i::operator +)
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opUnMinus"), &Vector2i::operator -)
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opCom"), &Vector2i::operator ~)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opEqual"), &Vector2i::operator ==)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opNotEqual"), &Vector2i::operator !=)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opLessThan"), &Vector2i::operator <)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterThan"), &Vector2i::operator >)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opLessEqual"), &Vector2i::operator <=)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterEqual"), &Vector2i::operator >=)
);
LogDbg("Registration of <Vector2i> type was successful");
return true;
}
} // Namespace:: SqMod

134
source/Base/Vector2i.hpp Normal file
View File

@@ -0,0 +1,134 @@
#ifndef _BASE_VECTOR2I_HPP_
#define _BASE_VECTOR2I_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Vector2i
{
// --------------------------------------------------------------------------------------------
typedef SQInt32 Value;
// --------------------------------------------------------------------------------------------
static const Vector2i NIL;
static const Vector2i MIN;
static const Vector2i MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Value x, y;
// --------------------------------------------------------------------------------------------
Vector2i() noexcept;
Vector2i(Value s) noexcept;
Vector2i(Value xv, Value yv) noexcept;
// --------------------------------------------------------------------------------------------
Vector2i(const Vector2u & v) noexcept;
Vector2i(const Vector2f & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2i(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
Vector2i(const Vector2i & v) noexcept;
Vector2i(Vector2i && v) noexcept;
// --------------------------------------------------------------------------------------------
~Vector2i();
// --------------------------------------------------------------------------------------------
Vector2i & operator = (const Vector2i & v) noexcept;
Vector2i & operator = (Vector2i && v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2i & operator = (Value s) noexcept;
Vector2i & operator = (const SQChar * values) noexcept;
Vector2i & operator = (const Vector2u & v) noexcept;
Vector2i & operator = (const Vector2f & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2i & operator += (const Vector2i & v) noexcept;
Vector2i & operator -= (const Vector2i & v) noexcept;
Vector2i & operator *= (const Vector2i & v) noexcept;
Vector2i & operator /= (const Vector2i & v) noexcept;
Vector2i & operator %= (const Vector2i & v) noexcept;
Vector2i & operator &= (const Vector2i & v) noexcept;
Vector2i & operator |= (const Vector2i & v) noexcept;
Vector2i & operator ^= (const Vector2i & v) noexcept;
Vector2i & operator <<= (const Vector2i & v) noexcept;
Vector2i & operator >>= (const Vector2i & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2i & operator += (Value s) noexcept;
Vector2i & operator -= (Value s) noexcept;
Vector2i & operator *= (Value s) noexcept;
Vector2i & operator /= (Value s) noexcept;
Vector2i & operator %= (Value s) noexcept;
Vector2i & operator &= (Value s) noexcept;
Vector2i & operator |= (Value s) noexcept;
Vector2i & operator ^= (Value s) noexcept;
Vector2i & operator <<= (Value s) noexcept;
Vector2i & operator >>= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
Vector2i & operator ++ () noexcept;
Vector2i & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Vector2i operator ++ (int) noexcept;
Vector2i operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Vector2i operator + (const Vector2i & v) const noexcept;
Vector2i operator - (const Vector2i & v) const noexcept;
Vector2i operator * (const Vector2i & v) const noexcept;
Vector2i operator / (const Vector2i & v) const noexcept;
Vector2i operator % (const Vector2i & v) const noexcept;
Vector2i operator & (const Vector2i & v) const noexcept;
Vector2i operator | (const Vector2i & v) const noexcept;
Vector2i operator ^ (const Vector2i & v) const noexcept;
Vector2i operator << (const Vector2i & v) const noexcept;
Vector2i operator >> (const Vector2i & v) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2i operator + (Value s) const noexcept;
Vector2i operator - (Value s) const noexcept;
Vector2i operator * (Value s) const noexcept;
Vector2i operator / (Value s) const noexcept;
Vector2i operator % (Value s) const noexcept;
Vector2i operator & (Value s) const noexcept;
Vector2i operator | (Value s) const noexcept;
Vector2i operator ^ (Value s) const noexcept;
Vector2i operator << (Value s) const noexcept;
Vector2i operator >> (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2i operator + () const noexcept;
Vector2i operator - () const noexcept;
// --------------------------------------------------------------------------------------------
Vector2i operator ~ () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Vector2i & v) const noexcept;
bool operator != (const Vector2i & v) const noexcept;
bool operator < (const Vector2i & v) const noexcept;
bool operator > (const Vector2i & v) const noexcept;
bool operator <= (const Vector2i & v) const noexcept;
bool operator >= (const Vector2i & v) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Vector2i & v) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nx, Value ny) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Vector2i & v) noexcept;
void Set(const Vector2u & v) noexcept;
void Set(const Vector2f & v) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { x = 0, y = 0; }
// --------------------------------------------------------------------------------------------
Vector2i Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_VECTOR2I_HPP_

640
source/Base/Vector2u.cpp Normal file
View File

@@ -0,0 +1,640 @@
#include "Base/Vector2u.hpp"
#include "Base/Vector2f.hpp"
#include "Base/Vector2i.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector2u Vector2u::NIL = Vector2u(0);
const Vector2u Vector2u::MIN = Vector2u(std::numeric_limits<Vector2u::Value>::min());
const Vector2u Vector2u::MAX = Vector2u(std::numeric_limits<Vector2u::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Vector2u::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector2u::Vector2u() noexcept
: x(0), y(0)
{
}
Vector2u::Vector2u(Value s) noexcept
: x(s), y(s)
{
}
Vector2u::Vector2u(Value xv, Value yv) noexcept
: x(xv), y(yv)
{
}
// ------------------------------------------------------------------------------------------------
Vector2u::Vector2u(const Vector2i & v) noexcept
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
Vector2u::Vector2u(const Vector2f & v) noexcept
: x(static_cast<Value>(v.x)), y(static_cast<Value>(v.y))
{
}
// ------------------------------------------------------------------------------------------------
Vector2u::Vector2u(const SQChar * values, SQChar delim) noexcept
: Vector2u(GetVector2u(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector2u::Vector2u(const Vector2u & v) noexcept
: x(v.x), y(v.y)
{
}
Vector2u::Vector2u(Vector2u && v) noexcept
: x(v.x), y(v.y)
{
}
// ------------------------------------------------------------------------------------------------
Vector2u::~Vector2u()
{
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator = (const Vector2u & v) noexcept
{
x = v.x;
y = v.y;
return *this;
}
Vector2u & Vector2u::operator = (Vector2u && v) noexcept
{
x = v.x;
y = v.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator = (Value s) noexcept
{
x = s;
y = s;
return *this;
}
Vector2u & Vector2u::operator = (const SQChar * values) noexcept
{
Set(GetVector2i(values, Delim));
return *this;
}
Vector2u & Vector2u::operator = (const Vector2i & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
Vector2u & Vector2u::operator = (const Vector2f & v) noexcept
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator += (const Vector2u & v) noexcept
{
x += v.x;
y += v.y;
return *this;
}
Vector2u & Vector2u::operator -= (const Vector2u & v) noexcept
{
x -= v.x;
y -= v.y;
return *this;
}
Vector2u & Vector2u::operator *= (const Vector2u & v) noexcept
{
x *= v.x;
y *= v.y;
return *this;
}
Vector2u & Vector2u::operator /= (const Vector2u & v) noexcept
{
x /= v.x;
y /= v.y;
return *this;
}
Vector2u & Vector2u::operator %= (const Vector2u & v) noexcept
{
x %= v.x;
y %= v.y;
return *this;
}
Vector2u & Vector2u::operator &= (const Vector2u & v) noexcept
{
x &= v.x;
y &= v.y;
return *this;
}
Vector2u & Vector2u::operator |= (const Vector2u & v) noexcept
{
x |= v.x;
y |= v.y;
return *this;
}
Vector2u & Vector2u::operator ^= (const Vector2u & v) noexcept
{
x ^= v.x;
y ^= v.y;
return *this;
}
Vector2u & Vector2u::operator <<= (const Vector2u & v) noexcept
{
x <<= v.x;
y <<= v.y;
return *this;
}
Vector2u & Vector2u::operator >>= (const Vector2u & v) noexcept
{
x >>= v.x;
y >>= v.y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator += (Value s) noexcept
{
x += s;
y += s;
return *this;
}
Vector2u & Vector2u::operator -= (Value s) noexcept
{
x -= s;
y -= s;
return *this;
}
Vector2u & Vector2u::operator *= (Value s) noexcept
{
x *= s;
y *= s;
return *this;
}
Vector2u & Vector2u::operator /= (Value s) noexcept
{
x /= s;
y /= s;
return *this;
}
Vector2u & Vector2u::operator %= (Value s) noexcept
{
x %= s;
y %= s;
return *this;
}
Vector2u & Vector2u::operator &= (Value s) noexcept
{
x &= s;
y &= s;
return *this;
}
Vector2u & Vector2u::operator |= (Value s) noexcept
{
x |= s;
y |= s;
return *this;
}
Vector2u & Vector2u::operator ^= (Value s) noexcept
{
x ^= s;
y ^= s;
return *this;
}
Vector2u & Vector2u::operator <<= (Value s) noexcept
{
x <<= s;
y <<= s;
return *this;
}
Vector2u & Vector2u::operator >>= (Value s) noexcept
{
x >>= s;
y >>= s;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u & Vector2u::operator ++ () noexcept
{
++x;
++y;
return *this;
}
Vector2u & Vector2u::operator -- () noexcept
{
--x;
--y;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator ++ (int) noexcept
{
Vector2i state(*this);
++x;
++y;
return state;
}
Vector2u Vector2u::operator -- (int) noexcept
{
Vector2i state(*this);
--x;
--y;
return state;
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator + (const Vector2u & v) const noexcept
{
return Vector2i(x + v.x, y + v.y);
}
Vector2u Vector2u::operator - (const Vector2u & v) const noexcept
{
return Vector2i(x - v.x, y - v.y);
}
Vector2u Vector2u::operator * (const Vector2u & v) const noexcept
{
return Vector2i(x * v.x, y * v.y);
}
Vector2u Vector2u::operator / (const Vector2u & v) const noexcept
{
return Vector2i(x / v.x, y / v.y);
}
Vector2u Vector2u::operator % (const Vector2u & v) const noexcept
{
return Vector2i(x % v.x, y % v.y);
}
Vector2u Vector2u::operator & (const Vector2u & v) const noexcept
{
return Vector2i(x & v.x, y & v.y);
}
Vector2u Vector2u::operator | (const Vector2u & v) const noexcept
{
return Vector2i(x | v.x, y | v.y);
}
Vector2u Vector2u::operator ^ (const Vector2u & v) const noexcept
{
return Vector2i(x ^ v.x, y ^ v.y);
}
Vector2u Vector2u::operator << (const Vector2u & v) const noexcept
{
return Vector2i(x << v.x, y << v.y);
}
Vector2u Vector2u::operator >> (const Vector2u & v) const noexcept
{
return Vector2i(x >> v.x, y >> v.y);
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator + (Value s) const noexcept
{
return Vector2i(x + s, y + s);
}
Vector2u Vector2u::operator - (Value s) const noexcept
{
return Vector2i(x - s, y - s);
}
Vector2u Vector2u::operator * (Value s) const noexcept
{
return Vector2i(x - s, y - s);
}
Vector2u Vector2u::operator / (Value s) const noexcept
{
return Vector2i(x / s, y / s);
}
Vector2u Vector2u::operator % (Value s) const noexcept
{
return Vector2i(x % s, y % s);
}
Vector2u Vector2u::operator & (Value s) const noexcept
{
return Vector2i(x & s, y & s);
}
Vector2u Vector2u::operator | (Value s) const noexcept
{
return Vector2i(x | s, y | s);
}
Vector2u Vector2u::operator ^ (Value s) const noexcept
{
return Vector2i(x ^ s, y ^ s);
}
Vector2u Vector2u::operator << (Value s) const noexcept
{
return Vector2i(x << s, y << s);
}
Vector2u Vector2u::operator >> (Value s) const noexcept
{
return Vector2i(x >> s, y >> s);
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator + () const noexcept
{
return Vector2i(x, y);
}
Vector2u Vector2u::operator - () const noexcept
{
return Vector2i(0, 0);
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::operator ~ () const noexcept
{
return Vector2i(~x, ~y);
}
// ------------------------------------------------------------------------------------------------
bool Vector2u::operator == (const Vector2u & v) const noexcept
{
return (x == v.x) && (y == v.y);
}
bool Vector2u::operator != (const Vector2u & v) const noexcept
{
return (x != v.x) && (y != v.y);
}
bool Vector2u::operator < (const Vector2u & v) const noexcept
{
return (x < v.x) && (y < v.y);
}
bool Vector2u::operator > (const Vector2u & v) const noexcept
{
return (x > v.x) && (y > v.y);
}
bool Vector2u::operator <= (const Vector2u & v) const noexcept
{
return (x <= v.x) && (y <= v.y);
}
bool Vector2u::operator >= (const Vector2u & v) const noexcept
{
return (x >= v.x) && (y >= v.y);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector2u::Cmp(const Vector2u & v) const noexcept
{
return *this == v ? 0 : (*this > v ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector2u::ToString() const noexcept
{
return ToStringF("%u,%u", x, y);
}
// ------------------------------------------------------------------------------------------------
void Vector2u::Set(Value ns) noexcept
{
x = ns;
y = ns;
}
void Vector2u::Set(Value nx, Value ny) noexcept
{
x = nx;
y = ny;
}
// ------------------------------------------------------------------------------------------------
void Vector2u::Set(const Vector2u & v) noexcept
{
x = v.x;
y = v.y;
}
void Vector2u::Set(const Vector2i & v) noexcept
{
x = static_cast<SQInt32>(v.x);
y = static_cast<SQInt32>(v.y);
}
void Vector2u::Set(const Vector2f & v) noexcept
{
x = static_cast<SQInt32>(v.x);
y = static_cast<SQInt32>(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2u::Set(const SQChar * values, SQChar delim) noexcept
{
Set(GetVector2i(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Vector2u::Generate() noexcept
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
}
void Vector2u::Generate(Value min, Value max) noexcept
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
}
}
void Vector2u::Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept
{
if (xmax < xmin || ymax < ymin)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(ymin, ymax);
y = RandomVal<Value>::Get(xmin, xmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector2u Vector2u::Abs() const noexcept
{
return Vector2i(x, y);
}
// ================================================================================================
bool Register_Vector2u(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector2u> type");
typedef Vector2u::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector2u"), Sqrat::Class<Vector2u>(vm, _SC("Vector2u"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val>()
.SetStaticValue(_SC("delim"), &Vector2u::Delim)
.Var(_SC("x"), &Vector2u::x)
.Var(_SC("y"), &Vector2u::y)
.Prop(_SC("abs"), &Vector2u::Abs)
.Func(_SC("_tostring"), &Vector2u::ToString)
.Func(_SC("_cmp"), &Vector2u::Cmp)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_add"), &Vector2u::operator +)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_sub"), &Vector2u::operator -)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_mul"), &Vector2u::operator *)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_div"), &Vector2u::operator /)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("_modulo"), &Vector2u::operator %)
.Func<Vector2u (Vector2u::*)(void) const>(_SC("_unm"), &Vector2u::operator -)
.Overload<void (Vector2u::*)(Val)>(_SC("set"), &Vector2u::Set)
.Overload<void (Vector2u::*)(Val, Val)>(_SC("set"), &Vector2u::Set)
.Overload<void (Vector2u::*)(const Vector2u &)>(_SC("set_vec2u"), &Vector2u::Set)
.Overload<void (Vector2u::*)(const Vector2i &)>(_SC("set_vec2i"), &Vector2u::Set)
.Overload<void (Vector2u::*)(const Vector2f &)>(_SC("set_vec2f"), &Vector2u::Set)
.Overload<void (Vector2u::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector2u::Set)
.Overload<void (Vector2u::*)(void)>(_SC("generate"), &Vector2u::Generate)
.Overload<void (Vector2u::*)(Val, Val)>(_SC("generate"), &Vector2u::Generate)
.Overload<void (Vector2u::*)(Val, Val, Val, Val)>(_SC("generate"), &Vector2u::Generate)
.Func(_SC("clear"), &Vector2u::Clear)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opAddAssign"), &Vector2u::operator +=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opSubAssign"), &Vector2u::operator -=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opMulAssign"), &Vector2u::operator *=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opDivAssign"), &Vector2u::operator /=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opModAssign"), &Vector2u::operator %=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opAndAssign"), &Vector2u::operator &=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opOrAssign"), &Vector2u::operator |=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opXorAssign"), &Vector2u::operator ^=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opShlAssign"), &Vector2u::operator <<=)
.Func<Vector2u & (Vector2u::*)(const Vector2u &)>(_SC("opShrAssign"), &Vector2u::operator >>=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opAddAssignS"), &Vector2u::operator +=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opSubAssignS"), &Vector2u::operator -=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opMulAssignS"), &Vector2u::operator *=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opDivAssignS"), &Vector2u::operator /=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opModAssignS"), &Vector2u::operator %=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opAndAssignS"), &Vector2u::operator &=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opOrAssignS"), &Vector2u::operator |=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opXorAssignS"), &Vector2u::operator ^=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opShlAssignS"), &Vector2u::operator <<=)
.Func<Vector2u & (Vector2u::*)(Vector2u::Value)>(_SC("opShrAssignS"), &Vector2u::operator >>=)
.Func<Vector2u & (Vector2u::*)(void)>(_SC("opPreInc"), &Vector2u::operator ++)
.Func<Vector2u & (Vector2u::*)(void)>(_SC("opPreDec"), &Vector2u::operator --)
.Func<Vector2u (Vector2u::*)(int)>(_SC("opPostInc"), &Vector2u::operator ++)
.Func<Vector2u (Vector2u::*)(int)>(_SC("opPostDec"), &Vector2u::operator --)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opAdd"), &Vector2u::operator +)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opSub"), &Vector2u::operator -)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opMul"), &Vector2u::operator *)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opDiv"), &Vector2u::operator /)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opMod"), &Vector2u::operator %)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opAnd"), &Vector2u::operator &)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opOr"), &Vector2u::operator |)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opShl"), &Vector2u::operator ^)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opShl"), &Vector2u::operator <<)
.Func<Vector2u (Vector2u::*)(const Vector2u &) const>(_SC("opShr"), &Vector2u::operator >>)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opAddS"), &Vector2u::operator +)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opSubS"), &Vector2u::operator -)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opMulS"), &Vector2u::operator *)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opDivS"), &Vector2u::operator /)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opModS"), &Vector2u::operator %)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opAndS"), &Vector2u::operator &)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opOrS"), &Vector2u::operator |)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opShlS"), &Vector2u::operator ^)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opShlS"), &Vector2u::operator <<)
.Func<Vector2u (Vector2u::*)(Vector2u::Value) const>(_SC("opShrS"), &Vector2u::operator >>)
.Func<Vector2u (Vector2u::*)(void) const>(_SC("opUnPlus"), &Vector2u::operator +)
.Func<Vector2u (Vector2u::*)(void) const>(_SC("opUnMinus"), &Vector2u::operator -)
.Func<Vector2u (Vector2u::*)(void) const>(_SC("opCom"), &Vector2u::operator ~)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opEqual"), &Vector2u::operator ==)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opNotEqual"), &Vector2u::operator !=)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opLessThan"), &Vector2u::operator <)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opGreaterThan"), &Vector2u::operator >)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opLessEqual"), &Vector2u::operator <=)
.Func<bool (Vector2u::*)(const Vector2u &) const>(_SC("opGreaterEqual"), &Vector2u::operator >=)
);
LogDbg("Registration of <Vector2u> type was successful");
return true;
}
} // Namespace:: SqMod

142
source/Base/Vector2u.hpp Normal file
View File

@@ -0,0 +1,142 @@
#ifndef _BASE_VECTOR2U_HPP_
#define _BASE_VECTOR2U_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Vector2u
{
// --------------------------------------------------------------------------------------------
typedef SQUnsignedInteger32 Value;
// --------------------------------------------------------------------------------------------
static const Vector2u NIL;
static const Vector2u MIN;
static const Vector2u MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Value x, y;
// --------------------------------------------------------------------------------------------
Vector2u() noexcept;
Vector2u(Value s) noexcept;
Vector2u(Value xv, Value yv) noexcept;
// --------------------------------------------------------------------------------------------
Vector2u(const Vector2i & v) noexcept;
Vector2u(const Vector2f & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2u(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
Vector2u(const Vector2u & v) noexcept;
Vector2u(Vector2u && v) noexcept;
// --------------------------------------------------------------------------------------------
~Vector2u();
// --------------------------------------------------------------------------------------------
Vector2u & operator = (const Vector2u & v) noexcept;
Vector2u & operator = (Vector2u && v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2u & operator = (Value s) noexcept;
Vector2u & operator = (const SQChar * values) noexcept;
Vector2u & operator = (const Vector2i & v) noexcept;
Vector2u & operator = (const Vector2f & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2u & operator += (const Vector2u & v) noexcept;
Vector2u & operator -= (const Vector2u & v) noexcept;
Vector2u & operator *= (const Vector2u & v) noexcept;
Vector2u & operator /= (const Vector2u & v) noexcept;
Vector2u & operator %= (const Vector2u & v) noexcept;
Vector2u & operator &= (const Vector2u & v) noexcept;
Vector2u & operator |= (const Vector2u & v) noexcept;
Vector2u & operator ^= (const Vector2u & v) noexcept;
Vector2u & operator <<= (const Vector2u & v) noexcept;
Vector2u & operator >>= (const Vector2u & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector2u & operator += (Value s) noexcept;
Vector2u & operator -= (Value s) noexcept;
Vector2u & operator *= (Value s) noexcept;
Vector2u & operator /= (Value s) noexcept;
Vector2u & operator %= (Value s) noexcept;
Vector2u & operator &= (Value s) noexcept;
Vector2u & operator |= (Value s) noexcept;
Vector2u & operator ^= (Value s) noexcept;
Vector2u & operator <<= (Value s) noexcept;
Vector2u & operator >>= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
Vector2u & operator ++ () noexcept;
Vector2u & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator ++ (int) noexcept;
Vector2u operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator + (const Vector2u & v) const noexcept;
Vector2u operator + (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator - (const Vector2u & v) const noexcept;
Vector2u operator - (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator * (const Vector2u & v) const noexcept;
Vector2u operator * (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator / (const Vector2u & v) const noexcept;
Vector2u operator / (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator % (const Vector2u & v) const noexcept;
Vector2u operator % (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator & (const Vector2u & v) const noexcept;
Vector2u operator & (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator | (const Vector2u & v) const noexcept;
Vector2u operator | (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator ^ (const Vector2u & v) const noexcept;
Vector2u operator ^ (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator << (const Vector2u & v) const noexcept;
Vector2u operator << (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator >> (const Vector2u & v) const noexcept;
Vector2u operator >> (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator + () const noexcept;
Vector2u operator - () const noexcept;
// --------------------------------------------------------------------------------------------
Vector2u operator ~ () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Vector2u & v) const noexcept;
bool operator != (const Vector2u & v) const noexcept;
bool operator < (const Vector2u & v) const noexcept;
bool operator > (const Vector2u & v) const noexcept;
bool operator <= (const Vector2u & v) const noexcept;
bool operator >= (const Vector2u & v) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Vector2u & v) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nx, Value ny) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Vector2u & v) noexcept;
void Set(const Vector2i & v) noexcept;
void Set(const Vector2f & v) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { x = 0, y = 0; }
// --------------------------------------------------------------------------------------------
Vector2u Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_VECTOR2U_HPP_

516
source/Base/Vector3.cpp Normal file
View File

@@ -0,0 +1,516 @@
#include "Base/Vector3.hpp"
#include "Base/Vector4.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector3 Vector3::NIL = Vector3(0);
const Vector3 Vector3::MIN = Vector3(std::numeric_limits<Vector3::Value>::min());
const Vector3 Vector3::MAX = Vector3(std::numeric_limits<Vector3::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Vector3::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector3::Vector3() noexcept
: x(0.0), y(0.0), z(0.0)
{
}
Vector3::Vector3(Value s) noexcept
: x(s), y(s), z(s)
{
}
Vector3::Vector3(Value xv, Value yv, Value zv) noexcept
: x(xv), y(yv), z(zv)
{
}
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(const Vector4 & v) noexcept
: x(v.x), y(v.y), z(v.z)
{
}
Vector3::Vector3(const Quaternion & q) noexcept
: x(q.x), y(q.y), z(q.z)
{
}
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(const SQChar * values, char delim) noexcept
: Vector3(GetVector3(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector3::Vector3(const Vector3 & v) noexcept
: x(v.x), y(v.y), z(v.z)
{
}
Vector3::Vector3(Vector3 && v) noexcept
: x(v.x), y(v.y), z(v.z)
{
}
// ------------------------------------------------------------------------------------------------
Vector3::~Vector3()
{
}
// ------------------------------------------------------------------------------------------------
Vector3 & Vector3::operator = (const Vector3 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
return *this;
}
Vector3 & Vector3::operator = (Vector3 && v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector3 & Vector3::operator = (Value s) noexcept
{
x = s;
y = s;
z = s;
return *this;
}
Vector3 & Vector3::operator = (const Vector4 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
return *this;
}
Vector3 & Vector3::operator = (const Quaternion & q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector3 & Vector3::operator += (const Vector3 & v) noexcept
{
x += v.x;
y += v.y;
z += v.z;
return *this;
}
Vector3 & Vector3::operator -= (const Vector3 & v) noexcept
{
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
Vector3 & Vector3::operator *= (const Vector3 & v) noexcept
{
x *= v.x;
y *= v.y;
z *= v.z;
return *this;
}
Vector3 & Vector3::operator /= (const Vector3 & v) noexcept
{
x /= v.x;
y /= v.y;
z /= v.z;
return *this;
}
Vector3 & Vector3::operator %= (const Vector3 & v) noexcept
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
z = std::fmod(z, v.z);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector3 & Vector3::operator += (Value s) noexcept
{
x += s;
y += s;
z += s;
return *this;
}
Vector3 & Vector3::operator -= (Value s) noexcept
{
x -= s;
y -= s;
z -= s;
return *this;
}
Vector3 & Vector3::operator *= (Value s) noexcept
{
x *= s;
y *= s;
z *= s;
return *this;
}
Vector3 & Vector3::operator /= (Value s) noexcept
{
x /= s;
y /= s;
z /= s;
return *this;
}
Vector3 & Vector3::operator %= (Value s) noexcept
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector3 & Vector3::operator ++ () noexcept
{
++x;
++y;
++z;
return *this;
}
Vector3 & Vector3::operator -- () noexcept
{
--x;
--y;
--z;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator ++ (int) noexcept
{
Vector3 state(*this);
++x;
++y;
++z;
return state;
}
Vector3 Vector3::operator -- (int) noexcept
{
Vector3 state(*this);
--x;
--y;
--z;
return state;
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator + (const Vector3 & v) const noexcept
{
return Vector3(x + v.x, y + v.y, z + v.z);
}
Vector3 Vector3::operator - (const Vector3 & v) const noexcept
{
return Vector3(x - v.x, y - v.y, z - v.z);
}
Vector3 Vector3::operator * (const Vector3 & v) const noexcept
{
return Vector3(x * v.x, y * v.y, z * v.z);
}
Vector3 Vector3::operator / (const Vector3 & v) const noexcept
{
return Vector3(x / v.x, y / v.y, z / v.z);
}
Vector3 Vector3::operator % (const Vector3 & v) const noexcept
{
return Vector3(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z));
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator + (Value s) const noexcept
{
return Vector3(x + s, y + s, z + s);
}
Vector3 Vector3::operator - (Value s) const noexcept
{
return Vector3(x - s, y - s, z - s);
}
Vector3 Vector3::operator * (Value s) const noexcept
{
return Vector3(x * s, y * s, z * s);
}
Vector3 Vector3::operator / (Value s) const noexcept
{
return Vector3(x / s, y / s, z / s);
}
Vector3 Vector3::operator % (Value s) const noexcept
{
return Vector3(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s));
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator + () const noexcept
{
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
}
Vector3 Vector3::operator - () const noexcept
{
return Vector3(-x, -y, -z);
}
// ------------------------------------------------------------------------------------------------
bool Vector3::operator == (const Vector3 & v) const noexcept
{
return EpsEq(x, v.x) && EpsEq(y, v.y) && EpsEq(z, v.z);
}
bool Vector3::operator != (const Vector3 & v) const noexcept
{
return !EpsEq(x, v.x) && !EpsEq(y, v.y) && !EpsEq(z, v.z);
}
bool Vector3::operator < (const Vector3 & v) const noexcept
{
return std::isless(x, v.x) && std::isless(y, v.y) && std::isless(z, v.z);
}
bool Vector3::operator > (const Vector3 & v) const noexcept
{
return std::isgreater(x, v.x) && std::isgreater(y, v.y) && std::isgreater(z, v.z);
}
bool Vector3::operator <= (const Vector3 & v) const noexcept
{
return std::islessequal(x, v.x) && std::islessequal(y, v.y) && std::islessequal(z, v.z);
}
bool Vector3::operator >= (const Vector3 & v) const noexcept
{
return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y) && std::isgreaterequal(z, v.z);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector3::Cmp(const Vector3 & v) const noexcept
{
return *this == v ? 0 : (*this > v ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector3::ToString() const noexcept
{
return ToStringF("%f,%f,%f", x, y, z);
}
// ------------------------------------------------------------------------------------------------
void Vector3::Set(Value ns) noexcept
{
x = ns;
y = ns;
z = ns;
}
void Vector3::Set(Value nx, Value ny, Value nz) noexcept
{
x = nx;
y = ny;
z = nz;
}
// ------------------------------------------------------------------------------------------------
void Vector3::Set(const Vector3 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
}
void Vector3::Set(const Vector4 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
}
void Vector3::Set(const Quaternion & q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
}
// ------------------------------------------------------------------------------------------------
void Vector3::Set(const SQChar * values, char delim) noexcept
{
Set(GetVector3(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Vector3::Generate() noexcept
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
z = RandomVal<Value>::Get();
}
void Vector3::Generate(Value min, Value max) noexcept
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
z = RandomVal<Value>::Get(min, max);
}
}
void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax) noexcept
{
if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin))
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(xmin, xmax);
y = RandomVal<Value>::Get(ymin, ymax);
z = RandomVal<Value>::Get(zmin, zmax);
}
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::Abs() const noexcept
{
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
}
// ================================================================================================
bool Register_Vector3(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector3> type");
typedef Vector3::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector3"), Sqrat::Class<Vector3>(vm, _SC("Vector3"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Vector3::Delim)
.Var(_SC("x"), &Vector3::x)
.Var(_SC("y"), &Vector3::y)
.Var(_SC("z"), &Vector3::z)
.Prop(_SC("abs"), &Vector3::Abs)
.Func(_SC("_tostring"), &Vector3::ToString)
.Func(_SC("_cmp"), &Vector3::Cmp)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_add"), &Vector3::operator +)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_sub"), &Vector3::operator -)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_mul"), &Vector3::operator *)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_div"), &Vector3::operator /)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_modulo"), &Vector3::operator %)
.Func<Vector3 (Vector3::*)(void) const>(_SC("_unm"), &Vector3::operator -)
.Overload<void (Vector3::*)(Val)>(_SC("set"), &Vector3::Set)
.Overload<void (Vector3::*)(Val, Val, Val)>(_SC("set"), &Vector3::Set)
.Overload<void (Vector3::*)(const Vector3 &)>(_SC("set_vec3"), &Vector3::Set)
.Overload<void (Vector3::*)(const Vector4 &)>(_SC("set_vec4"), &Vector3::Set)
.Overload<void (Vector3::*)(const Quaternion &)>(_SC("set_quat"), &Vector3::Set)
.Overload<void (Vector3::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector3::Set)
.Overload<void (Vector3::*)(void)>(_SC("generate"), &Vector3::Generate)
.Overload<void (Vector3::*)(Val, Val)>(_SC("generate"), &Vector3::Generate)
.Overload<void (Vector3::*)(Val, Val, Val, Val, Val, Val)>(_SC("generate"), &Vector3::Generate)
.Func(_SC("clear"), &Vector3::Clear)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opAddAssign"), &Vector3::operator +=)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opSubAssign"), &Vector3::operator -=)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opMulAssign"), &Vector3::operator *=)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opDivAssign"), &Vector3::operator /=)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opModAssign"), &Vector3::operator %=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opAddAssignS"), &Vector3::operator +=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opSubAssignS"), &Vector3::operator -=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opMulAssignS"), &Vector3::operator *=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opDivAssignS"), &Vector3::operator /=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opModAssignS"), &Vector3::operator %=)
.Func<Vector3 & (Vector3::*)(void)>(_SC("opPreInc"), &Vector3::operator ++)
.Func<Vector3 & (Vector3::*)(void)>(_SC("opPreDec"), &Vector3::operator --)
.Func<Vector3 (Vector3::*)(int)>(_SC("opPostInc"), &Vector3::operator ++)
.Func<Vector3 (Vector3::*)(int)>(_SC("opPostDec"), &Vector3::operator --)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opAdd"), &Vector3::operator +)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opSub"), &Vector3::operator -)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opMul"), &Vector3::operator *)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opDiv"), &Vector3::operator /)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opMod"), &Vector3::operator %)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opAddS"), &Vector3::operator +)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opSubS"), &Vector3::operator -)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opMulS"), &Vector3::operator *)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opDivS"), &Vector3::operator /)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opModS"), &Vector3::operator %)
.Func<Vector3 (Vector3::*)(void) const>(_SC("opUnPlus"), &Vector3::operator +)
.Func<Vector3 (Vector3::*)(void) const>(_SC("opUnMinus"), &Vector3::operator -)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opEqual"), &Vector3::operator ==)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opNotEqual"), &Vector3::operator !=)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessThan"), &Vector3::operator <)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterThan"), &Vector3::operator >)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessEqual"), &Vector3::operator <=)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterEqual"), &Vector3::operator >=)
);
LogDbg("Registration of <Vector3> type was successful");
return true;
}
} // Namespace:: SqMod

111
source/Base/Vector3.hpp Normal file
View File

@@ -0,0 +1,111 @@
#ifndef _BASE_VECTOR3_HPP_
#define _BASE_VECTOR3_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Vector3
{
// --------------------------------------------------------------------------------------------
typedef SQFloat Value;
// --------------------------------------------------------------------------------------------
static const Vector3 NIL;
static const Vector3 MIN;
static const Vector3 MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Value x, y, z;
// --------------------------------------------------------------------------------------------
Vector3() noexcept;
Vector3(Value s) noexcept;
Vector3(Value xv, Value yv, Value zv) noexcept;
// --------------------------------------------------------------------------------------------
Vector3(const Vector4 & v) noexcept;
Vector3(const Quaternion & q) noexcept;
// --------------------------------------------------------------------------------------------
Vector3(const SQChar * values, char delim) noexcept;
// --------------------------------------------------------------------------------------------
Vector3(const Vector3 & v) noexcept;
Vector3(Vector3 && v) noexcept;
// --------------------------------------------------------------------------------------------
~Vector3();
// --------------------------------------------------------------------------------------------
Vector3 & operator = (const Vector3 & v) noexcept;
Vector3 & operator = (Vector3 && v) noexcept;
// --------------------------------------------------------------------------------------------
Vector3 & operator = (Value s) noexcept;
Vector3 & operator = (const Vector4 & v) noexcept;
Vector3 & operator = (const Quaternion & q) noexcept;
// --------------------------------------------------------------------------------------------
Vector3 & operator += (const Vector3 & v) noexcept;
Vector3 & operator -= (const Vector3 & v) noexcept;
Vector3 & operator *= (const Vector3 & v) noexcept;
Vector3 & operator /= (const Vector3 & v) noexcept;
Vector3 & operator %= (const Vector3 & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector3 & operator += (Value s) noexcept;
Vector3 & operator -= (Value s) noexcept;
Vector3 & operator *= (Value s) noexcept;
Vector3 & operator /= (Value s) noexcept;
Vector3 & operator %= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
Vector3 & operator ++ () noexcept;
Vector3 & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Vector3 operator ++ (int) noexcept;
Vector3 operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Vector3 operator + (const Vector3 & v) const noexcept;
Vector3 operator - (const Vector3 & v) const noexcept;
Vector3 operator * (const Vector3 & v) const noexcept;
Vector3 operator / (const Vector3 & v) const noexcept;
Vector3 operator % (const Vector3 & v) const noexcept;
// --------------------------------------------------------------------------------------------
Vector3 operator + (Value s) const noexcept;
Vector3 operator - (Value s) const noexcept;
Vector3 operator * (Value s) const noexcept;
Vector3 operator / (Value s) const noexcept;
Vector3 operator % (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector3 operator + () const noexcept;
Vector3 operator - () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Vector3 & v) const noexcept;
bool operator != (const Vector3 & v) const noexcept;
bool operator < (const Vector3 & v) const noexcept;
bool operator > (const Vector3 & v) const noexcept;
bool operator <= (const Vector3 & v) const noexcept;
bool operator >= (const Vector3 & v) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Vector3 & v) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nx, Value ny, Value nz) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Vector3 & v) noexcept;
void Set(const Vector4 & v) noexcept;
void Set(const Quaternion & q) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, char delim) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { x = 0.0, y = 0.0, z = 0.0; }
// --------------------------------------------------------------------------------------------
Vector3 Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_VECTOR3_HPP_

559
source/Base/Vector4.cpp Normal file
View File

@@ -0,0 +1,559 @@
#include "Base/Vector4.hpp"
#include "Base/Vector3.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Shared.hpp"
#include "Register.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
const Vector4 Vector4::NIL = Vector4(0);
const Vector4 Vector4::MIN = Vector4(std::numeric_limits<Vector4::Value>::min());
const Vector4 Vector4::MAX = Vector4(std::numeric_limits<Vector4::Value>::max());
// ------------------------------------------------------------------------------------------------
SQChar Vector4::Delim = ',';
// ------------------------------------------------------------------------------------------------
Vector4::Vector4() noexcept
: x(0.0), y(0.0), z(0.0), w(0.0)
{
}
Vector4::Vector4(Value s) noexcept
: x(s), y(s), z(s), w(s)
{
}
Vector4::Vector4(Value xv, Value yv, Value zv) noexcept
: x(xv), y(yv), z(zv), w(0.0)
{
}
Vector4::Vector4(Value xv, Value yv, Value zv, Value wv) noexcept
: x(xv), y(yv), z(zv), w(wv)
{
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(const Vector3 & v) noexcept
: x(v.x), y(v.y), z(v.z), w(0.0)
{
}
Vector4::Vector4(const Quaternion & q) noexcept
: x(q.x), y(q.y), z(q.z), w(q.w)
{
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(const SQChar * values, SQChar delim) noexcept
: Vector4(GetVector4(values, delim))
{
}
// ------------------------------------------------------------------------------------------------
Vector4::Vector4(const Vector4 & v) noexcept
: x(v.x), y(v.y), z(v.z), w(v.w)
{
}
Vector4::Vector4(Vector4 && v) noexcept
: x(v.x), y(v.y), z(v.z), w(v.w)
{
}
// ------------------------------------------------------------------------------------------------
Vector4::~Vector4()
{
}
// ------------------------------------------------------------------------------------------------
Vector4 & Vector4::operator = (const Vector4 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
w = v.w;
return *this;
}
Vector4 & Vector4::operator = (Vector4 && v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
w = v.w;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector4 & Vector4::operator = (Value s) noexcept
{
x = s;
y = s;
z = s;
w = s;
return *this;
}
Vector4 & Vector4::operator = (const Vector3 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
w = 0.0;
return *this;
}
Vector4 & Vector4::operator = (const Quaternion & q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector4 & Vector4::operator += (const Vector4 & v) noexcept
{
x += v.x;
y += v.y;
z += v.z;
w += v.w;
return *this;
}
Vector4 & Vector4::operator -= (const Vector4 & v) noexcept
{
x -= v.x;
y -= v.y;
z -= v.z;
w -= v.w;
return *this;
}
Vector4 & Vector4::operator *= (const Vector4 & v) noexcept
{
x *= v.x;
y *= v.y;
z *= v.z;
w *= v.w;
return *this;
}
Vector4 & Vector4::operator /= (const Vector4 & v) noexcept
{
x /= v.x;
y /= v.y;
z /= v.z;
w /= v.w;
return *this;
}
Vector4 & Vector4::operator %= (const Vector4 & v) noexcept
{
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
z = std::fmod(z, v.z);
w = std::fmod(w, v.w);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector4 & Vector4::operator += (Value s) noexcept
{
x += s;
y += s;
z += s;
w += s;
return *this;
}
Vector4 & Vector4::operator -= (Value s) noexcept
{
x -= s;
y -= s;
z -= s;
w -= s;
return *this;
}
Vector4 & Vector4::operator *= (Value s) noexcept
{
x *= s;
y *= s;
z *= s;
w *= s;
return *this;
}
Vector4 & Vector4::operator /= (Value s) noexcept
{
x /= s;
y /= s;
z /= s;
w /= s;
return *this;
}
Vector4 & Vector4::operator %= (Value s) noexcept
{
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
w = std::fmod(w, s);
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector4 & Vector4::operator ++ () noexcept
{
++x;
++y;
++z;
++w;
return *this;
}
Vector4 & Vector4::operator -- () noexcept
{
--x;
--y;
--z;
--w;
return *this;
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator ++ (int) noexcept
{
Vector4 state(*this);
++x;
++y;
++z;
++w;
return state;
}
Vector4 Vector4::operator -- (int) noexcept
{
Vector4 state(*this);
--x;
--y;
--z;
--w;
return state;
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator + (const Vector4 & v) const noexcept
{
return Vector4(x + v.x, y + v.y, z + v.z, w + v.w);
}
Vector4 Vector4::operator - (const Vector4 & v) const noexcept
{
return Vector4(x - v.x, y - v.y, z - v.z, w - v.w);
}
Vector4 Vector4::operator * (const Vector4 & v) const noexcept
{
return Vector4(x * v.x, y * v.y, z * v.z, w * v.w);
}
Vector4 Vector4::operator / (const Vector4 & v) const noexcept
{
return Vector4(x / v.x, y / v.y, z / v.z, w / v.w);
}
Vector4 Vector4::operator % (const Vector4 & v) const noexcept
{
return Vector4(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z), std::fmod(w, v.w));
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator + (Value s) const noexcept
{
return Vector4(x + s, y + s, z + s, w + s);
}
Vector4 Vector4::operator - (Value s) const noexcept
{
return Vector4(x - s, y - s, z - s, w - s);
}
Vector4 Vector4::operator * (Value s) const noexcept
{
return Vector4(x * s, y * s, z * s, w * s);
}
Vector4 Vector4::operator / (Value s) const noexcept
{
return Vector4(x / s, y / s, z / s, w / s);
}
Vector4 Vector4::operator % (Value s) const noexcept
{
return Vector4(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator + () const noexcept
{
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
}
Vector4 Vector4::operator - () const noexcept
{
return Vector4(-x, -y, -z, -w);
}
// ------------------------------------------------------------------------------------------------
bool Vector4::operator == (const Vector4 & v) const noexcept
{
return EpsEq(x, v.x) && EpsEq(y, v.y) && EpsEq(z, v.z) && EpsEq(w, v.w);
}
bool Vector4::operator != (const Vector4 & v) const noexcept
{
return !EpsEq(x, v.x) && !EpsEq(y, v.y) && !EpsEq(z, v.z) && !EpsEq(w, v.w);
}
bool Vector4::operator < (const Vector4 & v) const noexcept
{
return std::isless(x, v.x) && std::isless(y, v.y) && std::isless(z, v.z) && std::isless(w, v.w);
}
bool Vector4::operator > (const Vector4 & v) const noexcept
{
return std::isgreater(x, v.x) && std::isgreater(y, v.y) && std::isgreater(z, v.z) && std::isgreater(w, v.w);
}
bool Vector4::operator <= (const Vector4 & v) const noexcept
{
return std::islessequal(x, v.x) && std::islessequal(y, v.y) && std::islessequal(z, v.z) && std::islessequal(w, v.w);
}
bool Vector4::operator >= (const Vector4 & v) const noexcept
{
return std::isgreaterequal(x, v.x) && std::isgreaterequal(y, v.y) && std::isgreaterequal(z, v.z) && std::isgreaterequal(w, v.w);
}
// ------------------------------------------------------------------------------------------------
SQInteger Vector4::Cmp(const Vector4 & v) const noexcept
{
return *this == v ? 0 : (*this > v ? 1 : -1);
}
// ------------------------------------------------------------------------------------------------
const SQChar * Vector4::ToString() const noexcept
{
return ToStringF("%f,%f,%f,%f", x, y, z, w);
}
// ------------------------------------------------------------------------------------------------
void Vector4::Set(Value ns) noexcept
{
x = ns;
y = ns;
z = ns;
w = ns;
}
void Vector4::Set(Value nx, Value ny, Value nz) noexcept
{
x = nx;
y = ny;
z = nz;
}
void Vector4::Set(Value nx, Value ny, Value nz, Value nw) noexcept
{
x = nx;
y = ny;
z = nz;
w = nw;
}
// ------------------------------------------------------------------------------------------------
void Vector4::Set(const Vector4 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
w = v.w;
}
void Vector4::Set(const Vector3 & v) noexcept
{
x = v.x;
y = v.y;
z = v.z;
w = 0.0;
}
void Vector4::Set(const Quaternion & q) noexcept
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
}
// ------------------------------------------------------------------------------------------------
void Vector4::Set(const SQChar * values, SQChar delim) noexcept
{
Set(GetVector4(values, delim));
}
// ------------------------------------------------------------------------------------------------
void Vector4::Generate() noexcept
{
x = RandomVal<Value>::Get();
y = RandomVal<Value>::Get();
z = RandomVal<Value>::Get();
w = RandomVal<Value>::Get();
}
void Vector4::Generate(Value min, Value max) noexcept
{
if (max < min)
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
z = RandomVal<Value>::Get(min, max);
y = RandomVal<Value>::Get(min, max);
}
}
void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax) noexcept
{
if (std::isless(xmax, xmin) || std::isless(ymax, ymin) || std::isless(zmax, zmin) || std::isless(wmax, wmin))
{
LogErr("max value is lower than min value");
}
else
{
x = RandomVal<Value>::Get(xmin, xmax);
y = RandomVal<Value>::Get(ymin, ymax);
z = RandomVal<Value>::Get(zmin, zmax);
y = RandomVal<Value>::Get(ymin, ymax);
}
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::Abs() const noexcept
{
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
}
// ================================================================================================
bool Register_Vector4(HSQUIRRELVM vm)
{
LogDbg("Beginning registration of <Vector4> type");
typedef Vector4::Value Val;
Sqrat::RootTable(vm).Bind(_SC("Vector4"), Sqrat::Class<Vector4>(vm, _SC("Vector4"))
.Ctor()
.Ctor<Val>()
.Ctor<Val, Val, Val>()
.Ctor<Val, Val, Val, Val>()
.Ctor<const SQChar *, SQChar>()
.SetStaticValue(_SC("delim"), &Vector4::Delim)
.Var(_SC("x"), &Vector4::x)
.Var(_SC("y"), &Vector4::y)
.Var(_SC("z"), &Vector4::z)
.Var(_SC("w"), &Vector4::w)
.Prop(_SC("abs"), &Vector4::Abs)
.Func(_SC("_tostring"), &Vector4::ToString)
.Func(_SC("_cmp"), &Vector4::Cmp)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_add"), &Vector4::operator +)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_sub"), &Vector4::operator -)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_mul"), &Vector4::operator *)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_div"), &Vector4::operator /)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_modulo"), &Vector4::operator %)
.Func<Vector4 (Vector4::*)(void) const>(_SC("_unm"), &Vector4::operator -)
.Overload<void (Vector4::*)(Val)>(_SC("set"), &Vector4::Set)
.Overload<void (Vector4::*)(Val, Val, Val)>(_SC("set"), &Vector4::Set)
.Overload<void (Vector4::*)(Val, Val, Val, Val)>(_SC("set"), &Vector4::Set)
.Overload<void (Vector4::*)(const Vector4 &)>(_SC("set_vec4"), &Vector4::Set)
.Overload<void (Vector4::*)(const Vector3 &)>(_SC("set_vec3"), &Vector4::Set)
.Overload<void (Vector4::*)(const Quaternion &)>(_SC("set_quat"), &Vector4::Set)
.Overload<void (Vector4::*)(const SQChar *, SQChar)>(_SC("set_str"), &Vector4::Set)
.Overload<void (Vector4::*)(void)>(_SC("generate"), &Vector4::Generate)
.Overload<void (Vector4::*)(Val, Val)>(_SC("generate"), &Vector4::Generate)
.Overload<void (Vector4::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("generate"), &Vector4::Generate)
.Func(_SC("clear"), &Vector4::Clear)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opAddAssign"), &Vector4::operator +=)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opSubAssign"), &Vector4::operator -=)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opMulAssign"), &Vector4::operator *=)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opDivAssign"), &Vector4::operator /=)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opModAssign"), &Vector4::operator %=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opAddAssignS"), &Vector4::operator +=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opSubAssignS"), &Vector4::operator -=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opMulAssignS"), &Vector4::operator *=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opDivAssignS"), &Vector4::operator /=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opModAssignS"), &Vector4::operator %=)
.Func<Vector4 & (Vector4::*)(void)>(_SC("opPreInc"), &Vector4::operator ++)
.Func<Vector4 & (Vector4::*)(void)>(_SC("opPreDec"), &Vector4::operator --)
.Func<Vector4 (Vector4::*)(int)>(_SC("opPostInc"), &Vector4::operator ++)
.Func<Vector4 (Vector4::*)(int)>(_SC("opPostDec"), &Vector4::operator --)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opAdd"), &Vector4::operator +)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opSub"), &Vector4::operator -)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opMul"), &Vector4::operator *)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opDiv"), &Vector4::operator /)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opMod"), &Vector4::operator %)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opAddS"), &Vector4::operator +)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opSubS"), &Vector4::operator -)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opMulS"), &Vector4::operator *)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opDivS"), &Vector4::operator /)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opModS"), &Vector4::operator %)
.Func<Vector4 (Vector4::*)(void) const>(_SC("opUnPlus"), &Vector4::operator +)
.Func<Vector4 (Vector4::*)(void) const>(_SC("opUnMinus"), &Vector4::operator -)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opEqual"), &Vector4::operator ==)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opNotEqual"), &Vector4::operator !=)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opLessThan"), &Vector4::operator <)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterThan"), &Vector4::operator >)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opLessEqual"), &Vector4::operator <=)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterEqual"), &Vector4::operator >=)
);
LogDbg("Registration of <Vector4> type was successful");
return true;
}
} // Namespace:: SqMod

113
source/Base/Vector4.hpp Normal file
View File

@@ -0,0 +1,113 @@
#ifndef _BASE_VECTOR4_HPP_
#define _BASE_VECTOR4_HPP_
// ------------------------------------------------------------------------------------------------
#include "Config.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* ...
*/
struct Vector4
{
// --------------------------------------------------------------------------------------------
typedef SQFloat Value;
// --------------------------------------------------------------------------------------------
static const Vector4 NIL;
static const Vector4 MIN;
static const Vector4 MAX;
// --------------------------------------------------------------------------------------------
static SQChar Delim;
// --------------------------------------------------------------------------------------------
Value x, y, z, w;
// --------------------------------------------------------------------------------------------
Vector4() noexcept;
Vector4(Value s) noexcept;
Vector4(Value xv, Value yv, Value zv) noexcept;
Vector4(Value xv, Value yv, Value zv, Value wv) noexcept;
// --------------------------------------------------------------------------------------------
Vector4(const Vector3 & v) noexcept;
Vector4(const Quaternion & q) noexcept;
// --------------------------------------------------------------------------------------------
Vector4(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
Vector4(const Vector4 & v) noexcept;
Vector4(Vector4 && v) noexcept;
// --------------------------------------------------------------------------------------------
~Vector4();
// --------------------------------------------------------------------------------------------
Vector4 & operator = (const Vector4 & v) noexcept;
Vector4 & operator = (Vector4 && v) noexcept;
// --------------------------------------------------------------------------------------------
Vector4 & operator = (Value s) noexcept;
Vector4 & operator = (const Vector3 & v) noexcept;
Vector4 & operator = (const Quaternion & q) noexcept;
// --------------------------------------------------------------------------------------------
Vector4 & operator += (const Vector4 & v) noexcept;
Vector4 & operator -= (const Vector4 & v) noexcept;
Vector4 & operator *= (const Vector4 & v) noexcept;
Vector4 & operator /= (const Vector4 & v) noexcept;
Vector4 & operator %= (const Vector4 & v) noexcept;
// --------------------------------------------------------------------------------------------
Vector4 & operator += (Value s) noexcept;
Vector4 & operator -= (Value s) noexcept;
Vector4 & operator *= (Value s) noexcept;
Vector4 & operator /= (Value s) noexcept;
Vector4 & operator %= (Value s) noexcept;
// --------------------------------------------------------------------------------------------
Vector4 & operator ++ () noexcept;
Vector4 & operator -- () noexcept;
// --------------------------------------------------------------------------------------------
Vector4 operator ++ (int) noexcept;
Vector4 operator -- (int) noexcept;
// --------------------------------------------------------------------------------------------
Vector4 operator + (const Vector4 & v) const noexcept;
Vector4 operator - (const Vector4 & v) const noexcept;
Vector4 operator * (const Vector4 & v) const noexcept;
Vector4 operator / (const Vector4 & v) const noexcept;
Vector4 operator % (const Vector4 & v) const noexcept;
// --------------------------------------------------------------------------------------------
Vector4 operator + (Value s) const noexcept;
Vector4 operator - (Value s) const noexcept;
Vector4 operator * (Value s) const noexcept;
Vector4 operator / (Value s) const noexcept;
Vector4 operator % (Value s) const noexcept;
// --------------------------------------------------------------------------------------------
Vector4 operator + () const noexcept;
Vector4 operator - () const noexcept;
// --------------------------------------------------------------------------------------------
bool operator == (const Vector4 & v) const noexcept;
bool operator != (const Vector4 & v) const noexcept;
bool operator < (const Vector4 & v) const noexcept;
bool operator > (const Vector4 & v) const noexcept;
bool operator <= (const Vector4 & v) const noexcept;
bool operator >= (const Vector4 & v) const noexcept;
// --------------------------------------------------------------------------------------------
SQInteger Cmp(const Vector4 & v) const noexcept;
// --------------------------------------------------------------------------------------------
const SQChar * ToString() const noexcept;
// --------------------------------------------------------------------------------------------
void Set(Value ns) noexcept;
void Set(Value nx, Value ny, Value nz) noexcept;
void Set(Value nx, Value ny, Value nz, Value nw) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const Vector4 & v) noexcept;
void Set(const Vector3 & v) noexcept;
void Set(const Quaternion & q) noexcept;
// --------------------------------------------------------------------------------------------
void Set(const SQChar * values, SQChar delim) noexcept;
// --------------------------------------------------------------------------------------------
void Generate() noexcept;
void Generate(Value min, Value max) noexcept;
void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax) noexcept;
// --------------------------------------------------------------------------------------------
void Clear() noexcept { x = 0.0, y = 0.0, z = 0.0, w = 0.0; }
// --------------------------------------------------------------------------------------------
Vector4 Abs() const noexcept;
};
} // Namespace:: SqMod
#endif // _BASE_VECTOR4_HPP_