|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TCG_SIZE_H
|
|
Toshihiro Shimizu |
890ddd |
#define TCG_SIZE_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace tcg {
|
|
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 {
|
|
Shinya Kitaoka |
120a6e |
typedef T value_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
T w, h;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SizeT() : w(), h() {}
|
|
Shinya Kitaoka |
120a6e |
SizeT(T w_, T h_) : w(w_), h(h_) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool empty() const { return (w <= 0) || (h <= 0); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SizeT &operator+=(const SizeT &other) {
|
|
Shinya Kitaoka |
120a6e |
w += other.w, h += other.h;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
SizeT &operator-=(const SizeT &other) {
|
|
Shinya Kitaoka |
120a6e |
w -= other.w, h -= other.h;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend SizeT<t> operator+(const SizeT<t> &a, const SizeT<t> &b) {</t></t></t>
|
|
Shinya Kitaoka |
120a6e |
return SizeT<t>(a.w + b.w, a.h + b.h);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend SizeT<t> operator-(const SizeT<t> &a, const SizeT<t> &b) {</t></t></t>
|
|
Shinya Kitaoka |
120a6e |
return SizeT<t>(a.w - b.w, a.h - b.h);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
SizeT &operator*=(K k) {
|
|
Shinya Kitaoka |
120a6e |
w *= k, h *= k;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
SizeT &operator/=(K k) {
|
|
Shinya Kitaoka |
120a6e |
w /= k, h /= k;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
friend SizeT<t> operator*(K k, const SizeT<t> &a) {</t></t>
|
|
Shinya Kitaoka |
120a6e |
return SizeT<t>(k * a.w, k * a.h);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
friend SizeT<t> operator*(const SizeT<t> &a, K k) {</t></t>
|
|
Shinya Kitaoka |
120a6e |
return SizeT<t>(a.w * k, a.h * k);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
friend SizeT<t> operator/(const SizeT<t> &a, K k) {</t></t>
|
|
Shinya Kitaoka |
120a6e |
return SizeT<t>(a.w / k, a.h / k);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SizeT &operator&=(const SizeT &other) {
|
|
Shinya Kitaoka |
120a6e |
if (other.w < w) w = other.w;
|
|
Shinya Kitaoka |
120a6e |
if (other.h < h) h = other.h;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SizeT &operator|=(const SizeT &other) {
|
|
Shinya Kitaoka |
120a6e |
if (other.w > w) w = other.w;
|
|
Shinya Kitaoka |
120a6e |
if (other.h > h) h = other.h;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend SizeT<t> operator&(const SizeT<t> &a, const SizeT<t> &b) {</t></t></t>
|
|
Shinya Kitaoka |
120a6e |
SizeT<t> tmp(a);</t>
|
|
Shinya Kitaoka |
120a6e |
return tmp &= b;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
friend SizeT<t> operator|(const SizeT<t> &a, const SizeT<t> &b) {</t></t></t>
|
|
Shinya Kitaoka |
120a6e |
SizeT<t> tmp(a);</t>
|
|
Shinya Kitaoka |
120a6e |
return tmp |= b;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
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 {
|
|
Shinya Kitaoka |
120a6e |
typedef T value_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
T w, h, d;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
Size3T() : w(), h(), d() {}
|
|
Shinya Kitaoka |
120a6e |
Size3T(T w_, T h_, T d_) : w(w_), h(h_), d(d_) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool empty() const { return (w <= 0) || (h <= 0) || (d <= 0); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Size3T &operator+=(const Size3T &other) {
|
|
Shinya Kitaoka |
120a6e |
w += other.w, h += other.h, d += other.d;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
Size3T &operator-=(const Size3T &other) {
|
|
Shinya Kitaoka |
120a6e |
w -= other.w, h -= other.h, d -= other.d;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend Size3T<t> operator+(const Size3T<t> &a, const Size3T<t> &b) {</t></t></t>
|
|
Shinya Kitaoka |
120a6e |
return SizeT<t>(a.w + b.w, a.h + b.h, a.d + b.d);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend Size3T<t> operator-(const Size3T<t> &a, const Size3T<t> &b) {</t></t></t>
|
|
Shinya Kitaoka |
120a6e |
return SizeT<t>(a.w - b.w, a.h - b.h, a.d + b.d);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
Size3T &operator*=(K k) {
|
|
Shinya Kitaoka |
120a6e |
w *= k, h *= k, d *= k;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
Size3T &operator/=(K k) {
|
|
Shinya Kitaoka |
120a6e |
w /= k, h /= k, d /= k;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
friend Size3T<t> operator*(K k, const Size3T<t> &a) {</t></t>
|
|
Shinya Kitaoka |
120a6e |
return Size3T<t>(k * a.w, k * a.h, k * a.d);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
friend Size3T<t> operator*(const Size3T<t> &a, K k) {</t></t>
|
|
Shinya Kitaoka |
120a6e |
return Size3T<t>(a.w * k, a.h * k, a.d * k);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename k=""></typename>
|
|
Shinya Kitaoka |
120a6e |
friend Size3T<t> operator/(const Size3T<t> &a, K k) {</t></t>
|
|
Shinya Kitaoka |
120a6e |
return Size3T<t>(a.w / k, a.h / k, a.d / k);</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Size3T &operator&=(const Size3T &other) {
|
|
Shinya Kitaoka |
120a6e |
if (other.w < w) w = other.w;
|
|
Shinya Kitaoka |
120a6e |
if (other.h < h) h = other.h;
|
|
Shinya Kitaoka |
120a6e |
if (other.d < d) d = other.d;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Size3T &operator|=(const Size3T &other) {
|
|
Shinya Kitaoka |
120a6e |
if (other.w > w) w = other.w;
|
|
Shinya Kitaoka |
120a6e |
if (other.h > h) h = other.h;
|
|
Shinya Kitaoka |
120a6e |
if (other.d > d) d = other.d;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend Size3T<t> operator&(const Size3T<t> &a, const Size3T<t> &b) {</t></t></t>
|
|
Shinya Kitaoka |
120a6e |
Size3T<t> tmp(a);</t>
|
|
Shinya Kitaoka |
120a6e |
return tmp &= b;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
friend Size3T<t> operator|(const Size3T<t> &a, const Size3T<t> &b) {</t></t></t>
|
|
Shinya Kitaoka |
120a6e |
Size3T<t> tmp(a);</t>
|
|
Shinya Kitaoka |
120a6e |
return tmp |= b;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
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 {
|
|
Shinya Kitaoka |
120a6e |
static const int size = N;
|
|
Shinya Kitaoka |
120a6e |
typedef T value_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
T span[N];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SizeN() {}
|
|
Shinya Kitaoka |
120a6e |
SizeN(const T &t) { std::fill(span, span + N, t); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template <typename it=""></typename>
|
|
Shinya Kitaoka |
120a6e |
SizeN(It begin, It end) {
|
|
Shinya Kitaoka |
120a6e |
std::copy(begin, end, span);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// To be completed...
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace tcg
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // TCG_SIZE_H
|