diff --git a/plugins/blur/CMakeLists.txt b/plugins/blur/CMakeLists.txt index e87ed2e..2eadecc 100644 --- a/plugins/blur/CMakeLists.txt +++ b/plugins/blur/CMakeLists.txt @@ -1,8 +1,10 @@ -project(blur_plugin) +project(blur_plugin C CXX) +set(PLUGINSDK_ROOT ../../toonz/sources/toonzqt) +set(PLUGINSDK_UTILS_PATH ../) set(HEADERS - ../../toonz/sources/toonzqt/toonz_plugin.h - ../../toonz/sources/toonzqt/toonz_hostif.h) + ${PLUGINSDK_ROOT}/toonz_plugin.h + ${PLUGINSDK_ROOT}/toonz_hostif.h) set(SOURCES blur.cpp) @@ -17,4 +19,4 @@ set_target_properties(blur PROPERTIES PREFIX "" SUFFIX ".plugin") -include_directories(../../toonz/sources/toonzqt ../) +include_directories(${PLUGINSDK_ROOT} ${PLUGINSDK_UTILS_PATH}) diff --git a/plugins/blur/blur.cpp b/plugins/blur/blur.cpp index 6c04230..cad9027 100644 --- a/plugins/blur/blur.cpp +++ b/plugins/blur/blur.cpp @@ -5,8 +5,8 @@ #include #include #include "pixelop.hpp" -#include "toonz_plugin_helper_rect.h" +#include #include #include diff --git a/plugins/geom/CMakeLists.txt b/plugins/geom/CMakeLists.txt index b907954..85e29e3 100644 --- a/plugins/geom/CMakeLists.txt +++ b/plugins/geom/CMakeLists.txt @@ -1,8 +1,11 @@ project(geom_plugin) +set(PLUGINSDK_ROOT ../../toonz/sources/toonzqt) +set(PLUGINSDK_UTILS_PATH ../) + set(HEADERS - ../../toonz/sources/toonzqt/toonz_plugin.h - ../../toonz/sources/toonzqt/toonz_hostif.h) + ${PLUGINSDK_ROOT}/toonz_plugin.h + ${PLUGINSDK_ROOT}/toonz_hostif.h) set(SOURCES geom.cpp) @@ -17,4 +20,4 @@ set_target_properties(geom PROPERTIES PREFIX "" SUFFIX ".plugin") -include_directories(../../toonz/sources/toonzqt ../) +include_directories(${PLUGINSDK_ROOT} ${PLUGINSDK_UTILS_PATH}) diff --git a/plugins/geom/geom.cpp b/plugins/geom/geom.cpp index 2f41009..303ba67 100644 --- a/plugins/geom/geom.cpp +++ b/plugins/geom/geom.cpp @@ -5,9 +5,8 @@ #include #include #include -#include "toonz_plugin_helper_rect.h" -#include "toonz_plugin_helper_affine.h" - +#include +#include #include #include diff --git a/plugins/multiplugin/CMakeLists.txt b/plugins/multiplugin/CMakeLists.txt index 2de78bf..bbd9ef6 100644 --- a/plugins/multiplugin/CMakeLists.txt +++ b/plugins/multiplugin/CMakeLists.txt @@ -1,8 +1,10 @@ project(multi_plugin) +set(PLUGINSDK_ROOT ../../toonz/sources/toonzqt) +set(PLUGINSDK_UTILS_PATH ../) set(HEADERS - ../../toonz/sources/toonzqt/toonz_plugin.h - ../../toonz/sources/toonzqt/toonz_hostif.h) + ${PLUGINSDK_ROOT}/toonz_plugin.h + ${PLUGINSDK_ROOT}/toonz_hostif.h) set(SOURCES multi.cpp) @@ -17,4 +19,4 @@ set_target_properties(multi PROPERTIES PREFIX "" SUFFIX ".plugin") -include_directories(../../toonz/sources/toonzqt ../) +include_directories(${PLUGINSDK_ROOT} ${PLUGINSDK_UTILS_PATH}) diff --git a/plugins/multiplugin/multi.cpp b/plugins/multiplugin/multi.cpp index c369a15..32a67eb 100644 --- a/plugins/multiplugin/multi.cpp +++ b/plugins/multiplugin/multi.cpp @@ -4,8 +4,8 @@ #include #include #include -#include "toonz_plugin_helper_rect.h" -#include "toonz_plugin_helper_affine.h" +#include +#include #include #include diff --git a/plugins/utils/affine.hpp b/plugins/utils/affine.hpp new file mode 100644 index 0000000..ef7a710 --- /dev/null +++ b/plugins/utils/affine.hpp @@ -0,0 +1,169 @@ +#ifndef TOONZ_PLUGIN_HELPER_UTILS_AFFINE_HPP__ +#define TOONZ_PLUGIN_HELPER_UTILS_AFFINE_HPP__ + +#include +#include +#include +#include +#include "rect.hpp" + +class ToonzAffine +{ +public: + double a11, a12, a13; + double a21, a22, a23; + + ToonzAffine() : a11(1), a12(0), a13(0), a21(0), a22(1), a23(0) {} + ToonzAffine(double a11, double a12, double a13, + double a21, double a22, double a23) + : a11(a11), a12(a12), a13(a13), a21(a21), a22(a22), a23(a23) {} + ToonzAffine(const toonz_affine_t &affine) : a11(affine.a11), a12(affine.a12), a13(affine.a13), a21(affine.a21), a22(affine.a22), a23(affine.a23) {} + ToonzAffine(const ToonzAffine &toonzAffine) + : a11(toonzAffine.a11), a12(toonzAffine.a12), a13(toonzAffine.a13), + a21(toonzAffine.a21), a22(toonzAffine.a22), a23(toonzAffine.a23) {} + + static bool equals(double a, double b, double err = 1e-9) + { + return std::abs(a - b) < err; + } + + ToonzAffine operator*(const ToonzAffine &toonzAffine) const; + ToonzAffine &operator=(const ToonzAffine &toonzAffine); + ToonzAffine &operator*=(const ToonzAffine &toonzAffine); + bool operator==(const ToonzAffine &toonzAffine) const; + bool operator!=(const ToonzAffine &toonzAffine) const; + + ToonzPoint operator*(const ToonzPoint &p) const; + ToonzRect operator*(const ToonzRect &p) const; + ToonzAffine inv() const; + double det() const; + bool isIdentity(double err = 1e-9) const; + bool isTranslation(double err = 1e-9) const; + bool isIsotropic(double err = 1e-9) const; + ToonzAffine place(double u, double v, double x, double y) const; +}; + +inline ToonzPoint ToonzAffine::operator*(const ToonzPoint &pt) const +{ + return ToonzPoint(pt.x * a11 + pt.y * a12 + a13, pt.x * a21 + pt.y * a22 + a23); +} + +inline ToonzRect ToonzAffine::operator*(const ToonzRect &r) const +{ + if (r.x0 == -std::numeric_limits::max() || + r.y0 == -std::numeric_limits::max() || + r.x1 == std::numeric_limits::max() || + r.y1 == std::numeric_limits::max()) + return ToonzRect(-std::numeric_limits::max(), -std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()); + ToonzPoint p0 = this->operator*(ToonzPoint(r.x0, r.y0)); + ToonzPoint p1 = this->operator*(ToonzPoint(r.x1, r.y0)); + ToonzPoint p2 = this->operator*(ToonzPoint(r.x0, r.y1)); + ToonzPoint p3 = this->operator*(ToonzPoint(r.x1, r.y1)); + return ToonzRect(std::min(std::min(p0.x, p1.x), std::min(p2.x, p3.x)), std::min(std::min(p0.y, p1.y), std::min(p2.y, p3.y)), + std::max(std::max(p0.x, p1.x), std::max(p2.x, p3.x)), std::max(std::max(p0.y, p1.y), std::max(p2.y, p3.y))); +} + +ToonzAffine ToonzAffine::operator*(const ToonzAffine &toonzAffine) const +{ + return ToonzAffine( + a11 * toonzAffine.a11 + a12 * toonzAffine.a21, + a11 * toonzAffine.a12 + a12 * toonzAffine.a22, + a11 * toonzAffine.a13 + a12 * toonzAffine.a23 + a13, + a21 * toonzAffine.a11 + a22 * toonzAffine.a21, + a21 * toonzAffine.a12 + a22 * toonzAffine.a22, + a21 * toonzAffine.a13 + a22 * toonzAffine.a23 + a23); +} + +ToonzAffine &ToonzAffine::operator=(const ToonzAffine &toonzAffine) +{ + a11 = toonzAffine.a11; + a12 = toonzAffine.a12; + a13 = toonzAffine.a13; + a21 = toonzAffine.a21; + a22 = toonzAffine.a22; + a23 = toonzAffine.a23; + return *this; +} + +ToonzAffine &ToonzAffine::operator*=(const ToonzAffine &toonzAffine) +{ + return *this = *this * toonzAffine; +} + +bool ToonzAffine::operator==(const ToonzAffine &toonzAffine) const +{ + return equals(a11, toonzAffine.a11) && equals(a12, toonzAffine.a12) && + equals(a13, toonzAffine.a13) && equals(a21, toonzAffine.a21) && + equals(a22, toonzAffine.a22) && equals(a23, toonzAffine.a23); +} + +bool ToonzAffine::operator!=(const ToonzAffine &toonzAffine) const +{ + return !(*this == toonzAffine); +} + +ToonzAffine ToonzAffine::inv() const +{ + if (equals(a12, 0.0) && equals(a21, 0.0)) { + assert(!equals(a11, 0.0, DBL_EPSILON)); + assert(!equals(a22, 0.0, DBL_EPSILON)); + double inv_a11 = 1.0 / a11; + double inv_a22 = 1.0 / a22; + return ToonzAffine( + inv_a11, 0.0, -a13 * inv_a11, + 0.0, inv_a22, -a23 * inv_a22); + } else if (equals(a11, 0.0) && equals(a22, 0.0)) { + assert(!equals(a12, 0.0, DBL_EPSILON)); + assert(!equals(a21, 0.0, DBL_EPSILON)); + double inv_a21 = 1.0 / a21; + double inv_a12 = 1.0 / a12; + return ToonzAffine( + 0.0, inv_a21, -a23 * inv_a21, + inv_a12, 0.0, -a13 * inv_a12); + } + double inv_det = 1.0 / det(); + return ToonzAffine( + a22 * inv_det, -a12 * inv_det, (a12 * a23 - a22 * a13) * inv_det, + -a21 * inv_det, a11 * inv_det, (a21 * a13 - a11 * a23) * inv_det); +} + +double ToonzAffine::det() const +{ + return a11 * a22 - a12 * a21; +} + +bool ToonzAffine::isIdentity(double err) const +{ + double value = + (a11 - 1.0) * (a11 - 1.0) + + (a22 - 1.0) * (a22 - 1.0) + + a12 * a12 + a13 * a13 + + a21 * a21 + a23 * a23; + return value < err; +} + +bool ToonzAffine::isTranslation(double err) const +{ + double value = + (a11 - 1.0) * (a11 - 1.0) + + (a22 - 1.0) * (a22 - 1.0) + + a12 * a12 + a21 * a21; + return value < err; +} + +bool ToonzAffine::isIsotropic(double err) const +{ + if (equals(a11, a22, err) && equals(a12, -a21, err)) { + return true; + } + return false; +} + +ToonzAffine ToonzAffine::place(double u, double v, double x, double y) const +{ + return ToonzAffine( + a11, a12, x - (a11 * u + a12 * v), + a21, a22, y - (a21 * u + a22 * v)); +} + +#endif diff --git a/plugins/utils/rect.hpp b/plugins/utils/rect.hpp new file mode 100644 index 0000000..1b51791 --- /dev/null +++ b/plugins/utils/rect.hpp @@ -0,0 +1,120 @@ +#ifndef TOONZ_PLUGIN_HELPER_UTILS_RECT_HPP__ +#define TOONZ_PLUGIN_HELPER_UTILS_RECT_HPP__ + +#include +#include +#include + +class ToonzRect +{ +public: + double x0, y0; + double x1, y1; + + ToonzRect() + : x0(0), y0(0), x1(0), y1(0) {} + ToonzRect(double x0, double y0, double x1, double y1) + : x0(x0), y0(y0), x1(x1), y1(y1) {} + ToonzRect(const ToonzRect &toonzRect) + : x0(toonzRect.x0), y0(toonzRect.y0), x1(toonzRect.x1), y1(toonzRect.y1) {} + + bool equals(double a, double b, double err = DBL_EPSILON) const + { + return fabs(a - b) < err; + } + + ToonzRect operator+(const ToonzRect &toonzRect) const; + ToonzRect operator*(const ToonzRect &toonzRect) const; + ToonzRect &operator+=(const ToonzRect &toonzRect); + ToonzRect &operator*=(const ToonzRect &toonzRect); + bool operator==(const ToonzRect &toonzRect) const; + + bool isEmpty() const; + bool isContained(const ToonzRect &toonzRect) const; + bool isOverlapped(const ToonzRect &toonzRect) const; + ToonzRect enlarge(double x, double y) const; +}; + +ToonzRect ToonzRect::operator+(const ToonzRect &toonzRect) const +{ + if (isEmpty()) { + return toonzRect; + } else if (toonzRect.isEmpty()) { + return *this; + } + return ToonzRect(std::min(x0, toonzRect.x0), std::min(y0, toonzRect.y0), + std::max(x1, toonzRect.x1), std::max(y1, toonzRect.y1)); +} + +ToonzRect ToonzRect::operator*(const ToonzRect &toonzRect) const +{ + if (isEmpty() || + toonzRect.isEmpty() || + toonzRect.x1 < x0 || + x1 < toonzRect.x0 || + toonzRect.y1 < y0 || + y1 < toonzRect.y0) { + return ToonzRect(); + } + + return ToonzRect(std::max(x0, toonzRect.x0), std::max(y0, toonzRect.y0), + std::min(x1, toonzRect.x1), std::min(y1, toonzRect.y1)); +} + +ToonzRect &ToonzRect::operator+=(const ToonzRect &toonzRect) +{ + return *this = *this + toonzRect; +} + +ToonzRect &ToonzRect::operator*=(const ToonzRect &toonzRect) +{ + return *this = *this * toonzRect; +} + +bool ToonzRect::operator==(const ToonzRect &toonzRect) const +{ + return equals(x0, toonzRect.x0) && + equals(y0, toonzRect.y0) && + equals(x1, toonzRect.x1) && + equals(y1, toonzRect.y1); +} + +bool ToonzRect::isEmpty() const +{ + if ((equals(x0, x1) && equals(y0, y1)) || + x0 > x1 || + y0 > y1) { + return true; + } + return false; +} + +bool ToonzRect::isContained(const ToonzRect &toonzRect) const +{ + return toonzRect.x0 <= x0 && x1 <= toonzRect.x1 && + toonzRect.y0 <= y0 && y1 <= toonzRect.y1; +} + +bool ToonzRect::isOverlapped(const ToonzRect &toonzRect) const +{ + return x0 <= toonzRect.x1 && x1 >= toonzRect.x0 && + y0 <= toonzRect.y1 && y1 >= toonzRect.y0; +} + +ToonzRect ToonzRect::enlarge(double x, double y) const +{ + if (isEmpty()) { + return *this; + } + return ToonzRect(x0 - x, y0 - y, x1 + x, y1 + y); +} + +class ToonzPoint +{ +public: + double x, y; + ToonzPoint() : x(0), y(0) {} + ToonzPoint(double x, double y) : x(x), y(y) {} +}; + +#endif diff --git a/toonz/install/package_sdk.sh b/toonz/install/package_sdk.sh new file mode 100755 index 0000000..98789b9 --- /dev/null +++ b/toonz/install/package_sdk.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +while getopts t:d:h OPT +do + case $OPT in + t) TOONZREPO=$OPTARG + ;; + d) DIST=$OPTARG + ;; + h) echo "-t opentoonz_repository_dir -d dist_dir" + exit 1; + ;; + \?) exit 1 + ;; + esac +done + +mkdir -p $DIST +pushd $DIST + +mkdir core +mkdir utils +mkdir doc + +cp $TOONZREPO/LICENSE.txt ./ +cp $TOONZREPO/toonz/sources/toonzqt/toonz_plugin.h core/ +cp $TOONZREPO/toonz/sources/toonzqt/toonz_hostif.h core/ +cp $TOONZREPO/toonz/sources/toonzqt/toonz_params.h core/ + +cp $TOONZREPO/plugins/utils/affine.hpp utils/ +cp $TOONZREPO/plugins/utils/rect.hpp utils/ +cp $TOONZREPO/plugins/utils/interf_holder.hpp utils/ +cp $TOONZREPO/plugins/utils/param_traits.hpp utils/ + +# copy samples + +mkdir -p samples/blur +mkdir -p samples/geom +mkdir -p samples/multiplugin + +cp $TOONZREPO/plugins/blur/* samples/blur/ +cp $TOONZREPO/plugins/geom/* samples/geom/ +cp $TOONZREPO/plugins/multiplugin/* samples/multiplugin/ + +find ./samples -iname CMakeLists.txt -exec sed -e 's/set(PLUGINSDK_ROOT.*)/set(PLUGINSDK_ROOT \.\.\/\.\.\/core)/' -i "" {} \; +find ./samples -iname CMakeLists.txt -exec sed -e 's/set(PLUGINSDK_UTILS_PATH.*)/set(PLUGINSDK_UTILS_PATH \.\.\/\.\.\/)/' -i "" {} \; + +popd diff --git a/toonz/sources/toonzqt/toonz_plugin_helper_affine.h b/toonz/sources/toonzqt/toonz_plugin_helper_affine.h deleted file mode 100644 index 1d2571b..0000000 --- a/toonz/sources/toonzqt/toonz_plugin_helper_affine.h +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef TOONZ_PLUGIN_HELPER_AFFINE_H__ -#define TOONZ_PLUGIN_HELPER_AFFINE_H__ - -#include -#include -#include -#include "toonz_plugin_helper_rect.h" -#include "toonz_hostif.h" -class ToonzAffine -{ -public: - double a11, a12, a13; - double a21, a22, a23; - - ToonzAffine() : a11(1), a12(0), a13(0), a21(0), a22(1), a23(0) {} - ToonzAffine(double a11, double a12, double a13, - double a21, double a22, double a23) - : a11(a11), a12(a12), a13(a13), a21(a21), a22(a22), a23(a23) {} - ToonzAffine(const toonz_affine_t &affine) : a11(affine.a11), a12(affine.a12), a13(affine.a13), a21(affine.a21), a22(affine.a22), a23(affine.a23) {} - ToonzAffine(const ToonzAffine &toonzAffine) - : a11(toonzAffine.a11), a12(toonzAffine.a12), a13(toonzAffine.a13), - a21(toonzAffine.a21), a22(toonzAffine.a22), a23(toonzAffine.a23) {} - - static bool equals(double a, double b, double err = 1e-9) - { - return std::abs(a - b) < err; - } - - ToonzAffine operator*(const ToonzAffine &toonzAffine) const; - ToonzAffine &operator=(const ToonzAffine &toonzAffine); - ToonzAffine &operator*=(const ToonzAffine &toonzAffine); - bool operator==(const ToonzAffine &toonzAffine) const; - bool operator!=(const ToonzAffine &toonzAffine) const; - - ToonzPoint operator*(const ToonzPoint &p) const; - ToonzRect operator*(const ToonzRect &p) const; - ToonzAffine inv() const; - double det() const; - bool isIdentity(double err = 1e-9) const; - bool isTranslation(double err = 1e-9) const; - bool isIsotropic(double err = 1e-9) const; - ToonzAffine place(double u, double v, double x, double y) const; -}; - -inline ToonzPoint ToonzAffine::operator*(const ToonzPoint &pt) const -{ - return ToonzPoint(pt.x * a11 + pt.y * a12 + a13, pt.x * a21 + pt.y * a22 + a23); -} - -inline ToonzRect ToonzAffine::operator*(const ToonzRect &r) const -{ - if (r.x0 == -std::numeric_limits::max() || - r.y0 == -std::numeric_limits::max() || - r.x1 == std::numeric_limits::max() || - r.y1 == std::numeric_limits::max()) - return ToonzRect(-std::numeric_limits::max(), -std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()); - ToonzPoint p0 = this->operator*(ToonzPoint(r.x0, r.y0)); - ToonzPoint p1 = this->operator*(ToonzPoint(r.x1, r.y0)); - ToonzPoint p2 = this->operator*(ToonzPoint(r.x0, r.y1)); - ToonzPoint p3 = this->operator*(ToonzPoint(r.x1, r.y1)); - return ToonzRect(std::min(std::min(p0.x, p1.x), std::min(p2.x, p3.x)), std::min(std::min(p0.y, p1.y), std::min(p2.y, p3.y)), - std::max(std::max(p0.x, p1.x), std::max(p2.x, p3.x)), std::max(std::max(p0.y, p1.y), std::max(p2.y, p3.y))); -} - -ToonzAffine ToonzAffine::operator*(const ToonzAffine &toonzAffine) const -{ - return ToonzAffine( - a11 * toonzAffine.a11 + a12 * toonzAffine.a21, - a11 * toonzAffine.a12 + a12 * toonzAffine.a22, - a11 * toonzAffine.a13 + a12 * toonzAffine.a23 + a13, - a21 * toonzAffine.a11 + a22 * toonzAffine.a21, - a21 * toonzAffine.a12 + a22 * toonzAffine.a22, - a21 * toonzAffine.a13 + a22 * toonzAffine.a23 + a23); -} - -ToonzAffine &ToonzAffine::operator=(const ToonzAffine &toonzAffine) -{ - a11 = toonzAffine.a11; - a12 = toonzAffine.a12; - a13 = toonzAffine.a13; - a21 = toonzAffine.a21; - a22 = toonzAffine.a22; - a23 = toonzAffine.a23; - return *this; -} - -ToonzAffine &ToonzAffine::operator*=(const ToonzAffine &toonzAffine) -{ - return *this = *this * toonzAffine; -} - -bool ToonzAffine::operator==(const ToonzAffine &toonzAffine) const -{ - return equals(a11, toonzAffine.a11) && equals(a12, toonzAffine.a12) && - equals(a13, toonzAffine.a13) && equals(a21, toonzAffine.a21) && - equals(a22, toonzAffine.a22) && equals(a23, toonzAffine.a23); -} - -bool ToonzAffine::operator!=(const ToonzAffine &toonzAffine) const -{ - return !(*this == toonzAffine); -} - -ToonzAffine ToonzAffine::inv() const -{ - if (equals(a12, 0.0) && equals(a21, 0.0)) { - assert(!equals(a11, 0.0, DBL_EPSILON)); - assert(!equals(a22, 0.0, DBL_EPSILON)); - double inv_a11 = 1.0 / a11; - double inv_a22 = 1.0 / a22; - return ToonzAffine( - inv_a11, 0.0, -a13 * inv_a11, - 0.0, inv_a22, -a23 * inv_a22); - } else if (equals(a11, 0.0) && equals(a22, 0.0)) { - assert(!equals(a12, 0.0, DBL_EPSILON)); - assert(!equals(a21, 0.0, DBL_EPSILON)); - double inv_a21 = 1.0 / a21; - double inv_a12 = 1.0 / a12; - return ToonzAffine( - 0.0, inv_a21, -a23 * inv_a21, - inv_a12, 0.0, -a13 * inv_a12); - } - double inv_det = 1.0 / det(); - return ToonzAffine( - a22 * inv_det, -a12 * inv_det, (a12 * a23 - a22 * a13) * inv_det, - -a21 * inv_det, a11 * inv_det, (a21 * a13 - a11 * a23) * inv_det); -} - -double ToonzAffine::det() const -{ - return a11 * a22 - a12 * a21; -} - -bool ToonzAffine::isIdentity(double err) const -{ - double value = - (a11 - 1.0) * (a11 - 1.0) + - (a22 - 1.0) * (a22 - 1.0) + - a12 * a12 + a13 * a13 + - a21 * a21 + a23 * a23; - return value < err; -} - -bool ToonzAffine::isTranslation(double err) const -{ - double value = - (a11 - 1.0) * (a11 - 1.0) + - (a22 - 1.0) * (a22 - 1.0) + - a12 * a12 + a21 * a21; - return value < err; -} - -bool ToonzAffine::isIsotropic(double err) const -{ - if (equals(a11, a22, err) && equals(a12, -a21, err)) { - return true; - } - return false; -} - -ToonzAffine ToonzAffine::place(double u, double v, double x, double y) const -{ - return ToonzAffine( - a11, a12, x - (a11 * u + a12 * v), - a21, a22, y - (a21 * u + a22 * v)); -} - -#endif diff --git a/toonz/sources/toonzqt/toonz_plugin_helper_rect.h b/toonz/sources/toonzqt/toonz_plugin_helper_rect.h deleted file mode 100644 index dedb0e2..0000000 --- a/toonz/sources/toonzqt/toonz_plugin_helper_rect.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef TOONZ_PLUGIN_HELPER_RECT_H__ -#define TOONZ_PLUGIN_HELPER_RECT_H__ - -#include -#include -#include - -class ToonzRect -{ -public: - double x0, y0; - double x1, y1; - - ToonzRect() - : x0(0), y0(0), x1(0), y1(0) {} - ToonzRect(double x0, double y0, double x1, double y1) - : x0(x0), y0(y0), x1(x1), y1(y1) {} - ToonzRect(const ToonzRect &toonzRect) - : x0(toonzRect.x0), y0(toonzRect.y0), x1(toonzRect.x1), y1(toonzRect.y1) {} - - bool equals(double a, double b, double err = DBL_EPSILON) const - { - return fabs(a - b) < err; - } - - ToonzRect operator+(const ToonzRect &toonzRect) const; - ToonzRect operator*(const ToonzRect &toonzRect) const; - ToonzRect &operator+=(const ToonzRect &toonzRect); - ToonzRect &operator*=(const ToonzRect &toonzRect); - bool operator==(const ToonzRect &toonzRect) const; - - bool isEmpty() const; - bool isContained(const ToonzRect &toonzRect) const; - bool isOverlapped(const ToonzRect &toonzRect) const; - ToonzRect enlarge(double x, double y) const; -}; - -ToonzRect ToonzRect::operator+(const ToonzRect &toonzRect) const -{ - if (isEmpty()) { - return toonzRect; - } else if (toonzRect.isEmpty()) { - return *this; - } - return ToonzRect(std::min(x0, toonzRect.x0), std::min(y0, toonzRect.y0), - std::max(x1, toonzRect.x1), std::max(y1, toonzRect.y1)); -} - -ToonzRect ToonzRect::operator*(const ToonzRect &toonzRect) const -{ - if (isEmpty() || - toonzRect.isEmpty() || - toonzRect.x1 < x0 || - x1 < toonzRect.x0 || - toonzRect.y1 < y0 || - y1 < toonzRect.y0) { - return ToonzRect(); - } - - return ToonzRect(std::max(x0, toonzRect.x0), std::max(y0, toonzRect.y0), - std::min(x1, toonzRect.x1), std::min(y1, toonzRect.y1)); -} - -ToonzRect &ToonzRect::operator+=(const ToonzRect &toonzRect) -{ - return *this = *this + toonzRect; -} - -ToonzRect &ToonzRect::operator*=(const ToonzRect &toonzRect) -{ - return *this = *this * toonzRect; -} - -bool ToonzRect::operator==(const ToonzRect &toonzRect) const -{ - return equals(x0, toonzRect.x0) && - equals(y0, toonzRect.y0) && - equals(x1, toonzRect.x1) && - equals(y1, toonzRect.y1); -} - -bool ToonzRect::isEmpty() const -{ - if ((equals(x0, x1) && equals(y0, y1)) || - x0 > x1 || - y0 > y1) { - return true; - } - return false; -} - -bool ToonzRect::isContained(const ToonzRect &toonzRect) const -{ - return toonzRect.x0 <= x0 && x1 <= toonzRect.x1 && - toonzRect.y0 <= y0 && y1 <= toonzRect.y1; -} - -bool ToonzRect::isOverlapped(const ToonzRect &toonzRect) const -{ - return x0 <= toonzRect.x1 && x1 >= toonzRect.x0 && - y0 <= toonzRect.y1 && y1 >= toonzRect.y0; -} - -ToonzRect ToonzRect::enlarge(double x, double y) const -{ - if (isEmpty()) { - return *this; - } - return ToonzRect(x0 - x, y0 - y, x1 + x, y1 + y); -} - -class ToonzPoint -{ -public: - double x, y; - ToonzPoint() : x(0), y(0) {} - ToonzPoint(double x, double y) : x(x), y(y) {} -}; - -#endif