diff --git a/toonz/sources/include/tcg/auto.h b/toonz/sources/include/tcg/auto.h deleted file mode 100644 index ae4252a..0000000 --- a/toonz/sources/include/tcg/auto.h +++ /dev/null @@ -1,199 +0,0 @@ -#pragma once - -#ifndef TCG_AUTO_H -#define TCG_AUTO_H - -#include "base.h" -#include "traits.h" - -/* \file auto.h - - \brief This file contains template classes able to perform special - operations upon - instance destruction. - - \details These classes can be useful to enforce block-scoped operations at a - block's - entry point, considering that a block end can be far away, or the - function - could return abruptly at several different points. -*/ - -namespace tcg { - -//******************************************************************************* -// tcg::auto_type definition -//******************************************************************************* - -struct _auto_type { - mutable bool m_destruct; - -public: - _auto_type(bool destruct) : m_destruct(destruct) {} - _auto_type(const _auto_type &other) : m_destruct(other.m_destruct) { - other.m_destruct = false; - } - _auto_type &operator=(const _auto_type &other) { - m_destruct = other.m_destruct, other.m_destruct = false; - return *this; - } -}; - -typedef const _auto_type &auto_type; - -//******************************************************************************* -// tcg::auto_func definition -//******************************************************************************* - -template -struct auto_zerary : public _auto_type { - Op m_op; - -public: - auto_zerary(bool destruct = true) : _auto_type(destruct) {} - ~auto_zerary() { - if (this->m_destruct) m_op(); - } -}; - -//-------------------------------------------------------------------- - -template ::arg1_type> -struct auto_unary : public _auto_type { - T m_arg1; - Op m_op; - -public: - auto_unary(bool destruct = true) : _auto_type(destruct) {} - auto_unary(Op op, T arg, bool destruct = true) - : _auto_type(destruct), m_arg1(arg), m_op(op) {} - ~auto_unary() { - if (this->m_destruct) m_op(m_arg1); - } -}; - -//-------------------------------------------------------------------- - -template ::arg1_type, - typename T2 = typename function_traits::arg2_type> -struct auto_binary : public _auto_type { - T1 m_arg1; - T2 m_arg2; - Op m_op; - -public: - auto_binary(bool destruct = true) : _auto_type(destruct) {} - auto_binary(Op op, T1 arg1, T2 arg2, bool destruct = true) - : _auto_type(destruct), m_arg1(arg1), m_arg2(arg2), m_op(op) {} - ~auto_binary() { - if (this->m_destruct) m_op(m_arg1, m_arg2); - } -}; - -//******************************************************************************* -// Helper functions -//******************************************************************************* - -template -auto_zerary make_auto(Op op, bool destruct = true) { - return auto_zerary(op, destruct); -} - -template -auto_unary make_auto(Op op, T &arg1, bool destruct = true) { - return auto_unary(op, arg1, destruct); -} - -template -auto_unary make_auto(Op op, const T &arg1, bool destruct = true) { - return auto_unary(op, arg1, destruct); -} - -template -auto_binary make_auto(Op op, T1 &arg1, T2 &arg2, bool destruct = true) { - return auto_binary(op, arg1, arg2, destruct); -} - -template -auto_binary make_auto(Op op, const T1 &arg1, T2 &arg2, - bool destruct = true) { - return auto_binary(op, arg1, arg2, destruct); -} - -template -auto_binary make_auto(Op op, T1 &arg1, const T2 &arg2, - bool destruct = true) { - return auto_binary(op, arg1, arg2, destruct); -} - -template -auto_binary make_auto(Op op, const T1 &arg1, const T2 &arg2, - bool destruct = true) { - return auto_binary(op, arg1, arg2, destruct); -} - -//******************************************************************************* -// tcg::auto_reset definition -//******************************************************************************* - -template -class auto_reset { - typedef T var_type; - -public: - var_type &m_var; - -public: - auto_reset(var_type &var) : m_var(var) {} - ~auto_reset() { m_var = val; } - -private: - auto_reset(const auto_reset &); - auto_reset &operator=(const auto_reset &); -}; - -//******************************************************************************* -// tcg::auto_backup definition -//******************************************************************************* - -template -struct auto_backup { - typedef T var_type; - -public: - var_type m_backup; - var_type *m_original; - -public: - auto_backup() : m_original() {} - auto_backup(var_type &original) : m_original(&original), m_backup(original) {} - auto_backup(var_type *original) : m_original(original) { - if (m_original) m_backup = *m_original; - } - ~auto_backup() { - if (m_original) *m_original = m_backup; - } - - void reset(T &original) { - m_original = &original; - m_backup = original; - } - void reset(T *original) { - m_original = original; - if (m_original) m_backup = *original; - } - - T *release() { - T *original = m_original; - m_original = 0; - return original; - } - -private: - auto_backup(const auto_backup &); - auto_backup &operator=(const auto_backup &); -}; - -} // namespace tcg - -#endif // TCG_AUTO_H diff --git a/toonz/sources/include/tcg/functional.h b/toonz/sources/include/tcg/functional.h deleted file mode 100644 index 19fa867..0000000 --- a/toonz/sources/include/tcg/functional.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#ifndef TCG_FUNCTIONAL_H -#define TCG_FUNCTIONAL_H - -#include "traits.h" - -// std includes -#include - -//********************************************************************************** -// Logical functor combinators -//********************************************************************************** - -namespace tcg { - -template -class unary_and - : public std::unary_function::arg_type, - bool> { - Fn1 m_fn1; - Fn2 m_fn2; - -public: - unary_and(const Fn1 &fn1, const Fn2 &fn2) : m_fn1(fn1), m_fn2(fn2) {} - - bool operator()(const typename function_traits::arg_type &t) const { - return m_fn1(t) && m_fn2(t); - } -}; - -template -unary_and and1(const Fn1 &fn1, const Fn2 &fn2) { - return unary_and(fn1, fn2); -} - -//---------------------------------------------------------------------------------- - -template -class unary_or - : public std::unary_function::arg_type, - bool> { - Fn1 m_fn1; - Fn2 m_fn2; - -public: - unary_or(const Fn1 &fn1, const Fn2 &fn2) : m_fn1(fn1), m_fn2(fn2) {} - - bool operator()(const typename function_traits::arg_type &t) const { - return m_fn1(t) || m_fn2(t); - } -}; - -template -unary_or or1(const Fn1 &fn1, const Fn2 &fn2) { - return unary_or(fn1, fn2); -} - -} // namespace tcg - -#endif // TCG_FUNCTIONAL_H diff --git a/toonz/sources/include/tcg/hpp/image_iterator.hpp b/toonz/sources/include/tcg/hpp/image_iterator.hpp deleted file mode 100644 index cc0e154..0000000 --- a/toonz/sources/include/tcg/hpp/image_iterator.hpp +++ /dev/null @@ -1,249 +0,0 @@ -#pragma once - -#ifndef TCG_IMAGE_ITERATOR_HPP -#define TCG_IMAGE_ITERATOR_HPP - -// tcg includes -#include "../image_iterator.h" -#include "../pixel_ops.h" - -namespace tcg { - -//*************************************************************************** -// image_edge_iterator implementation -//*************************************************************************** - -template -template -image_edge_iterator::image_edge_iterator(const Img &img, int x, - int y, int dirX, - int dirY) - : m_lx_1(image_traits::width(img) - 1) - , m_ly_1(image_traits::height(img) - 1) - , m_wrap(image_traits::wrap(img)) - , m_pos(x, y) - , m_dir(dirX, dirY) - , m_outsideColor(image_traits::outsideColor(img)) - , m_elbowColor(m_outsideColor) - , m_pix(image_traits::pixel(img, x, y)) - , m_turn(UNKNOWN) { - pixels(m_leftPix, m_rightPix); - colors(m_leftColor, m_rightColor); -} - -//--------------------------------------------------------------------------------------------- - -template -inline void image_edge_iterator::pixels(iter pixLeft, - iter pixRight) { - if (m_dir.y) - if (m_dir.y > 0) - pixLeft = m_pix - 1, pixRight = m_pix; - else - pixLeft = m_pix - m_wrap, pixRight = pixLeft - 1; - else if (m_dir.x > 0) - pixLeft = m_pix, pixRight = m_pix - m_wrap; - else - pixRight = m_pix - 1, pixLeft = pixRight - m_wrap; -} - -//--------------------------------------------------------------------------------------------- - -template -inline void image_edge_iterator::colors( - value_type &leftColor, value_type &rightColor) { - if (m_dir.y) - if (m_dir.y > 0) { - if (m_pos.y > m_ly_1) - leftColor = rightColor = m_outsideColor; - else { - leftColor = (m_pos.x > 0) ? *m_leftPix : m_outsideColor; - rightColor = (m_pos.x <= m_lx_1) ? *m_rightPix : m_outsideColor; - } - } else { - if (m_pos.y < 1) - leftColor = rightColor = m_outsideColor; - else { - leftColor = (m_pos.x <= m_lx_1) ? *m_leftPix : m_outsideColor; - rightColor = (m_pos.x > 0) ? *m_rightPix : m_outsideColor; - } - } - else if (m_dir.x > 0) { - if (m_pos.x > m_lx_1) - leftColor = rightColor = m_outsideColor; - else { - leftColor = (m_pos.y <= m_ly_1) ? *m_leftPix : m_outsideColor; - rightColor = (m_pos.y > 0) ? *m_rightPix : m_outsideColor; - } - } else { - if (m_pos.x < 1) - leftColor = rightColor = m_outsideColor; - else { - leftColor = (m_pos.y > 0) ? *m_leftPix : m_outsideColor; - rightColor = (m_pos.y <= m_ly_1) ? *m_rightPix : m_outsideColor; - } - } -} - -//--------------------------------------------------------------------------------------------- - -template -inline void image_edge_iterator::turn( - const value_type &newLeftColor, const value_type &newRightColor, - policy) { - if (newLeftColor == m_rightColor) { - if (newRightColor == m_leftColor) - turnAmbiguous(newLeftColor, newRightColor); - else - turnLeft(); - } else { - if (newRightColor != m_rightColor) - turnRight(); - else - m_turn = STRAIGHT; - } - - m_elbowColor = newLeftColor; - - pixels(m_leftPix, m_rightPix); -} - -//--------------------------------------------------------------------------------------------- - -template -inline void image_edge_iterator::turn( - const value_type &newLeftColor, const value_type &newRightColor, - policy) { - if (newRightColor == m_leftColor) { - if (newLeftColor == m_rightColor) - turnAmbiguous(newLeftColor, newRightColor); - else - turnRight(); - } else { - if (newLeftColor != m_leftColor) - turnLeft(); - else - m_turn = STRAIGHT; - } - - m_elbowColor = newRightColor; - - pixels(m_leftPix, m_rightPix); -} - -//--------------------------------------------------------------------------------------------- - -template -inline void image_edge_iterator::turnAmbiguous( - const value_type &newLeftColor, const value_type &newRightColor) { - UCHAR count1 = 0, count2 = 0; - - value_type val; - - // Check the 4x4 neighbourhood and connect the minority color - if (m_pos.x > 2) { - val = *(m_pix - 2); - if (val == m_leftColor) - ++count1; - else if (val == m_rightColor) - ++count2; - - val = *(m_pix - 2 - m_wrap); - if (val == m_leftColor) - ++count1; - else if (val == m_rightColor) - ++count2; - } - - if (m_pos.x < m_lx_1) { - val = *(m_pix + 1); - if (val == m_leftColor) - ++count1; - else if (val == m_rightColor) - ++count2; - - val = *(m_pix + 1 - m_wrap); - if (val == m_leftColor) - ++count1; - else if (val == m_rightColor) - ++count2; - } - - if (m_pos.y > 2) { - int wrap2 = m_wrap << 1; - - val = *(m_pix - wrap2); - if (val == m_leftColor) - ++count1; - else if (val == m_rightColor) - ++count2; - - val = *(m_pix - wrap2 - 1); - if (val == m_leftColor) - ++count1; - else if (val == m_rightColor) - ++count2; - } - - if (m_pos.y < m_ly_1) { - val = *(m_pix + m_wrap); - if (val == m_leftColor) - ++count1; - else if (val == m_rightColor) - ++count2; - - val = *(m_pix + m_wrap - 1); - if (val == m_leftColor) - ++count1; - else if (val == m_rightColor) - ++count2; - } - - // Minority connection - join the one with less count - if (count1 <= count2) - turnRight(); // Join m_leftColor == newRightColor - else if (count1 > count2) - turnLeft(); // Join m_rightColor == newLeftColor - - m_turn |= AMBIGUOUS; -} - -//--------------------------------------------------------------------------------------------- - -template -void image_edge_iterator::advance(policy) { - value_type newLeftColor = m_leftColor, newRightColor = m_rightColor; - - int pixAdd = m_dir.y * m_wrap + m_dir.x; - - m_pos.x += m_dir.x, m_pos.y += m_dir.y; - m_pix += pixAdd, m_leftPix += pixAdd, m_rightPix += pixAdd; - m_leftColor = newLeftColor; - - colors(newLeftColor, newRightColor); - - turn(newLeftColor, newRightColor); - colors(m_leftColor, m_rightColor); -} - -//--------------------------------------------------------------------------------------------- - -template -void image_edge_iterator::advance(policy) { - value_type newLeftColor = m_leftColor, newRightColor = m_rightColor; - - int pixAdd = m_dir.y * m_wrap + m_dir.x; - - m_pos.x += m_dir.x, m_pos.y += m_dir.y; - m_pix += pixAdd, m_leftPix += pixAdd, m_rightPix += pixAdd; - m_rightColor = newRightColor; - - colors(newLeftColor, newRightColor); - - turn(newLeftColor, newRightColor); - colors(m_leftColor, m_rightColor); -} - -} // namespace tcg - -#endif // TCG_IMAGE_ITERATOR_HPP diff --git a/toonz/sources/include/tcg/image_iterator.h b/toonz/sources/include/tcg/image_iterator.h deleted file mode 100644 index ba5494e..0000000 --- a/toonz/sources/include/tcg/image_iterator.h +++ /dev/null @@ -1,255 +0,0 @@ - - -#ifndef TCG_IMAGE_ITERATOR_H -#define TCG_IMAGE_ITERATOR_H - -// tcg includes -#include "tcg_ptr.h" -#include "tcg_image_ops.h" -#include "tcg_point.h" - -// STD includes -#include - -namespace tcg { - -//********************************************************************************************************* -// Image Iterator class -//********************************************************************************************************* - -/*! - The image_iterator class models an iterator accessing pixels of an image along - its rows. -*/ - -template -class image_iterator : public iterator_traits::inheritable_iterator_type { - typedef typename iterator_traits::inheritable_iterator_type iter; - -public: - typedef typename iter::iterator_category iterator_category; - typedef typename iter::value_type value_type; - typedef typename iter::difference_type difference_type; - typedef typename iter::pointer pointer; - typedef typename iter::reference reference; - -public: - image_iterator() {} - - template - image_iterator(const Img &img, int x, int y) - : iter(image_traits::pixel(img, x, y)) - , m_base(image_traits::pixel(img, 0, 0)) - , m_lx(image_traits::width(img)) - , m_ly(image_traits::height(img)) - , m_wrap(image_traits::wrap(img)) - , m_skew(m_wrap - lx) {} - - int x() const { return (iter::operator-(m_base)) % m_wrap; } - int y() const { return (iter::operator-(m_base)) / m_wrap; } - - image_iterator &operator++() { - iter::operator++(); - if (x() >= m_lx) iter::operator+=(m_skew); - return *this; - } - image_iterator operator++(int) { - image_iterator it(*this); - operator++(); - return it; - } - - image_iterator &operator--() { - iter::operator--(); - if (x() < 0) iter::operator-=(m_skew); - return *this; - } - image_iterator operator--(int) { - image_iterator it(*this); - operator--(); - return it; - } - - image_iterator &operator+=(difference_type d) { - int yCount = (x() + d) / m_lx; - iter::operator+=((d - yCount * m_lx) + yCount * m_wrap); - return *this; - } - image_iterator operator+(difference_type d) const { - image_iterator it(*this); - it += d; - return it; - } - - image_iterator operator-(difference_type d) const { return operator+(-d); } - image_iterator &operator-=(difference_type d) { return operator+=(-d); } - - difference_type operator-(const image_iterator &other) const { - return (x() - other.x()) + m_lx * (y() - other.y()); - } - - reference operator[](difference_type d) const { - const image_iterator &it = operator+(d); - return *it; - } - -protected: - iter m_base; - int m_lx, m_ly, m_wrap, m_skew; -}; - -//********************************************************************************************************* -// image_edge_iterator class -//********************************************************************************************************* - -enum _iei_adherence_policy { LEFT_ADHERENCE, RIGHT_ADHERENCE }; - -/*! - The image_edge_iterator class models a forward iterator following the contour - of - an image area of uniform color. -*/ - -template -class image_edge_iterator { - typedef typename iterator_traits::inheritable_iterator_type iter; - -public: - typedef std::forward_iterator_tag iterator_category; - typedef typename iter::value_type value_type; - typedef typename iter::difference_type difference_type; - typedef typename iter::pointer pointer; - typedef typename iter::reference reference; - -public: - enum { adherence = _adherence }; - - enum Direction { - STRAIGHT = 0x0, - LEFT = 0x1, - RIGHT = 0x2, - AMBIGUOUS = 0x4, - UNKNOWN = 0x8, - AMBIGUOUS_LEFT = LEFT | AMBIGUOUS, - AMBIGUOUS_RIGHT = RIGHT | AMBIGUOUS - }; - -public: - image_edge_iterator() {} - - template - image_edge_iterator(const Img &img, int x, int y, int dirX, int dirY); - - const Point &pos() const { return m_pos; } - const Point &dir() const { return m_dir; } - - const value_type &leftColor() const { return m_leftColor; } - const value_type &rightColor() const { return m_rightColor; } - - const value_type &color() const { return color(policy<_adherence>()); } - const value_type &oppositeColor() const { - return oppositeColor(policy<_adherence>()); - } - const value_type &elbowColor() const { return m_elbowColor; } - - iter leftPixel() const { return m_leftPix; } - iter rightPixel() const { return m_rightPix; } - - iter pixel() const { return pixel(policy<_adherence>()); } - iter oppositePixel() const { return oppositePixel(policy<_adherence>()); } - - Direction turn() const { return Direction(m_turn); } - -public: - // Iterator functions - - bool operator==(const image_edge_iterator &it) const { - return (m_pos == it.m_pos) && (m_dir == it.m_dir); - } - bool operator!=(const image_edge_iterator &it) const { - return !operator==(it); - } - - image_edge_iterator &operator++() { - advance(policy<_adherence>()); - return *this; - } - image_edge_iterator operator++(int) { - image_edge_iterator temp(*this); - operator++(); - return temp; - } - -private: - void pixels(iter pixLeft, iter pixRight); - void colors(value_type &leftColor, value_type &rightColor); - - void turnLeft() { - int temp = m_dir.x; - m_dir.x = -m_dir.y; - m_dir.y = temp; - m_turn = LEFT; - } - void turnRight() { - int temp = m_dir.x; - m_dir.x = m_dir.y; - m_dir.y = -temp; - m_turn = RIGHT; - } - - void turn(const value_type &newLeftColor, const value_type &newRightColor) { - turn(newLeftColor, newRightColor, policy<_adherence>()); - } - void turnAmbiguous(const value_type &newLeftColor, - const value_type &newRightColor); - -private: - template <_iei_adherence_policy> - struct policy {}; - - const value_type &color(policy) const { return m_leftColor; } - const value_type &color(policy) const { - return m_rightColor; - } - - const value_type &oppositeColor(policy) const { - return m_rightColor; - } - const value_type &oppositeColor(policy) const { - return m_leftColor; - } - - iter pixel(policy) const { return m_leftPix; } - iter pixel(policy) const { return m_rightPix; } - - iter oppositePixel(policy) const { return m_rightPix; } - iter oppositePixel(policy) const { return m_leftPix; } - - void turn(const value_type &newLeftColor, const value_type &newRightColor, - policy); - void turn(const value_type &newLeftColor, const value_type &newRightColor, - policy); - - void advance(policy); - void advance(policy); - -private: - int m_lx_1, m_ly_1, m_wrap; - - Point m_pos, m_dir; - - value_type m_leftColor, m_rightColor, m_outsideColor, m_elbowColor; - iter m_pix, m_leftPix, m_rightPix; - - int m_turn; -}; - -} // namespace tcg - -#endif // TCG_IMAGE_ITERATOR_H - -//===================================================================================== - -#ifdef INCLUDE_HPP -#include "hpp/image_iterator.hpp" -#endif // INCLUDE_HPP diff --git a/toonz/sources/include/tcg/rect.h b/toonz/sources/include/tcg/rect.h deleted file mode 100644 index 1b1bdb7..0000000 --- a/toonz/sources/include/tcg/rect.h +++ /dev/null @@ -1,276 +0,0 @@ -#pragma once - -#ifndef TCG_RECT_H -#define TCG_RECT_H - -#include "point.h" -#include "size.h" - -// STD includes -#include - -namespace tcg { - -//********************************************************************************** -// Bidimensional Rect class -//********************************************************************************** - -template -struct RectT { - T x0, y0, x1, y1; - -public: - RectT() : x0((std::numeric_limits::max)()), y0(x0), x1(-x0), y1(x1) {} - RectT(T x0_, T y0_, T x1_, T y1_) : x0(x0_), y0(y0_), x1(x1_), y1(y1_) {} - RectT(const PointT &p0, const PointT &p1) - : x0(p0.x), y0(p0.y), x1(p1.x), y1(p1.y) {} - RectT(const PointT &p0, const SizeT &size) - : x0(p0.x), y0(p0.y), x1(p0.x + size.w), y1(p0.y + size.h) {} - - bool empty() const { return (x1 <= x0) || (y1 <= y0); } - - PointT p0() const { return PointT(x0, y0); } - PointT p1() const { return PointT(x1, y1); } - PointT center() const { return PointT((x0 + x1) / 2, (y0 + y1) / 2); } - - T width() const { return x1 - x0; } - T height() const { return y1 - y0; } - SizeT size() const { return SizeT(width(), height()); } - - bool operator==(const RectT &other) const { - return x0 == other.x0 && y0 == other.y0 && x1 == other.x1 && y1 == other.y1; - } - bool operator!=(const RectT &other) const { return !operator==(other); } - - RectT &operator+=(const PointT &p) { - x0 += p.x, y0 += p.y, x1 += p.x, y1 += p.y; - return *this; - } - RectT &operator-=(const PointT &p) { - x0 -= p.x, y0 -= p.y, x1 -= p.x, y1 -= p.y; - return *this; - } - - friend RectT operator+(const RectT &r, const tcg::PointT &p) { - return RectT(r.x0 + p.x, r.y0 + p.y, r.x1 + p.x, r.y1 + p.y); - } - friend RectT operator-(const RectT &r, const tcg::PointT &p) { - return RectT(r.x0 - p.x, r.y0 - p.y, r.x1 - p.x, r.y1 - p.y); - } - friend RectT operator+(const tcg::PointT &p, const RectT &r) { - return RectT(p.x + r.x0, p.y + r.y0, p.x + r.x1, p.y + r.y1); - } - friend RectT operator-(const tcg::PointT &p, const RectT &r) { - return RectT(p.x - r.x0, p.y - r.y0, p.x - r.x1, p.y - r.y1); - } - - template - RectT &operator*=(K k) { - x0 *= k, y0 *= k, x1 *= k, y1 *= k; - return *this; - } - - template - friend RectT operator*(const RectT &r, K k) { - return RectT(r.x0 * k, r.y0 * k, r.x1 * k, r.y1 * k); - } - template - friend RectT operator*(K k, const RectT &r) { - return RectT(k * r.x0, k * r.y0, k * r.x1, k * r.y1); - } - - RectT &operator|=(const RectT &other) { - if (x0 > other.x0) x0 = other.x0; - if (y0 > other.y0) y0 = other.y0; - if (x1 < other.x1) x1 = other.x1; - if (y1 < other.y1) y1 = other.y1; - return *this; - } - - RectT &operator&=(const RectT &other) { - if (x0 < other.x0) x0 = other.x0; - if (y0 < other.y0) y0 = other.y0; - if (x1 > other.x1) x1 = other.x1; - if (y1 > other.y1) y1 = other.y1; - return *this; - } - - RectT &operator|=(const PointT &p) { - return operator|=(RectT(p.x, p.y, p.x, p.y)); - } - RectT &operator&=(const PointT &p) { - return operator&=(RectT(p.x, p.y, p.x, p.y)); - } - - friend RectT operator|(const RectT &a, const RectT &b) { - return RectT(a) |= b; - } - friend RectT operator&(const RectT &a, const RectT &b) { - return RectT(a) &= b; - } - - friend RectT operator|(const RectT &r, const PointT &p) { - return RectT(r) |= p; - } - friend RectT operator&(const RectT &r, const PointT &p) { - return RectT(r) &= p; - } - friend RectT operator|(const PointT &p, const RectT &r) { - return RectT(r) |= p; - } - friend RectT operator&(const PointT &p, const RectT &r) { - return RectT(r) &= p; - } -}; - -//------------------------------------------------------------------------ - -typedef RectT RectD; -typedef RectT RectI; -typedef RectI Rect; - -//********************************************************************************** -// Tridimensional Rect class -//********************************************************************************** - -template -struct Rect3T { - T x0, y0, z0, x1, y1, z1; - -public: - Rect3T() - : x0((std::numeric_limits::max)()) - , y0(x0) - , z0(x0) - , x1(-x0) - , y1(x1) - , z1(x1) {} - Rect3T(T x0_, T y0_, T z0_, T x1_, T y1_, T z1_) - : x0(x0_), y0(y0_), z0(z0_), x1(x1_), y1(y1_), z1(z1_) {} - Rect3T(const Point3T &p0, const Point3T &p1) - : x0(p0.x), y0(p0.y), z0(p0.z) x1(p1.x), y1(p1.y), z1(p1.z) {} - Rect3T(const Point3T &p0, const Size3T &size) - : x0(p0.x) - , y0(p0.y) - , z0(p0.z) - , x1(p0.x + size.w) - , y1(p0.y + size.h) - , z1(p0.z + size.d) {} - - bool empty() const { return (x1 <= x0) || (y1 <= y0) || (z1 <= z0); } - - Point3T p0() const { return Point3T(x0, y0, z0); } - Point3T p1() const { return Point3T(x1, y1, z1); } - Point3T center() const { - return Point3T((x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2); - } - - T width() const { return x1 - x0; } - T height() const { return y1 - y0; } - T depth() const { return z1 - z0; } - Size3T size() const { return Size3T(width(), height(), depth()); } - - bool operator==(const Rect3T &other) const { - return x0 == other.x0 && y0 == other.y0 && z0 == other.z0 && - x1 == other.x1 && y1 == other.y1 && z1 == other.z1; - } - bool operator!=(const Rect3T &other) const { return !operator==(other); } - - Rect3T &operator+=(const Point3T &p) { - x0 += p.x, y0 += p.y, z0 += p.z, x1 += p.x, y1 += p.y, z1 += p.z; - return *this; - } - Rect3T &operator-=(const Point3T &p) { - x0 -= p.x, y0 -= p.y, z0 -= p.z, x1 -= p.x, y1 -= p.y, z1 -= p.z; - return *this; - } - - friend Rect3T operator+(const Rect3T &r, const tcg::Point3T &p) { - return Rect3T(r.x0 + p.x, r.y0 + p.y, r.z0 + p.z, r.x1 + p.x, r.y1 + p.y, - r.z1 + p.z); - } - friend Rect3T operator-(const Rect3T &r, const tcg::Point3T &p) { - return Rect3T(r.x0 - p.x, r.y0 - p.y, r.z0 - p.z, r.x1 - p.x, r.y1 - p.y, - r.z1 - p.z); - } - friend Rect3T operator+(const tcg::Point3T &p, const Rect3T &r) { - return Rect3T(p.x + r.x0, p.x + r.y0, p.x + r.z0, p.x + r.x1 + p.x, r.y1, - p.x + r.z1); - } - friend Rect3T operator-(const tcg::Point3T &p, const Rect3T &r) { - return Rect3T(p.x - r.x0, p.y - r.y0, p.z - r.z0, p.x - r.x1, p.y - r.y1, - p.z - r.z1); - } - - template - Rect3T &operator*=(K k) { - x0 *= k, y0 *= k, z0 *= k, x1 *= k, y1 *= k, z1 *= k; - return *this; - } - - template - friend Rect3T operator*(const Rect3T &r, K k) { - return RectT(r.x0 * k, r.y0 * k, r.z0 * k, r.x1 * k, r.y1 * k, r.z1 * k); - } - template - friend Rect3T operator*(K k, const Rect3T &r) { - return RectT(k * r.x0, k * r.y0, k * r.z0, k * r.x1, k * r.y1, k * r.z1); - } - - Rect3T &operator|=(const Rect3T &other) { - if (x0 > other.x0) x0 = other.x0; - if (y0 > other.y0) y0 = other.y0; - if (z0 > other.z0) z0 = other.z0; - if (x1 < other.x1) x1 = other.x1; - if (y1 < other.y1) y1 = other.y1; - if (z1 < other.z1) z1 = other.z1; - return *this; - } - - Rect3T &operator&=(const Rect3T &other) { - if (x0 < other.x0) x0 = other.x0; - if (y0 < other.y0) y0 = other.y0; - if (z0 < other.z0) z0 = other.z0; - if (x1 > other.x1) x1 = other.x1; - if (y1 > other.y1) y1 = other.y1; - if (z1 > other.z1) z1 = other.z1; - return *this; - } - - Rect3T &operator|=(const Point3T &p) { - return operator|=(RectT(p.x, p.y, p.z, p.x, p.y, p.z)); - } - Rect3T &operator&=(const Point3T &p) { - return operator&=(RectT(p.x, p.y, p.z, p.x, p.y, p.z)); - } - - friend Rect3T operator|(const Rect3T &a, const Rect3T &b) { - return Rect3T(a) |= b; - } - friend Rect3T operator&(const Rect3T &a, const Rect3T &b) { - return Rect3T(a) &= b; - } - - friend Rect3T operator|(const Rect3T &r, const Point3T &p) { - return Rect3T(r) |= p; - } - friend Rect3T operator&(const Rect3T &r, const Point3T &p) { - return Rect3T(r) &= p; - } - friend Rect3T operator|(const Point3T &p, const Rect3T &r) { - return Rect3T(r) |= p; - } - friend Rect3T operator&(const Point3T &p, const Rect3T &r) { - return Rect3T(r) &= p; - } -}; - -//------------------------------------------------------------------------ - -typedef Rect3T Rect3D; -typedef Rect3T Rect3I; -typedef RectI Rect; - -} // namespace tcg - -#endif // TCG_RECT_H diff --git a/toonz/sources/include/tcg/size.h b/toonz/sources/include/tcg/size.h deleted file mode 100644 index c43d9d7..0000000 --- a/toonz/sources/include/tcg/size.h +++ /dev/null @@ -1,218 +0,0 @@ -#pragma once - -#ifndef TCG_SIZE_H -#define TCG_SIZE_H - -namespace tcg { - -//********************************************************************************** -// Bidimensional size class -//********************************************************************************** - -template -struct SizeT { - typedef T value_type; - -public: - T w, h; - -public: - SizeT() : w(), h() {} - SizeT(T w_, T h_) : w(w_), h(h_) {} - - bool empty() const { return (w <= 0) || (h <= 0); } - - SizeT &operator+=(const SizeT &other) { - w += other.w, h += other.h; - return *this; - } - SizeT &operator-=(const SizeT &other) { - w -= other.w, h -= other.h; - return *this; - } - - friend SizeT operator+(const SizeT &a, const SizeT &b) { - return SizeT(a.w + b.w, a.h + b.h); - } - - friend SizeT operator-(const SizeT &a, const SizeT &b) { - return SizeT(a.w - b.w, a.h - b.h); - } - - template - SizeT &operator*=(K k) { - w *= k, h *= k; - return *this; - } - - template - SizeT &operator/=(K k) { - w /= k, h /= k; - return *this; - } - - template - friend SizeT operator*(K k, const SizeT &a) { - return SizeT(k * a.w, k * a.h); - } - - template - friend SizeT operator*(const SizeT &a, K k) { - return SizeT(a.w * k, a.h * k); - } - - template - friend SizeT operator/(const SizeT &a, K k) { - return SizeT(a.w / k, a.h / k); - } - - SizeT &operator&=(const SizeT &other) { - if (other.w < w) w = other.w; - if (other.h < h) h = other.h; - - return *this; - } - - SizeT &operator|=(const SizeT &other) { - if (other.w > w) w = other.w; - if (other.h > h) h = other.h; - - return *this; - } - - friend SizeT operator&(const SizeT &a, const SizeT &b) { - SizeT tmp(a); - return tmp &= b; - } - friend SizeT operator|(const SizeT &a, const SizeT &b) { - SizeT tmp(a); - return tmp |= b; - } -}; - -//------------------------------------------------------------------------ - -typedef SizeT SizeI; -typedef SizeI Size; -typedef SizeT SizeD; - -//********************************************************************************** -// Tridimensional size class -//********************************************************************************** - -template -struct Size3T { - typedef T value_type; - -public: - T w, h, d; - -public: - Size3T() : w(), h(), d() {} - Size3T(T w_, T h_, T d_) : w(w_), h(h_), d(d_) {} - - bool empty() const { return (w <= 0) || (h <= 0) || (d <= 0); } - - Size3T &operator+=(const Size3T &other) { - w += other.w, h += other.h, d += other.d; - return *this; - } - Size3T &operator-=(const Size3T &other) { - w -= other.w, h -= other.h, d -= other.d; - return *this; - } - - friend Size3T operator+(const Size3T &a, const Size3T &b) { - return SizeT(a.w + b.w, a.h + b.h, a.d + b.d); - } - - friend Size3T operator-(const Size3T &a, const Size3T &b) { - return SizeT(a.w - b.w, a.h - b.h, a.d + b.d); - } - - template - Size3T &operator*=(K k) { - w *= k, h *= k, d *= k; - return *this; - } - - template - Size3T &operator/=(K k) { - w /= k, h /= k, d /= k; - return *this; - } - - template - friend Size3T operator*(K k, const Size3T &a) { - return Size3T(k * a.w, k * a.h, k * a.d); - } - - template - friend Size3T operator*(const Size3T &a, K k) { - return Size3T(a.w * k, a.h * k, a.d * k); - } - - template - friend Size3T operator/(const Size3T &a, K k) { - return Size3T(a.w / k, a.h / k, a.d / k); - } - - Size3T &operator&=(const Size3T &other) { - if (other.w < w) w = other.w; - if (other.h < h) h = other.h; - if (other.d < d) d = other.d; - - return *this; - } - - Size3T &operator|=(const Size3T &other) { - if (other.w > w) w = other.w; - if (other.h > h) h = other.h; - if (other.d > d) d = other.d; - - return *this; - } - - friend Size3T operator&(const Size3T &a, const Size3T &b) { - Size3T tmp(a); - return tmp &= b; - } - friend Size3T operator|(const Size3T &a, const Size3T &b) { - Size3T tmp(a); - return tmp |= b; - } -}; - -//------------------------------------------------------------------------ - -typedef Size3T Size3I; -typedef Size3I Size3; -typedef Size3T Size3D; - -//********************************************************************************** -// N-dimensional size class -//********************************************************************************** - -template -struct SizeN { - static const int size = N; - typedef T value_type; - -public: - T span[N]; - -public: - SizeN() {} - SizeN(const T &t) { std::fill(span, span + N, t); } - - template - SizeN(It begin, It end) { - std::copy(begin, end, span); - } - - // To be completed... -}; - -} // namespace tcg - -#endif // TCG_SIZE_H diff --git a/toonz/sources/include/tcg/tcg_auto.h b/toonz/sources/include/tcg/tcg_auto.h deleted file mode 100644 index a2bec77..0000000 --- a/toonz/sources/include/tcg/tcg_auto.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "auto.h" diff --git a/toonz/sources/include/tcg/tcg_image_iterator.h b/toonz/sources/include/tcg/tcg_image_iterator.h deleted file mode 100644 index 3b93c06..0000000 --- a/toonz/sources/include/tcg/tcg_image_iterator.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "image_iterator.h"