Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef T_GEOMETRY_INCLUDED
Toshihiro Shimizu 890ddd
#define T_GEOMETRY_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tutil.h"
Shinya Kitaoka 3bfa54
#include <cmath></cmath>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TGEOMETRY_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
911124
911124
inline double logNormalDistribuitionUnscaled(double x, double x0, double w)
911124
  { return exp(-0.5*pow(log(x/x0)/w, 2.0))/x; }
911124
911124
inline double logNormalDistribuition(double x, double x0, double w)
911124
  { return logNormalDistribuitionUnscaled(x, x0, w)/(w*sqrt(2.0*M_PI)); }
911124
911124
//=============================================================================
f9b4ad
f9b4ad
template <class t=""> class TPoint4T;</class>
f9b4ad
Shinya Kitaoka 120a6e
/*
Shinya Kitaoka 120a6e
* This is an example of how to use the TPointT, the TRectT and the TAffine
Shinya Kitaoka 120a6e
* classes.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
/*!  The template class TPointT defines the x- and y-coordinates of a point.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class TPointT {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  T x, y;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointT() : x(0), y(0){};
Shinya Kitaoka 120a6e
  TPointT(T _x, T _y) : x(_x), y(_y){};
Shinya Kitaoka 120a6e
  TPointT(const TPointT &point) : x(point.x), y(point.y){};
f9b4ad
  explicit TPointT(const TPoint4T<t> &point);</t>
f9b4ad
Shinya Kitaoka 120a6e
  inline TPointT &operator=(const TPointT &a) {
Shinya Kitaoka 120a6e
    x = a.x;
Shinya Kitaoka 120a6e
    y = a.y;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline TPointT &operator+=(const TPointT &a) {
Shinya Kitaoka 120a6e
    x += a.x;
Shinya Kitaoka 120a6e
    y += a.y;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  inline TPointT &operator-=(const TPointT &a) {
Shinya Kitaoka 120a6e
    x -= a.x;
Shinya Kitaoka 120a6e
    y -= a.y;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  inline TPointT operator+(const TPointT &a) const {
Shinya Kitaoka 120a6e
    return TPointT(x + a.x, y + a.y);
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  inline TPointT operator-(const TPointT &a) const {
Shinya Kitaoka 120a6e
    return TPointT(x - a.x, y - a.y);
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  inline TPointT operator-() const { return TPointT(-x, -y); };
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
f9b4ad
template <class t=""></class>
f9b4ad
class TPoint4T {
f9b4ad
public:
f9b4ad
  union {
f9b4ad
    struct { T x, y, z, w; };
f9b4ad
    T a[4];
f9b4ad
  };
f9b4ad
f9b4ad
  TPoint4T():
f9b4ad
    x(), y(), z(), w() { };
f9b4ad
  TPoint4T(T x, T y, T z, T w):
f9b4ad
    x(x), y(y), z(z), w(w) { };
f9b4ad
  explicit TPoint4T(const TPointT<t> &p, T w = (T)1):</t>
f9b4ad
      x(p.x), y(p.y), z(), w(w) { };
f9b4ad
};
f9b4ad
f9b4ad
template <class t=""></class>
f9b4ad
inline TPointT<t>::TPointT(const TPoint4T<t> &point) : x(point.x), y(point.y){};</t></t>
f9b4ad
Shinya Kitaoka 120a6e
/*! \relates TPointT
Toshihiro Shimizu 890ddd
* Rotate a point 90 degrees (counterclockwise).
Shinya Kitaoka 120a6e
\param p a point.
Toshihiro Shimizu 890ddd
\return the rotated point
Toshihiro Shimizu 890ddd
\sa rotate270
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <class t=""></class>
Jeremy Bullock 66c844
inline TPointT<t> rotate90(const TPointT<t> &p)  // 90 counterclockwise</t></t>
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  return TPointT<t>(-p.y, p.x);</t>
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
/*! \relates TPointT
Toshihiro Shimizu 890ddd
* Rotate a point 270 degrees (clockwise).
Shinya Kitaoka 120a6e
\param p a point.
Toshihiro Shimizu 890ddd
\return the rotated point
Toshihiro Shimizu 890ddd
\sa rotate90
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <class t=""></class>
Jeremy Bullock 66c844
inline TPointT<t> rotate270(const TPointT<t> &p)  // 90 clockwise</t></t>
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  return TPointT<t>(p.y, -p.x);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Toshihiro Shimizu 890ddd
*/
Jeremy Bullock 66c844
template <class t="">  // Scalar(dot) Product</class>
Shinya Kitaoka 120a6e
inline T operator*(const TPointT<t> &a, const TPointT<t> &b) {</t></t>
Shinya Kitaoka 120a6e
  return a.x * b.x + a.y * b.y;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline std::ostream &operator<<(std::ostream &out, const TPointT<t> &p) {</t>
Shinya Kitaoka 120a6e
  return out << "(" << p.x << ", " << p.y << ")";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TPointT<int> TPoint, TPointI;</int>
Toshihiro Shimizu 890ddd
typedef TPointT<double> TPointD;</double>
f9b4ad
typedef TPoint4T<double> TPoint4D;</double>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TPointT<int>;</int>
Toshihiro Shimizu 890ddd
template class DVAPI TPointT<double>;</double>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline bool operator==(const TPointT<t> &p0, const TPointT<t> &p1) {</t></t>
Shinya Kitaoka 120a6e
  return p0.x == p1.x && p0.y == p1.y;
Toshihiro Shimizu 890ddd
}
a19ac5
template<class t=""></class>
a19ac5
inline bool operator!=(const TPointT<t> &p0, const TPointT<t> &p1) {</t></t>
b25709
  return p0.x != p1.x || p0.y != p1.y;
a19ac5
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates TPointT
Shinya Kitaoka 120a6e
inline TPoint operator*(int a, const TPoint &p) {
Shinya Kitaoka 120a6e
  return TPoint(a * p.x, a * p.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates TPointT
Shinya Kitaoka 120a6e
inline TPoint operator*(const TPoint &p, int a) {
Shinya Kitaoka 120a6e
  return TPoint(a * p.x, a * p.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates TPointT
Shinya Kitaoka 120a6e
inline TPointD operator*(double a, const TPointD &p) {
Shinya Kitaoka 120a6e
  return TPointD(a * p.x, a * p.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates TPointT
Shinya Kitaoka 120a6e
inline TPointD operator*(const TPointD &p, double a) {
Shinya Kitaoka 120a6e
  return TPointD(a * p.x, a * p.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Shinya Kitaoka 120a6e
This helper function returns the square of the absolute value of the specified
Shinya Kitaoka 120a6e
point (a TPointI)
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline int norm2(const TPointI &p) { return p.x * p.x + p.y * p.y; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Shinya Kitaoka 120a6e
This helper function returns the square of the absolute value of the specified
Shinya Kitaoka 120a6e
point (a TPointD)
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline double norm2(const TPointD &p) { return p.x * p.x + p.y * p.y; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Shinya Kitaoka 120a6e
This helper function returns the absolute value of the specified point
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline double norm(const TPointD &p) { return std::sqrt(norm2(p)); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Shinya Kitaoka 120a6e
This helper function returns the normalized version of the specified point
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline TPointD normalize(const TPointD &p) {
Shinya Kitaoka 120a6e
  double n = norm(p);
Shinya Kitaoka 120a6e
  assert(n != 0.0);
Shinya Kitaoka 120a6e
  return (1.0 / n) * p;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Toshihiro Shimizu 890ddd
This helper function converts a TPoint (TPointT<int>) into a TPointD</int>
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline TPointD convert(const TPoint &p) { return TPointD(p.x, p.y); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Toshihiro Shimizu 890ddd
This helper function converts a TPointD (TPointT<double>) into a TPoint</double>
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline TPoint convert(const TPointD &p) {
Shinya Kitaoka 120a6e
  return TPoint(tround(p.x), tround(p.y));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Shinya Kitaoka 120a6e
This helper function returns the square of the distance between two points
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline double tdistance2(const TPointD &p1, const TPointD &p2) {
Shinya Kitaoka 120a6e
  return norm2(p2 - p1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool operator==(const TPointD &p0, const TPointD &p1) {
Shinya Kitaoka 120a6e
  return tdistance2(p0, p1) < TConsts::epsilon * TConsts::epsilon;
Toshihiro Shimizu 890ddd
}
a19ac5
inline bool operator!=(const TPointD &p0, const TPointD &p1) {
a19ac5
  return !(p0 == p1);
a19ac5
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Shinya Kitaoka 120a6e
This helper function returns the distance between two points
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline double tdistance(const TPointD &p1, const TPointD &p2) {
Shinya Kitaoka 120a6e
  return norm(p2 - p1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
the cross product
Toshihiro Shimizu 890ddd
\relates TPointT
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline double cross(const TPointD &a, const TPointD &b) {
Shinya Kitaoka 120a6e
  return a.x * b.y - a.y * b.x;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
the cross product
Toshihiro Shimizu 890ddd
\relates TPoint
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline int cross(const TPoint &a, const TPoint &b) {
Shinya Kitaoka 120a6e
  return a.x * b.y - a.y * b.x;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
returns the angle of the point p in polar coordinates
Toshihiro Shimizu 890ddd
n.b atan(-y) = -pi/2, atan(x) = 0, atan(y) = pi/2, atan(-x) = pi
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline double atan(const TPointD &p) { return atan2(p.y, p.x); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class DVAPI T3DPointT {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  T x, y, z;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  T3DPointT() : x(0), y(0), z(0) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  T3DPointT(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}
Shinya Kitaoka 120a6e
  T3DPointT(const TPointT<t> &_p, T _z) : x(_p.x), y(_p.y), z(_z) {}</t>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  T3DPointT(const T3DPointT &_p) : x(_p.x), y(_p.y), z(_p.z) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline T3DPointT &operator=(const T3DPointT &a) {
Shinya Kitaoka 120a6e
    x = a.x;
Shinya Kitaoka 120a6e
    y = a.y;
Shinya Kitaoka 120a6e
    z = a.z;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline T3DPointT &operator+=(const T3DPointT &a) {
Shinya Kitaoka 120a6e
    x += a.x;
Shinya Kitaoka 120a6e
    y += a.y;
Shinya Kitaoka 120a6e
    z += a.z;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline T3DPointT &operator-=(const T3DPointT &a) {
Shinya Kitaoka 120a6e
    x -= a.x;
Shinya Kitaoka 120a6e
    y -= a.y;
Shinya Kitaoka 120a6e
    z -= a.z;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline T3DPointT operator+(const T3DPointT &a) const {
Shinya Kitaoka 120a6e
    return T3DPointT(x + a.x, y + a.y, z + a.z);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline T3DPointT operator-(const T3DPointT &a) const {
Shinya Kitaoka 120a6e
    return T3DPointT(x - a.x, y - a.y, z - a.z);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline T3DPointT operator-() const { return T3DPointT(-x, -y, -z); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool operator==(const T3DPointT &p) const {
Shinya Kitaoka 120a6e
    return x == p.x && y == p.y && z == p.z;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool operator!=(const T3DPointT &p) const {
Shinya Kitaoka 120a6e
    return x != p.x || y != p.y || z != p.z;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline std::ostream &operator<<(std::ostream &out, const T3DPointT<t> &p) {</t>
Shinya Kitaoka 120a6e
  return out << "(" << p.x << ", " << p.y << ", " << p.z << ")";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef T3DPointT<int> T3DPoint, T3DPointI;</int>
Toshihiro Shimizu 890ddd
typedef T3DPointT<double> T3DPointD;</double>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI T3DPointT<int>;</int>
Toshihiro Shimizu 890ddd
template class DVAPI T3DPointT<double>;</double>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates T3DPointT
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline T3DPointT<t> operator*(T a, const T3DPointT<t> &p) {</t></t>
Shinya Kitaoka 120a6e
  return T3DPointT<t>(a * p.x, a * p.y, a * p.z);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates TPointT
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline T3DPointT<t> operator*(const T3DPointT<t> &p, T a) {</t></t>
Shinya Kitaoka 120a6e
  return T3DPointT<t>(a * p.x, a * p.y, a * p.z);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointT
Shinya Kitaoka 120a6e
This helper function returns the square of the absolute value of the specified
Shinya Kitaoka 120a6e
point (a TPointI)
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline T norm2(const T3DPointT<t> &p) {</t>
Shinya Kitaoka 120a6e
  return p.x * p.x + p.y * p.y + p.z * p.z;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline T norm(const T3DPointT<t> &p) {</t>
Shinya Kitaoka 120a6e
  return std::sqrt(norm2(p));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline T3DPointD normalize(const T3DPointD &p) {
Shinya Kitaoka 120a6e
  double n = norm(p);
Shinya Kitaoka 120a6e
  assert(n != 0.0);
Shinya Kitaoka 120a6e
  return (1.0 / n) * p;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline T3DPointD convert(const T3DPoint &p) { return T3DPointD(p.x, p.y, p.z); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline T3DPoint convert(const T3DPointD &p) {
Shinya Kitaoka 120a6e
  return T3DPoint(tround(p.x), tround(p.y), tround(p.z));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline T tdistance(const T3DPointT<t> &p1, const T3DPointT<t> &p2) {</t></t>
Shinya Kitaoka 120a6e
  return norm<t>(p2 - p1);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline T tdistance2(const T3DPointT<t> &p1, const T3DPointT<t> &p2) {</t></t>
Shinya Kitaoka 120a6e
  return norm2<t>(p2 - p1);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline T3DPointT<t> cross(const T3DPointT<t> &a, const T3DPointT<t> &b) {</t></t></t>
Shinya Kitaoka 120a6e
  return T3DPointT<t>(a.y * b.z - b.y * a.z, a.z * b.x - b.z * a.x,</t>
Shinya Kitaoka 120a6e
                      a.x * b.y - b.x * a.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
TThickPoint describe a thick point.
Toshihiro Shimizu 890ddd
\relates TThickQuadratic, TThickCubic
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka d1f6c4
class DVAPI TThickPoint final : public TPointD {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  double thick;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TThickPoint() : TPointD(), thick(0) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TThickPoint(double _x, double _y, double _thick = 0)
Shinya Kitaoka 120a6e
      : TPointD(_x, _y), thick(_thick) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TThickPoint(const TPointD &_p, double _thick = 0)
Shinya Kitaoka 120a6e
      : TPointD(_p.x, _p.y), thick(_thick) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TThickPoint(const T3DPointD &_p) : TPointD(_p.x, _p.y), thick(_p.z) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TThickPoint(const TThickPoint &_p) : TPointD(_p.x, _p.y), thick(_p.thick) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline TThickPoint &operator=(const TThickPoint &a) {
Shinya Kitaoka 120a6e
    x     = a.x;
Shinya Kitaoka 120a6e
    y     = a.y;
Shinya Kitaoka 120a6e
    thick = a.thick;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline TThickPoint &operator+=(const TThickPoint &a) {
Shinya Kitaoka 120a6e
    x += a.x;
Shinya Kitaoka 120a6e
    y += a.y;
Shinya Kitaoka 120a6e
    thick += a.thick;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline TThickPoint &operator-=(const TThickPoint &a) {
Shinya Kitaoka 120a6e
    x -= a.x;
Shinya Kitaoka 120a6e
    y -= a.y;
Shinya Kitaoka 120a6e
    thick -= a.thick;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline TThickPoint operator+(const TThickPoint &a) const {
Shinya Kitaoka 120a6e
    return TThickPoint(x + a.x, y + a.y, thick + a.thick);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline TThickPoint operator-(const TThickPoint &a) const {
Shinya Kitaoka 120a6e
    return TThickPoint(x - a.x, y - a.y, thick - a.thick);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline TThickPoint operator-() const { return TThickPoint(-x, -y, -thick); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool operator==(const TThickPoint &p) const {
Shinya Kitaoka 120a6e
    return x == p.x && y == p.y && thick == p.thick;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool operator!=(const TThickPoint &p) const {
Shinya Kitaoka 120a6e
    return x != p.x || y != p.y || thick != p.thick;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline double operator*(const TThickPoint &a, const TThickPoint &b) {
Shinya Kitaoka 120a6e
  return a.x * b.x + a.y * b.y + a.thick * b.thick;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline TThickPoint operator*(double a, const TThickPoint &p) {
Shinya Kitaoka 120a6e
  return TThickPoint(a * p.x, a * p.y, a * p.thick);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline TThickPoint operator*(const TThickPoint &p, double a) {
Shinya Kitaoka 120a6e
  return TThickPoint(a * p.x, a * p.y, a * p.thick);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TPointD
Toshihiro Shimizu 890ddd
This helper function converts a TThickPoint into a TPointD
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline TPointD convert(const TThickPoint &p) { return TPointD(p.x, p.y); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TThickPoint
Shinya Kitaoka 120a6e
This helper function returns the square of the distance between two thick points
Toshihiro Shimizu 890ddd
(only x and y are used)
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline double tdistance2(const TThickPoint &p1, const TThickPoint &p2) {
Shinya Kitaoka 120a6e
  return norm2(convert(p2 - p1));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TThickPoint
Shinya Kitaoka 120a6e
This helper function returns the distance between two thick  points
Toshihiro Shimizu 890ddd
(only x and y are used)
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline double tdistance(const TThickPoint &p1, const TThickPoint &p2) {
Shinya Kitaoka 120a6e
  return norm(convert(p2 - p1));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline std::ostream &operator<<(std::ostream &out, const TThickPoint &p) {
Shinya Kitaoka 120a6e
  return out << "(" << p.x << ", " << p.y << ", " << p.thick << ")";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
//!	This is a template class representing a generic vector in a plane, i.e.
Shinya Kitaoka 38fd86
//! a point.
Shinya Kitaoka 120a6e
/*!
Shinya Kitaoka 120a6e
                It is a data structure with two objects in it representing
Shinya Kitaoka 120a6e
   coordinate of the point and
Shinya Kitaoka 120a6e
                the basic operations on it.
Shinya Kitaoka 120a6e
        */
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class DVAPI TDimensionT {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  T lx, ly;
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Constructs a vector of two elements, i.e. a point in a plane.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TDimensionT() : lx(), ly() {}
Shinya Kitaoka 120a6e
  TDimensionT(T _lx, T _ly) : lx(_lx), ly(_ly) {}
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Copy constructor.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TDimensionT(const TDimensionT &d) : lx(d.lx), ly(d.ly) {}
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Vector addition.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TDimensionT &operator+=(TDimensionT a) {
Shinya Kitaoka 120a6e
    lx += a.lx;
Shinya Kitaoka 120a6e
    ly += a.ly;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Difference of two vectors.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TDimensionT &operator-=(TDimensionT a) {
Shinya Kitaoka 120a6e
    lx -= a.lx;
Shinya Kitaoka 120a6e
    ly -= a.ly;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Addition of two vectors.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TDimensionT operator+(TDimensionT a) const {
Shinya Kitaoka 120a6e
    TDimensionT ris(*this);
Shinya Kitaoka 120a6e
    return ris += a;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Vector difference.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TDimensionT operator-(TDimensionT a) const {
Shinya Kitaoka 120a6e
    TDimensionT ris(*this);
Shinya Kitaoka 120a6e
    return ris -= a;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Compare vectors and returns \e true if are equals element by element.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  bool operator==(const TDimensionT &d) const {
Shinya Kitaoka 120a6e
    return lx == d.lx && ly == d.ly;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Compare vectors and returns \e true if are not equals element by
Shinya Kitaoka 120a6e
     element.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  bool operator!=(const TDimensionT &d) const { return !operator==(d); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TDimensionT<int> TDimension, TDimensionI;</int>
Toshihiro Shimizu 890ddd
typedef TDimensionT<double> TDimensionD;</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline std::ostream &operator<<(std::ostream &out, const TDimensionT<t> &p) {</t>
Shinya Kitaoka 120a6e
  return out << "(" << p.lx << ", " << p.ly << ")";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TDimensionT<int>;</int>
Toshihiro Shimizu 890ddd
template class DVAPI TDimensionT<double>;</double>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! Specifies the corners of a rectangle.
Jeremy Bullock 66c844
/*!
Jeremy Bullock 66c844
x0 specifies the x-coordinate of the bottom-left corner of a rectangle.
Jeremy Bullock 66c844
y0 specifies the y-coordinate of the bottom-left corner of a rectangle.
Jeremy Bullock 66c844
x1 specifies the x-coordinate of the upper-right corner of a rectangle.
Jeremy Bullock 66c844
y1 specifies the y-coordinate of the upper-right corner of a rectangle.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class DVAPI TRectT {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  /*! if x0>x1 || y0>y1 then rect is empty
Shinya Kitaoka 120a6e
if x0==y1 && y0==y1 and rect is a  TRectD then rect is empty */
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  T x0, y0;
Shinya Kitaoka 120a6e
  T x1, y1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! makes an empty rect */
Shinya Kitaoka 120a6e
  TRectT();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRectT(T _x0, T _y0, T _x1, T _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1){};
Jeremy Bullock 66c844
Shinya Kitaoka 120a6e
  TRectT(const TRectT &rect)
Shinya Kitaoka 120a6e
      : x0(rect.x0), y0(rect.y0), x1(rect.x1), y1(rect.y1){};
Jeremy Bullock 66c844
Shinya Kitaoka 120a6e
  TRectT(const TPointT<t> &p0, const TPointT<t> &p1)  // non importa l'ordine</t></t>
Shinya Kitaoka 120a6e
      : x0(std::min((T)p0.x, (T)p1.x)),
Shinya Kitaoka 120a6e
        y0(std::min((T)p0.y, (T)p1.y)),
Shinya Kitaoka 120a6e
        x1(std::max((T)p0.x, (T)p1.x)),
Shinya Kitaoka 120a6e
        y1(std::max((T)p0.y, (T)p1.y)){};
Jeremy Bullock 66c844
Shinya Kitaoka 120a6e
  TRectT(const TPointT<t> &bottomLeft, const TDimensionT<t> &d);</t></t>
Jeremy Bullock 66c844
Shinya Kitaoka 120a6e
  TRectT(const TDimensionT<t> &d);</t>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void empty();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! TRectD is empty if and only if (x0>x1 || y0>y1) || (x0==y1 && y0==y1);
Shinya Kitaoka 120a6e
TRectI  is empty if x0>x1 || y0>y1 */
Shinya Kitaoka 120a6e
  bool isEmpty() const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  T getLx() const;
Shinya Kitaoka 120a6e
  T getLy() const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDimensionT<t> getSize() const { return TDimensionT<t>(getLx(), getLy()); };</t></t>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointT<t> getP00() const { return TPointT<t>(x0, y0); };</t></t>
Shinya Kitaoka 120a6e
  TPointT<t> getP10() const { return TPointT<t>(x1, y0); };</t></t>
Shinya Kitaoka 120a6e
  TPointT<t> getP01() const { return TPointT<t>(x0, y1); };</t></t>
Shinya Kitaoka 120a6e
  TPointT<t> getP11() const { return TPointT<t>(x1, y1); };</t></t>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Returns the union of two source rectangles.
Jeremy Bullock 66c844
  //!The union is the smallest rectangle that contains both source rectangles.
Shinya Kitaoka 120a6e
  TRectT<t> operator+(const TRectT<t> &rect) const {  // unione</t></t>
Shinya Kitaoka 120a6e
    if (isEmpty())
Shinya Kitaoka 120a6e
      return rect;
Shinya Kitaoka 120a6e
    else if (rect.isEmpty())
Shinya Kitaoka 120a6e
      return *this;
Shinya Kitaoka 120a6e
    else
Jeremy Bullock 66c844
      return TRectT<t>(std::min((T)x0, (T)rect.x0), </t>
Jeremy Bullock 66c844
                       std::min((T)y0, (T)rect.y0),
Shinya Kitaoka 120a6e
                       std::max((T)x1, (T)rect.x1),
Shinya Kitaoka 120a6e
                       std::max((T)y1, (T)rect.y1));
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  TRectT<t> &operator+=(const TRectT<t> &rect) {  // unione</t></t>
Shinya Kitaoka 120a6e
    return *this = *this + rect;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  TRectT<t> &operator*=(const TRectT<t> &rect) {  // intersezione</t></t>
Shinya Kitaoka 120a6e
    return *this = *this * rect;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Jeremy Bullock 66c844
  //!Returns the intersection of two existing rectangles.
Jeremy Bullock 66c844
  //The intersection is the largest rectangle contained in both existing rectangles.
Shinya Kitaoka 120a6e
  TRectT<t> operator*(const TRectT<t> &rect) const {  // intersezione</t></t>
Shinya Kitaoka 120a6e
    if (isEmpty() || rect.isEmpty())
Shinya Kitaoka 120a6e
      return TRectT<t>();</t>
Shinya Kitaoka 120a6e
    else if (rect.x1 < x0 || x1 < rect.x0 || rect.y1 < y0 || y1 < rect.y0)
Shinya Kitaoka 120a6e
      return TRectT<t>();</t>
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TRectT<t>(std::max((T)x0, (T)rect.x0), std::max((T)y0, (T)rect.y0),</t>
Shinya Kitaoka 120a6e
                       std::min((T)x1, (T)rect.x1),
Shinya Kitaoka 120a6e
                       std::min((T)y1, (T)rect.y1));
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Jeremy Bullock 66c844
  TRectT<t> &operator+=(const TPointT<t> &p) {  // shift</t></t>
Shinya Kitaoka 120a6e
    x0 += p.x;
Shinya Kitaoka 120a6e
    y0 += p.y;
Shinya Kitaoka 120a6e
    x1 += p.x;
Shinya Kitaoka 120a6e
    y1 += p.y;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  TRectT<t> &operator-=(const TPointT<t> &p) {</t></t>
Shinya Kitaoka 120a6e
    x0 -= p.x;
Shinya Kitaoka 120a6e
    y0 -= p.y;
Shinya Kitaoka 120a6e
    x1 -= p.x;
Shinya Kitaoka 120a6e
    y1 -= p.y;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  TRectT<t> operator+(const TPointT<t> &p) const {</t></t>
Shinya Kitaoka 120a6e
    TRectT<t> ris(*this);</t>
Shinya Kitaoka 120a6e
    return ris += p;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  TRectT<t> operator-(const TPointT<t> &p) const {</t></t>
Shinya Kitaoka 120a6e
    TRectT<t> ris(*this);</t>
Shinya Kitaoka 120a6e
    return ris -= p;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool operator==(const TRectT<t> &r) const {</t>
Shinya Kitaoka 120a6e
    return x0 == r.x0 && y0 == r.y0 && x1 == r.x1 && y1 == r.y1;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool operator!=(const TRectT<t> &r) const {</t>
Shinya Kitaoka 120a6e
    return x0 != r.x0 || y0 != r.y0 || x1 != r.x1 || y1 != r.y1;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool contains(const TPointT<t> &p) const {</t>
Shinya Kitaoka 120a6e
    return x0 <= p.x && p.x <= x1 && y0 <= p.y && p.y <= y1;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool contains(const TRectT<t> &b) const {</t>
Shinya Kitaoka 120a6e
    return x0 <= b.x0 && x1 >= b.x1 && y0 <= b.y0 && y1 >= b.y1;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool overlaps(const TRectT<t> &b) const {</t>
Shinya Kitaoka 120a6e
    return x0 <= b.x1 && x1 >= b.x0 && y0 <= b.y1 && y1 >= b.y0;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRectT<t> enlarge(T dx, T dy) const {</t>
Shinya Kitaoka 120a6e
    if (isEmpty()) return *this;
Shinya Kitaoka 120a6e
    return TRectT<t>(x0 - dx, y0 - dy, x1 + dx, y1 + dy);</t>
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRectT<t> enlarge(T d) const { return enlarge(d, d); };</t>
Shinya Kitaoka 120a6e
  TRectT<t> enlarge(TDimensionT<t> d) const { return enlarge(d.lx, d.ly); };</t></t>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TRectT<int> TRect, TRectI;</int>
Toshihiro Shimizu 890ddd
typedef TRectT<double> TRectD;</double>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TRectT<int>;</int>
Toshihiro Shimizu 890ddd
template class DVAPI TRectT<double>;</double>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// check this, not final version
Shinya Kitaoka 120a6e
/*!
Toshihiro Shimizu 890ddd
\relates TRectT
Toshihiro Shimizu 890ddd
Convert a TRectD into a TRect
Toshihiro Shimizu 890ddd
*/
Jeremy Bullock 66c844
Shinya Kitaoka 120a6e
inline TRect convert(const TRectD &r) {
Shinya Kitaoka 120a6e
  return TRect((int)(r.x0 + 0.5), (int)(r.y0 + 0.5), (int)(r.x1 + 0.5),
Shinya Kitaoka 120a6e
               (int)(r.y1 + 0.5));
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
/*!
Shinya Kitaoka 120a6e
\relates TRectT
Toshihiro Shimizu 890ddd
Convert a TRect into a TRectD
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline TRectD convert(const TRect &r) { return TRectD(r.x0, r.y0, r.x1, r.y1); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// template?
Shinya Kitaoka 120a6e
/*!
Shinya Kitaoka 120a6e
\relates TRectT
Shinya Kitaoka 120a6e
\relates TPointT
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline TRectD boundingBox(const TPointD &p0, const TPointD &p1) {
Jeremy Bullock 66c844
  return TRectD(std::min(p0.x, p1.x), std::min(p0.y, p1.y),  // bottom left
Jeremy Bullock 66c844
                std::max(p0.x, p1.x), std::max(p0.y, p1.y));  // top right
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TRectT
Shinya Kitaoka 120a6e
\relates TPointT
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline TRectD boundingBox(const TPointD &p0, const TPointD &p1,
Shinya Kitaoka 120a6e
                          const TPointD &p2) {
Shinya Kitaoka 120a6e
  return TRectD(std::min({p0.x, p1.x, p2.x}), std::min({p0.y, p1.y, p2.y}),
Shinya Kitaoka 120a6e
                std::max({p0.x, p1.x, p2.x}), std::max({p0.y, p1.y, p2.y}));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
\relates TRectT
Shinya Kitaoka 120a6e
\relates TPointT
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
inline TRectD boundingBox(const TPointD &p0, const TPointD &p1,
Shinya Kitaoka 120a6e
                          const TPointD &p2, const TPointD &p3) {
Shinya Kitaoka 120a6e
  return TRectD(
Shinya Kitaoka 120a6e
      std::min({p0.x, p1.x, p2.x, p3.x}), std::min({p0.y, p1.y, p2.y, p3.y}),
Shinya Kitaoka 120a6e
      std::max({p0.x, p1.x, p2.x, p3.x}), std::max({p0.y, p1.y, p2.y, p3.y}));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock 66c844
// TRectT is a rectangle that uses thick points
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
inline TRectT<int>::TRectT() : x0(0), y0(0), x1(-1), y1(-1) {}</int>
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline TRectT<int>::TRectT(const TPointT<int> &bottomLeft,</int></int>
Shinya Kitaoka 120a6e
                           const TDimensionT<int> &d)</int>
Shinya Kitaoka 120a6e
    : x0(bottomLeft.x)
Shinya Kitaoka 120a6e
    , y0(bottomLeft.y)
Shinya Kitaoka 120a6e
    , x1(bottomLeft.x + d.lx - 1)
Shinya Kitaoka 120a6e
    , y1(bottomLeft.y + d.ly - 1){};
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
inline TRectT<int>::TRectT(const TDimensionT<int> &d)</int></int>
Shinya Kitaoka 120a6e
    : x0(0), y0(0), x1(d.lx - 1), y1(d.ly - 1){};
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline bool TRectT<int>::isEmpty() const {</int>
Shinya Kitaoka 120a6e
  return x0 > x1 || y0 > y1;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline void TRectT<int>::empty() {</int>
Shinya Kitaoka 120a6e
  x0 = y0 = 0;
Shinya Kitaoka 120a6e
  x1 = y1 = -1;
Toshihiro Shimizu 890ddd
}
Jeremy Bullock 66c844
Jeremy Bullock 66c844
// Is the adding of one here to account for the thickness?
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline int TRectT<int>::getLx() const {</int>
Shinya Kitaoka 120a6e
  return x1 >= x0 ? x1 - x0 + 1 : 0;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline int TRectT<int>::getLy() const {</int>
Shinya Kitaoka 120a6e
  return y1 >= y0 ? y1 - y0 + 1 : 0;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
inline TRectT<double>::TRectT() : x0(0), y0(0), x1(0), y1(0) {}</double>
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline TRectT<double>::TRectT(const TPointT<double> &bottomLeft,</double></double>
Shinya Kitaoka 120a6e
                              const TDimensionT<double> &d)</double>
Shinya Kitaoka 120a6e
    : x0(bottomLeft.x)
Shinya Kitaoka 120a6e
    , y0(bottomLeft.y)
Shinya Kitaoka 120a6e
    , x1(bottomLeft.x + d.lx)
Shinya Kitaoka 120a6e
    , y1(bottomLeft.y + d.ly){};
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
inline TRectT<double>::TRectT(const TDimensionT<double> &d)</double></double>
Shinya Kitaoka 120a6e
    : x0(0.0), y0(0.0), x1(d.lx), y1(d.ly){};
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline bool TRectT<double>::isEmpty() const {</double>
Shinya Kitaoka 120a6e
  return (x0 == x1 && y0 == y1) || x0 > x1 || y0 > y1;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline void TRectT<double>::empty() {</double>
Shinya Kitaoka 120a6e
  x0 = y0 = x1 = y1 = 0;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline double TRectT<double>::getLx() const {</double>
Shinya Kitaoka 120a6e
  return x1 >= x0 ? x1 - x0 : 0;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline double TRectT<double>::getLy() const {</double>
Shinya Kitaoka 120a6e
  return y1 >= y0 ? y1 - y0 : 0;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline TRectD &operator*=(TRectD &rect, double factor) {
Shinya Kitaoka 120a6e
  rect.x0 *= factor;
Shinya Kitaoka 120a6e
  rect.y0 *= factor;
Shinya Kitaoka 120a6e
  rect.x1 *= factor;
Shinya Kitaoka 120a6e
  rect.y1 *= factor;
Shinya Kitaoka 120a6e
  return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline TRectD operator*(const TRectD &rect, double factor) {
Shinya Kitaoka 120a6e
  TRectD result(rect);
Shinya Kitaoka 120a6e
  return result *= factor;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline TRectD &operator/=(TRectD &rect, double factor) {
Shinya Kitaoka 120a6e
  assert(factor != 0.0);
Shinya Kitaoka 120a6e
  return rect *= (1.0 / factor);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline TRectD operator/(const TRectD &rect, double factor) {
Shinya Kitaoka 120a6e
  assert(factor != 0.0);
Shinya Kitaoka 120a6e
  TRectD result(rect);
Shinya Kitaoka 120a6e
  return result *= 1.0 / factor;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline std::ostream &operator<<(std::ostream &out, const TRectT<t> &r) {</t>
Shinya Kitaoka 120a6e
  return out << "(" << r.x0 << "," << r.y0 << ";" << r.x1 << "," << r.y1 << ")";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TConsts {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
extern DVVAR const TPointD napd;
Toshihiro Shimizu 890ddd
extern DVVAR const TPoint nap;
Toshihiro Shimizu 890ddd
extern DVVAR const T3DPointD nap3d;
Toshihiro Shimizu 890ddd
extern DVVAR const TThickPoint natp;
Toshihiro Shimizu 890ddd
extern DVVAR const TRectD infiniteRectD;
Toshihiro Shimizu 890ddd
extern DVVAR const TRectI infiniteRectI;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
//! This is the base class for the affine transformations.
Toshihiro Shimizu 890ddd
/*!
Jeremy Bullock 66c844
 This class performs basic manipulations of affine transformations.
Jeremy Bullock 66c844
 An affine transformation is a linear transformation followed by a translation.
Jeremy Bullock 66c844
 
Jeremy Bullock 66c844
  [a11, a12, a13]
Jeremy Bullock 66c844
  [a21, a22, a23]
Jeremy Bullock 66c844
Jeremy Bullock 66c844
  a13 and a23 represent translation (moving sideways or up and down)
Jeremy Bullock 66c844
  the other 4 handle rotation, scale and shear
Jeremy Bullock 66c844
*/
Shinya Kitaoka 120a6e
class DVAPI TAffine {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  double a11, a12, a13;
Shinya Kitaoka 120a6e
  double a21, a22, a23;
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          By default the object is initialized with a null matrix and a null
Shinya Kitaoka 120a6e
     translation vector.
Toshihiro Shimizu 890ddd
  */
Shinya Kitaoka 120a6e
  TAffine() : a11(1.0), a12(0.0), a13(0.0), a21(0.0), a22(1.0), a23(0.0){};
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Initializes the internal matrix and vector of translation with the
Shinya Kitaoka 120a6e
     user values.
Toshihiro Shimizu 890ddd
  */
Shinya Kitaoka 120a6e
  TAffine(double p11, double p12, double p13, double p21, double p22,
Shinya Kitaoka 120a6e
          double p23)
Shinya Kitaoka 120a6e
      : a11(p11), a12(p12), a13(p13), a21(p21), a22(p22), a23(p23){};
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Copy constructor.
Toshihiro Shimizu 890ddd
  */
Shinya Kitaoka 120a6e
  TAffine(const TAffine &a)
Shinya Kitaoka 120a6e
      : a11(a.a11)
Shinya Kitaoka 120a6e
      , a12(a.a12)
Shinya Kitaoka 120a6e
      , a13(a.a13)
Shinya Kitaoka 120a6e
      , a21(a.a21)
Shinya Kitaoka 120a6e
      , a22(a.a22)
Shinya Kitaoka 120a6e
      , a23(a.a23){};
f9b4ad
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Assignment operator.
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  TAffine &operator=(const TAffine &a);
Jeremy Bullock 66c844
  /*Moved to tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
a11 = a.a11; a12 = a.a12; a13 = a.a13;
Shinya Kitaoka 120a6e
a21 = a.a21; a22 = a.a22; a23 = a.a23;
Shinya Kitaoka 120a6e
return *this;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Matrix multiplication.
Shinya Kitaoka 120a6e
          

\f$\left(\begin{array}{cc}\bf{A}&\vec{a}\\\vec{0}&1\end{array}\right)

Shinya Kitaoka 120a6e
          \left(\begin{array}{cc}\bf{B}&\vec{b}\\\vec{0}&1\end{array}\right)\f$

Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  TAffine operator*(const TAffine &b) const;
Jeremy Bullock 66c844
  /*Moved to in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
return TAffine (
Shinya Kitaoka 120a6e
a11 * b.a11 + a12 * b.a21,
Shinya Kitaoka 120a6e
a11 * b.a12 + a12 * b.a22,
Shinya Kitaoka 120a6e
a11 * b.a13 + a12 * b.a23 + a13,
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
a21 * b.a11 + a22 * b.a21,
Shinya Kitaoka 120a6e
a21 * b.a12 + a22 * b.a22,
Shinya Kitaoka 120a6e
a21 * b.a13 + a22 * b.a23 + a23);
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TAffine operator*=(const TAffine &b);
Jeremy Bullock 66c844
  /*Moved to tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
return *this = *this * b;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  /*!
luz paz 6454c4
          Returns the inverse tansformation as:
Shinya Kitaoka 120a6e
          

\f$\left(\begin{array}{ccc}\bf{A}^{-1}&-\bf{A}^{-1}&\vec{b}\\\vec{0}&\vec{0}&1\end{array}\right)\f$

Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TAffine inv() const;
Jeremy Bullock 66c844
  /*Moved to tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
if(a12 == 0.0 && a21 == 0.0)
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
assert(a11 != 0.0);
Shinya Kitaoka 120a6e
assert(a22 != 0.0);
Shinya Kitaoka 120a6e
double inv_a11 = 1.0/a11;
Shinya Kitaoka 120a6e
double inv_a22 = 1.0/a22;
Shinya Kitaoka 120a6e
return TAffine(inv_a11,0, -a13 * inv_a11,
Shinya Kitaoka 120a6e
  0,inv_a22, -a23 * inv_a22);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
else if(a11 == 0.0 && a22 == 0.0)
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
assert(a12 != 0.0);
Shinya Kitaoka 120a6e
assert(a21 != 0.0);
Shinya Kitaoka 120a6e
double inv_a21 = 1.0/a21;
Shinya Kitaoka 120a6e
double inv_a12 = 1.0/a12;
Shinya Kitaoka 120a6e
return TAffine(0, inv_a21, -a23 * inv_a21,
Shinya Kitaoka 120a6e
  inv_a12, 0, -a13 * inv_a12);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
else
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
double d = 1./det();
Shinya Kitaoka 120a6e
return TAffine(a22*d,-a12*d, (a12*a23-a22*a13)*d,
Shinya Kitaoka 120a6e
  -a21*d, a11*d, (a21*a13-a11*a23)*d);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double det() const;
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp{
Shinya Kitaoka 120a6e
return a11*a22-a12*a21;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns \e true if all elements are equals.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  bool operator==(const TAffine &a) const;
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
return a11==a.a11 && a12==a.a12 && a13==a.a13 &&
Shinya Kitaoka 120a6e
a21==a.a21 && a22==a.a22 && a23==a.a23;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns \e true if at least one element is different.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool operator!=(const TAffine &a) const;
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
return a11!=a.a11 || a12!=a.a12 || a13!=a.a13 ||
Shinya Kitaoka 120a6e
a21!=a.a21 || a22!=a.a22 || a23!=a.a23;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns \e true if the transformation is an identity,
Shinya Kitaoka 120a6e
          i.e in the error limit \e err leaves the vectors unchanged.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isIdentity(double err = 1.e-8) const;
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
return ((a11-1.0)*(a11-1.0)+(a22-1.0)*(a22-1.0)+
Shinya Kitaoka 120a6e
a12*a12+a13*a13+a21*a21+a23*a23) < err;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns \e true if in the error limits \e err \f$\bf{A}\f$ is the
Shinya Kitaoka 120a6e
     identity matrix.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
9a49d4
  bool isZero(double err = 1.e-8) const;
9a49d4
Shinya Kitaoka 120a6e
  bool isTranslation(double err = 1.e-8) const;
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
return ((a11-1.0)*(a11-1.0)+(a22-1.0)*(a22-1.0)+
Shinya Kitaoka 120a6e
a12*a12+a21*a21) < err;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns \e true if in the error limits the matrix \f$\bf{A}\f$ is of
Shinya Kitaoka 120a6e
     the form:
Shinya Kitaoka 120a6e
          

\f$\left(\begin{array}{cc}a&b\\-b&a\end{array}\right)\f$

.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isIsotropic(double err = 1.e-8) const;
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Toshihiro Shimizu 890ddd
  {
Shinya Kitaoka 120a6e
    return areAlmostEqual(a11, a22, err) && areAlmostEqual(a12, -a21, err);
Toshihiro Shimizu 890ddd
  };
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!
luz paz 6454c4
          Returns the transformed point.
Toshihiro Shimizu 890ddd
  */
Shinya Kitaoka 120a6e
  TPointD operator*(const TPointD &p) const;
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
return TPointD(p.x*a11+p.y*a12+a13, p.x*a21+p.y*a22+a23);
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!
f9b4ad
          Transform point without translation
f9b4ad
  */
f9b4ad
  TPointD transformDirection(const TPointD &p) const;
f9b4ad
f9b4ad
  /*!
f9b4ad
          Retruns the transformed box of the bounding box.
Toshihiro Shimizu 890ddd
  */
Shinya Kitaoka 120a6e
  TRectD operator*(const TRectD &rect) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns a translated matrix that change the vector (u,v) in (x,y).
Shinya Kitaoka 120a6e
  \n	It returns a matrix of the form:
Shinya Kitaoka 120a6e
          

\f$\left(\begin{array}{ccc}\bf{A}&\vec{x}-\bf{A} \vec{u}\\

Shinya Kitaoka 120a6e
          \vec{0}&1\end{array}\right)\f$

Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TAffine place(double u, double v, double x, double y) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          See above.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TAffine place(const TPointD &pIn, const TPointD &pOut) const;
9a49d4
9a49d4
  inline static TAffine identity()
9a49d4
    { return TAffine(); }
9a49d4
  inline static TAffine zero()
9a49d4
    { return TAffine(0, 0, 0, 0, 0, 0); }
9a49d4
9a49d4
  inline static TAffine translation(double x, double y)
9a49d4
    { return TAffine(1, 0, x, 0, 1, y); }
9a49d4
  inline static TAffine translation(const TPointD &p)
9a49d4
    { return translation(p.x, p.y); }
9a49d4
9a49d4
  inline static TAffine scale(double sx, double sy)
9a49d4
    { return TAffine(sx, 0, 0, 0, sy, 0); }
9a49d4
  inline static TAffine scale(double s)
9a49d4
    { return scale(s, s); }
9a49d4
  inline static TAffine scale(const TPointD ¢er, double sx, double sy)
9a49d4
    { return translation(center)*scale(sx, sy)*translation(-center); }
9a49d4
  inline static TAffine scale(const TPointD ¢er, double s)
9a49d4
    { return scale(center, s, s); }
9a49d4
9a49d4
  static TAffine rotation(double angle);
9a49d4
  inline static TAffine rotation(const TPointD ¢er, double angle)
9a49d4
    { return translation(center)*rotation(angle)*translation(-center); }
9a49d4
9a49d4
  inline static TAffine shear(double sx, double sy)
9a49d4
    { return TAffine(1, sx, 0, sy, 1, 0); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// template <>
Shinya Kitaoka 120a6e
inline bool areAlmostEqual(const TPointD &a, const TPointD &b,
Shinya Kitaoka 120a6e
                           double err = TConsts::epsilon) {
Shinya Kitaoka 120a6e
  return tdistance2(a, b) < err * err;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// template <>
Shinya Kitaoka 120a6e
inline bool areAlmostEqual(const TRectD &a, const TRectD &b,
Shinya Kitaoka 120a6e
                           double err = TConsts::epsilon) {
Shinya Kitaoka 120a6e
  return areAlmostEqual(a.getP00(), b.getP00(), err) &&
Shinya Kitaoka 120a6e
         areAlmostEqual(a.getP11(), b.getP11(), err);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const TAffine AffI = TAffine();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TTranslation final : public TAffine {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TTranslation(){};
Shinya Kitaoka 120a6e
  TTranslation(double x, double y) : TAffine(1, 0, x, 0, 1, y){};
Shinya Kitaoka 120a6e
  TTranslation(const TPointD &p) : TAffine(1, 0, p.x, 0, 1, p.y){};
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TRotation final : public TAffine {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TRotation(){};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*! makes a rotation matrix of  "degrees" degrees counterclockwise
Shinya Kitaoka 120a6e
on the origin */
Shinya Kitaoka 120a6e
  TRotation(double degrees);
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
double rad, sn, cs;
Shinya Kitaoka 120a6e
int idegrees = (int)degrees;
Shinya Kitaoka 120a6e
if ((double)idegrees == degrees && idegrees % 90 == 0)
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
switch ((idegrees / 90) & 3)
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
case 0:  sn =  0; cs =  1; break;
Shinya Kitaoka 120a6e
case 1:  sn =  1; cs =  0; break;
Shinya Kitaoka 120a6e
case 2:  sn =  0; cs = -1; break;
Shinya Kitaoka 120a6e
case 3:  sn = -1; cs =  0; break;
Shinya Kitaoka 120a6e
default: sn =  0; cs =  0; break;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
else
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
rad = degrees * (TConsts::pi_180);
Shinya Kitaoka 120a6e
sn = sin (rad);
Shinya Kitaoka 120a6e
cs = cos (rad);
Shinya Kitaoka 120a6e
if (sn == 1 || sn == -1)
Shinya Kitaoka 120a6e
  cs = 0;
Shinya Kitaoka 120a6e
if (cs == 1 || cs == -1)
Shinya Kitaoka 120a6e
  sn = 0;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
a11=cs;a12= -sn;a21= -a12;a22=a11;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*! makes a rotation matrix of  "degrees" degrees counterclockwise
Shinya Kitaoka 120a6e
on the given center */
Shinya Kitaoka 120a6e
  TRotation(const TPointD ¢er, double degrees);
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
TAffine a = TTranslation(center) * TRotation(degrees) * TTranslation(-center);
Shinya Kitaoka 120a6e
a11 = a.a11; a12 = a.a12; a13 = a.a13;
Shinya Kitaoka 120a6e
a21 = a.a21; a22 = a.a22; a23 = a.a23;
Shinya Kitaoka 120a6e
};
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TScale final : public TAffine {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TScale(){};
Shinya Kitaoka 120a6e
  TScale(double sx, double sy) : TAffine(sx, 0, 0, 0, sy, 0){};
Shinya Kitaoka 120a6e
  TScale(double s) : TAffine(s, 0, 0, 0, s, 0) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TScale(const TPointD ¢er, double sx, double sy);
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
TAffine a = TTranslation(center) * TScale(sx,sy) * TTranslation(-center);
Shinya Kitaoka 120a6e
a11 = a.a11; a12 = a.a12; a13 = a.a13;
Shinya Kitaoka 120a6e
a21 = a.a21; a22 = a.a22; a23 = a.a23;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TScale(const TPointD ¢er, double s);
Shinya Kitaoka 120a6e
  /*Sposto in tgeometry.cpp
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
TAffine a = TTranslation(center) * TScale(s) * TTranslation(-center);
Shinya Kitaoka 120a6e
a11 = a.a11; a12 = a.a12; a13 = a.a13;
Shinya Kitaoka 120a6e
a21 = a.a21; a22 = a.a22; a23 = a.a23;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TShear final : public TAffine {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TShear(){};
Shinya Kitaoka 120a6e
  TShear(double sx, double sy) : TAffine(1, sx, 0, sy, 1, 0){};
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool areEquals(const TAffine &a, const TAffine &b, double err = 1e-8) {
Shinya Kitaoka 120a6e
  return fabs(a.a11 - b.a11) < err && fabs(a.a12 - b.a12) < err &&
Shinya Kitaoka 120a6e
         fabs(a.a13 - b.a13) < err && fabs(a.a21 - b.a21) < err &&
Shinya Kitaoka 120a6e
         fabs(a.a22 - b.a22) < err && fabs(a.a23 - b.a23) < err;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline TAffine inv(const TAffine &a) { return a.inv(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline std::ostream &operator<<(std::ostream &out, const TAffine &a) {
Shinya Kitaoka 120a6e
  return out << "(" << a.a11 << ", " << a.a12 << ", " << a.a13 << ";" << a.a21
Shinya Kitaoka 120a6e
             << ", " << a.a22 << ", " << a.a23 << ")";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
f9b4ad
f9b4ad
//=============================================================================
f9b4ad
f9b4ad
//! This class performs basic manipulations of affine transformations in 3D space.
f9b4ad
//! the matrix is transposed to TAffine and equal to OpenGL
f9b4ad
f9b4ad
class DVAPI TAffine4 {
f9b4ad
public:
f9b4ad
  union {
f9b4ad
    struct {
f9b4ad
      double a11, a12, a13, a14;
f9b4ad
      double a21, a22, a23, a24;
f9b4ad
      double a31, a32, a33, a34;
f9b4ad
      double a41, a42, a43, a44;
f9b4ad
    };
f9b4ad
    double m[4][4];
f9b4ad
    double a[16];
f9b4ad
  };
f9b4ad
f9b4ad
  inline TAffine4():
f9b4ad
    a11(1.0), a12(0.0), a13(0.0), a14(0.0),
f9b4ad
    a21(0.0), a22(1.0), a23(0.0), a24(0.0),
f9b4ad
    a31(0.0), a32(0.0), a33(1.0), a34(0.0),
f9b4ad
    a41(0.0), a42(0.0), a43(0.0), a44(1.0) { }
f9b4ad
f9b4ad
  inline explicit TAffine4(const TAffine &a):
f9b4ad
    a11(a.a11), a12(a.a21), a13(0.0), a14(0.0),
f9b4ad
    a21(a.a12), a22(a.a22), a23(0.0), a24(0.0),
f9b4ad
    a31( 0.0 ), a32( 0.0 ), a33(1.0), a34(0.0),
f9b4ad
    a41(a.a13), a42(a.a23), a43(0.0), a44(1.0) { }
f9b4ad
f9b4ad
  inline TAffine4(
f9b4ad
    const TPoint4D &rowX,
f9b4ad
    const TPoint4D &rowY,
f9b4ad
    const TPoint4D &rowZ,
f9b4ad
    const TPoint4D &rowW
f9b4ad
  ):
f9b4ad
    a11(rowX.x), a12(rowX.y), a13(rowX.z), a14(rowX.w),
f9b4ad
    a21(rowY.x), a22(rowY.y), a23(rowY.z), a24(rowY.w),
f9b4ad
    a31(rowZ.x), a32(rowZ.y), a33(rowZ.z), a34(rowZ.w),
f9b4ad
    a41(rowW.x), a42(rowW.y), a43(rowW.z), a44(rowW.w) { }
f9b4ad
f9b4ad
  inline TPoint4D& row(int index)
f9b4ad
    { return *(TPoint4D*)(m[index]); }
f9b4ad
  inline const TPoint4D& row(int index) const
f9b4ad
    { return *(const TPoint4D*)(m[index]); }
f9b4ad
f9b4ad
  inline TPoint4D& rowX() { return row(0); }
f9b4ad
  inline TPoint4D& rowY() { return row(1); }
f9b4ad
  inline TPoint4D& rowZ() { return row(2); }
f9b4ad
  inline TPoint4D& rowW() { return row(3); }
f9b4ad
f9b4ad
  inline const TPoint4D& rowX() const { return row(0); }
f9b4ad
  inline const TPoint4D& rowY() const { return row(1); }
f9b4ad
  inline const TPoint4D& rowZ() const { return row(2); }
f9b4ad
  inline const TPoint4D& rowW() const { return row(3); }
f9b4ad
f9b4ad
  TPoint4D operator*(const TPoint4D &b) const;
f9b4ad
  TAffine4 operator*(const TAffine4 &b) const;
f9b4ad
  TAffine4 operator*=(const TAffine4 &b);
f9b4ad
f9b4ad
  TAffine4 inv() const;
f9b4ad
f9b4ad
  TAffine get2d(double z = 0.0) const;
f9b4ad
f9b4ad
  inline static TAffine4 identity() { return TAffine4(); }
f9b4ad
  static TAffine4 translation(double x, double y, double z);
f9b4ad
  static TAffine4 scale(double x, double y, double z);
f9b4ad
  static TAffine4 rotation(double x, double y, double z, double angle);
f9b4ad
  static TAffine4 rotationX(double angle);
f9b4ad
  static TAffine4 rotationY(double angle);
f9b4ad
  static TAffine4 rotationZ(double angle);
f9b4ad
  static TAffine4 perspective(double near, double far, double tangent);
f9b4ad
};
f9b4ad
58525d
58525d
//=============================================================================
58525d
58525d
//! This class performs binary manipulations with angle ranges
58525d
9a49d4
typedef unsigned int TAngleI;
9a49d4
58525d
class DVAPI TAngleRangeSet {
58525d
public:
9a49d4
  typedef TAngleI Type;
58525d
  typedef std::vector<type> List;</type>
58525d
f36ea4
  static const Type min = Type();
58525d
  static const Type max = Type() - Type(1);
58525d
  static const Type half = ((Type() - Type(1)) >> 1) + Type(1);
58525d
58525d
  static Type fromDouble(double a)
58525d
    { return Type(round((a/M_2PI + 0.5)*max)); }
58525d
  static double toDouble(Type a)
58525d
    { return ((double)a/(double)max - 0.5)*M_2PI; }
5d8766
  static List::const_iterator empty_iterator()
5d8766
    { static List list; return list.end(); }
5d8766
  
58525d
  struct Range {
58525d
    Type a0, a1;
58525d
    Range(): a0(), a1() { }
58525d
    Range(Type a0, Type a1): a0(a0), a1(a1) { }
58525d
    inline bool isEmpty() const { return a0 == a1; }
58525d
    inline Range flip() const { return Range(a1, a0); }
58525d
  };
58525d
ac9bac
  struct Iterator {
ac9bac
  private:
ac9bac
    bool m_flip;
ac9bac
    List::const_iterator m_prebegin;
ac9bac
    List::const_iterator m_begin;
ac9bac
    List::const_iterator m_end;
ac9bac
    List::const_iterator m_current;
ac9bac
    bool m_lapped;
ac9bac
ac9bac
  public:
ac9bac
    inline Iterator(): m_flip(), m_lapped(true)
ac9bac
      { reset(); }
ac9bac
    inline explicit Iterator(const List &list, bool flip = false, bool reverse = false)
ac9bac
      { set(list, flip, reverse); }
ac9bac
    inline explicit Iterator(const TAngleRangeSet &ranges, bool flip = false, bool reverse = false)
ac9bac
      { set(ranges, flip, reverse); }
ac9bac
ac9bac
    inline Iterator& set(bool full) {
ac9bac
      m_flip = full; m_lapped = !m_flip;
036a63
      m_current = m_prebegin = m_begin = m_end = empty_iterator();
ac9bac
      return *this;
ac9bac
    }
ac9bac
ac9bac
    inline Iterator& reset()
ac9bac
      { return set(false); }
ac9bac
ac9bac
    inline Iterator& set(const List &list, bool flip = false, bool reverse = false) {
ac9bac
      assert(list.size()%2 == 0);
ac9bac
      if (list.empty()) {
ac9bac
        set(flip);
ac9bac
      } else {
ac9bac
        m_flip = flip;
ac9bac
        m_lapped = false;
ac9bac
        if (flip) {
ac9bac
          m_prebegin = list.end() - 1;
ac9bac
          m_begin = list.begin();
ac9bac
          m_end = m_prebegin - 1;
ac9bac
        } else {
ac9bac
          m_prebegin = list.begin();
ac9bac
          m_begin = m_prebegin + 1;
ac9bac
          m_end = list.end() - 1;
ac9bac
        }
ac9bac
      }
ac9bac
      m_current = reverse ? m_end : m_begin;
ac9bac
      return *this;
ac9bac
    }
ac9bac
ac9bac
    inline Iterator& set(const TAngleRangeSet &ranges, bool flip = false, bool reverse = false)
ac9bac
      { return set(ranges.angles(), ranges.isFlipped() != flip, reverse); }
ac9bac
f36ea4
    inline const Type a0() const
f36ea4
      { return valid() ? *(m_current == m_begin ? m_prebegin : m_current - 1) : Type(); }
f36ea4
    inline const Type a1() const
f36ea4
      { return valid() ? *m_current : Type(); }
ac9bac
    inline double d0() const
ac9bac
      { return toDouble(a0()); }
ac9bac
    inline double d1() const
ac9bac
      { return toDouble(a1()); }
ac9bac
    inline double d1greater() const {
ac9bac
      return !valid() ? (m_flip ? M_PI : -M_PI)
ac9bac
           : m_current == m_begin && m_prebegin > m_begin
ac9bac
           ? toDouble(*m_current) + M_2PI : toDouble(*m_current);
ac9bac
    }
ac9bac
    inline Range range() const
ac9bac
      { return Range(a0(), a1()); }
ac9bac
    inline int size() const
ac9bac
      { return (m_end - m_begin)/2 + 1; }
ac9bac
    inline int index() const
ac9bac
      { return (m_current - m_begin)/2; }
ac9bac
    inline int reverseIndex() const
ac9bac
      { int i = index(); return i == 0 ? 0 : size() - i; }
ac9bac
    inline bool lapped() const
ac9bac
      { return m_lapped; }
ac9bac
    inline bool valid() const
ac9bac
      { return m_prebegin != m_begin; }
ac9bac
    inline bool isFull() const
ac9bac
      { return !valid() && m_flip; }
ac9bac
    inline bool isEmpty() const
ac9bac
      { return !valid() && !m_flip; }
ac9bac
ac9bac
    inline operator bool() const
ac9bac
      { return !m_lapped; }
ac9bac
ac9bac
    inline Iterator& operator++() {
ac9bac
      if (!valid()) { m_lapped = true; return *this; }
ac9bac
      m_lapped = (m_current == m_end);
ac9bac
      if (m_lapped) m_current = m_begin; else m_current += 2;
ac9bac
      return *this;
ac9bac
    }
ac9bac
ac9bac
    inline Iterator& operator--() {
ac9bac
      if (!valid()) { m_lapped = true; return *this; }
ac9bac
      m_lapped = (m_current == m_end);
ac9bac
      if (m_lapped) m_current = m_end; else m_current -= 2;
ac9bac
      return *this;
ac9bac
    }
ac9bac
ac9bac
    inline Iterator& operator += (int i) {
ac9bac
      if (i == 0) { m_lapped = isEmpty(); return *this; }
ac9bac
      if (!valid()) { m_lapped = true; return *this; }
ac9bac
      int ii = index();
ac9bac
      int s = size();
ac9bac
      if (ii + i >= 0 && ii + i < s) {
ac9bac
        m_current += i*2;
ac9bac
        m_lapped = false;
ac9bac
      } else {
ac9bac
        m_current = m_begin + ((ii + s + i%s)%s)*2;
ac9bac
        m_lapped = true;
ac9bac
      }
ac9bac
      return *this;
ac9bac
    }
ac9bac
ac9bac
    inline int operator-(const Iterator &i) const {
ac9bac
      assert(m_flip == i.m_flip && m_begin == i.m_begin && m_end == i.m_end && m_prebegin == i.m_prebegin);
ac9bac
      int ii = m_current - i.m_current;
ac9bac
      return ii < 0 ? ii + size() : ii;
ac9bac
    }
ac9bac
ac9bac
    inline Iterator operator++() const
ac9bac
      { Iterator copy(*this); ++(*this); return copy; }
ac9bac
    inline Iterator operator--() const
ac9bac
      { Iterator copy(*this); --(*this); return copy; }
ac9bac
    inline Iterator& operator -= (int i)
ac9bac
      { return (*this) += -i; }
ac9bac
    inline Iterator operator+(int i) const
ac9bac
      { Iterator ii(*this); return ii += i; }
ac9bac
    inline Iterator operator-(int i) const
ac9bac
      { Iterator ii(*this); return ii -= i; }
ac9bac
  };
ac9bac
58525d
private:
58525d
  bool m_flip;
58525d
  List m_angles;
58525d
58525d
  int find(Type a) const;
58525d
  void insert(Type a);
812e8c
  void doAdd(Type a0, Type a1);
58525d
58525d
public:
58525d
  inline explicit TAngleRangeSet(bool fill = false): m_flip(fill) { }
58525d
  inline TAngleRangeSet(const TAngleRangeSet &x, bool flip = false):
58525d
      m_flip(x.isFlipped() != flip), m_angles(x.angles()) { }
58525d
58525d
  inline const List& angles() const { return m_angles; }
58525d
  inline bool isFlipped() const { return m_flip; }
58525d
  inline bool isEmpty() const { return !m_flip && m_angles.empty(); }
58525d
  inline bool isFull() const { return m_flip && m_angles.empty(); }
58525d
58525d
  bool contains(Type a) const;
58525d
  bool check() const;
58525d
58525d
  inline void clear() { m_flip = false; m_angles.clear(); }
58525d
  inline void fill() { m_flip = true; m_angles.clear(); }
58525d
  inline void invert() { m_flip = !m_flip; }
58525d
58525d
  void set(Type a0, Type a1);
58525d
  void set(const TAngleRangeSet &x, bool flip = false);
58525d
58525d
  //! also known as 'xor'
58525d
  void invert(Type a0, Type a1);
58525d
  inline void invert(const Range &x) { invert(x.a0, x.a1); }
58525d
  void invert(const TAngleRangeSet &x);
58525d
58525d
  void add(Type a0, Type a1);
58525d
  inline void add(const Range &x) { add(x.a0, x.a1); }
58525d
  void add(const TAngleRangeSet &x);
58525d
58525d
  void subtract(Type a0, Type a1);
58525d
  inline void subtract(const Range &x) { subtract(x.a0, x.a1); }
58525d
  void subtract(const TAngleRangeSet &x);
58525d
58525d
  void intersect(Type a0, Type a1);
58525d
  inline void intersect(const Range &x) { intersect(x.a0, x.a1); }
58525d
  void intersect(const TAngleRangeSet &x);
58525d
};
58525d
58525d
Shinya Kitaoka 120a6e
#endif  //  __T_GEOMETRY_INCLUDED__