Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TCG_SIZE_H
Toshihiro Shimizu 890ddd
#define TCG_SIZE_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace tcg
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Bidimensional size  class
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
struct SizeT {
Toshihiro Shimizu 890ddd
	typedef T value_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	T w, h;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	SizeT() : w(), h() {}
Toshihiro Shimizu 890ddd
	SizeT(T w_, T h_) : w(w_), h(h_) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool empty() const { return (w <= 0) || (h <= 0); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	SizeT &operator+=(const SizeT &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		w += other.w, h += other.h;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	SizeT &operator-=(const SizeT &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		w -= other.w, h -= other.h;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend SizeT<t> operator+(const SizeT<t> &a, const SizeT<t> &b)</t></t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return SizeT<t>(a.w + b.w, a.h + b.h);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend SizeT<t> operator-(const SizeT<t> &a, const SizeT<t> &b)</t></t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return SizeT<t>(a.w - b.w, a.h - b.h);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	SizeT &operator*=(K k)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		w *= k, h *= k;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	SizeT &operator/=(K k)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		w /= k, h /= k;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	friend SizeT<t> operator*(K k, const SizeT<t> &a)</t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return SizeT<t>(k * a.w, k * a.h);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	friend SizeT<t> operator*(const SizeT<t> &a, K k)</t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return SizeT<t>(a.w * k, a.h * k);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	friend SizeT<t> operator/(const SizeT<t> &a, K k)</t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return SizeT<t>(a.w / k, a.h / k);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	SizeT &operator&=(const SizeT &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (other.w < w)
Toshihiro Shimizu 890ddd
			w = other.w;
Toshihiro Shimizu 890ddd
		if (other.h < h)
Toshihiro Shimizu 890ddd
			h = other.h;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	SizeT &operator|=(const SizeT &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (other.w > w)
Toshihiro Shimizu 890ddd
			w = other.w;
Toshihiro Shimizu 890ddd
		if (other.h > h)
Toshihiro Shimizu 890ddd
			h = other.h;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend SizeT<t> operator&(const SizeT<t> &a, const SizeT<t> &b)</t></t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		SizeT<t> tmp(a);</t>
Toshihiro Shimizu 890ddd
		return tmp &= b;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	friend SizeT<t> operator|(const SizeT<t> &a, const SizeT<t> &b)</t></t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		SizeT<t> tmp(a);</t>
Toshihiro Shimizu 890ddd
		return tmp |= b;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef SizeT<int> SizeI;</int>
Toshihiro Shimizu 890ddd
typedef SizeI Size;
Toshihiro Shimizu 890ddd
typedef SizeT<double> SizeD;</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Tridimensional size  class
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
struct Size3T {
Toshihiro Shimizu 890ddd
	typedef T value_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	T w, h, d;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Size3T() : w(), h(), d() {}
Toshihiro Shimizu 890ddd
	Size3T(T w_, T h_, T d_) : w(w_), h(h_), d(d_) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool empty() const { return (w <= 0) || (h <= 0) || (d <= 0); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Size3T &operator+=(const Size3T &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		w += other.w, h += other.h, d += other.d;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	Size3T &operator-=(const Size3T &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		w -= other.w, h -= other.h, d -= other.d;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend Size3T<t> operator+(const Size3T<t> &a, const Size3T<t> &b)</t></t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return SizeT<t>(a.w + b.w, a.h + b.h, a.d + b.d);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend Size3T<t> operator-(const Size3T<t> &a, const Size3T<t> &b)</t></t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return SizeT<t>(a.w - b.w, a.h - b.h, a.d + b.d);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	Size3T &operator*=(K k)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		w *= k, h *= k, d *= k;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	Size3T &operator/=(K k)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		w /= k, h /= k, d /= k;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	friend Size3T<t> operator*(K k, const Size3T<t> &a)</t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return Size3T<t>(k * a.w, k * a.h, k * a.d);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	friend Size3T<t> operator*(const Size3T<t> &a, K k)</t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return Size3T<t>(a.w * k, a.h * k, a.d * k);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename k=""></typename>
Toshihiro Shimizu 890ddd
	friend Size3T<t> operator/(const Size3T<t> &a, K k)</t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return Size3T<t>(a.w / k, a.h / k, a.d / k);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Size3T &operator&=(const Size3T &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (other.w < w)
Toshihiro Shimizu 890ddd
			w = other.w;
Toshihiro Shimizu 890ddd
		if (other.h < h)
Toshihiro Shimizu 890ddd
			h = other.h;
Toshihiro Shimizu 890ddd
		if (other.d < d)
Toshihiro Shimizu 890ddd
			d = other.d;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Size3T &operator|=(const Size3T &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (other.w > w)
Toshihiro Shimizu 890ddd
			w = other.w;
Toshihiro Shimizu 890ddd
		if (other.h > h)
Toshihiro Shimizu 890ddd
			h = other.h;
Toshihiro Shimizu 890ddd
		if (other.d > d)
Toshihiro Shimizu 890ddd
			d = other.d;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend Size3T<t> operator&(const Size3T<t> &a, const Size3T<t> &b)</t></t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		Size3T<t> tmp(a);</t>
Toshihiro Shimizu 890ddd
		return tmp &= b;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	friend Size3T<t> operator|(const Size3T<t> &a, const Size3T<t> &b)</t></t></t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		Size3T<t> tmp(a);</t>
Toshihiro Shimizu 890ddd
		return tmp |= b;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef Size3T<int> Size3I;</int>
Toshihiro Shimizu 890ddd
typedef Size3I Size3;
Toshihiro Shimizu 890ddd
typedef Size3T<double> Size3D;</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    N-dimensional size  class
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <int n,="" t="" typename=""></int>
Toshihiro Shimizu 890ddd
struct SizeN {
Toshihiro Shimizu 890ddd
	static const int size = N;
Toshihiro Shimizu 890ddd
	typedef T value_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	T span[N];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	SizeN() {}
Toshihiro Shimizu 890ddd
	SizeN(const T &t) { std::fill(span, span + N, t); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <typename it=""></typename>
Toshihiro Shimizu 890ddd
	SizeN(It begin, It end)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::copy(begin, end, span);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// To be completed...
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace tcg
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // TCG_SIZE_H