|
Toshihiro Shimizu |
890ddd |
|
|
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 |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* This is an example of how to use the TPointT, the TRectT and the TAffine 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>
|
|
Toshihiro Shimizu |
890ddd |
class TPointT
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
T x, y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointT() : x(0), y(0){};
|
|
Toshihiro Shimizu |
890ddd |
TPointT(T _x, T _y) : x(_x), y(_y){};
|
|
Toshihiro Shimizu |
890ddd |
TPointT(const TPointT &point) : x(point.x), y(point.y){};
|
|
Toshihiro Shimizu |
890ddd |
inline TPointT &operator=(const TPointT &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x = a.x;
|
|
Toshihiro Shimizu |
890ddd |
y = a.y;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TPointT &operator+=(const TPointT &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x += a.x;
|
|
Toshihiro Shimizu |
890ddd |
y += a.y;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
inline TPointT &operator-=(const TPointT &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x -= a.x;
|
|
Toshihiro Shimizu |
890ddd |
y -= a.y;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
inline TPointT operator+(const TPointT &a) const { return TPointT(x + a.x, y + a.y); };
|
|
Toshihiro Shimizu |
890ddd |
inline TPointT operator-(const TPointT &a) const { return TPointT(x - a.x, y - a.y); };
|
|
Toshihiro Shimizu |
890ddd |
inline TPointT operator-() const { return TPointT(-x, -y); };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator!=(const TPointT &p) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x != p.x || y != p.y;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
* Rotate a point 90 degrees (counterclockwise).
|
|
Toshihiro Shimizu |
890ddd |
\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>
|
|
Toshihiro Shimizu |
890ddd |
inline TPointT<t> rotate90(const TPointT<t> &p) // counterclockwise</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPointT<t>(-p.y, p.x);</t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*! \relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
* Rotate a point 270 degrees (clockwise).
|
|
Toshihiro Shimizu |
890ddd |
\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>
|
|
Toshihiro Shimizu |
890ddd |
inline TPointT<t> rotate270(const TPointT<t> &p) // clockwise</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPointT<t>(p.y, -p.x);</t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""> // prodotto scalare</class>
|
|
Toshihiro Shimizu |
890ddd |
inline T operator*(const TPointT<t> &a, const TPointT<t> &b)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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 |
3bfa54 |
inline std::ostream &operator<<(std::ostream &out, const TPointT<t> &p)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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>
|
|
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>
|
|
Toshihiro Shimizu |
890ddd |
inline bool operator==(const TPointT<t> &p0, const TPointT<t> &p1)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return p0.x == p1.x && p0.y == p1.y;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
inline TPoint operator*(int a, const TPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPoint(a * p.x, a * p.y);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
inline TPoint operator*(const TPoint &p, int a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPoint(a * p.x, a * p.y);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
inline TPointD operator*(double a, const TPointD &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPointD(a * p.x, a * p.y);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
inline TPointD operator*(const TPointD &p, double a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPointD(a * p.x, a * p.y);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function returns the square of the absolute value of the specified point (a TPointI)
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline int norm2(const TPointI &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return p.x * p.x + p.y * p.y;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function returns the square of the absolute value of the specified point (a TPointD)
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline double norm2(const TPointD &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return p.x * p.x + p.y * p.y;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function returns the absolute value of the specified point
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline double norm(const TPointD &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
return std::sqrt(norm2(p));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function returns the normalized version of the specified point
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TPointD normalize(const TPointD &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double n = norm(p);
|
|
Toshihiro Shimizu |
890ddd |
assert(n != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
return (1.0 / n) * p;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function converts a TPoint (TPointT<int>) into a TPointD</int>
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TPointD convert(const TPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPointD(p.x, p.y);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function converts a TPointD (TPointT<double>) into a TPoint</double>
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TPoint convert(const TPointD &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPoint(tround(p.x), tround(p.y));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function returns the square of the distance between two points
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline double tdistance2(const TPointD &p1, const TPointD &p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return norm2(p2 - p1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline bool operator==(const TPointD &p0, const TPointD &p1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return tdistance2(p0, p1) < TConsts::epsilon * TConsts::epsilon;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function returns the distance between two points
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline double tdistance(const TPointD &p1, const TPointD &p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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 |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline double cross(const TPointD &a, const TPointD &b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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 |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline int cross(const TPoint &a, const TPoint &b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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 |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline double atan(const TPointD &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return atan2(p.y, p.x);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI T3DPointT
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
T x, y, z;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T3DPointT()
|
|
Toshihiro Shimizu |
890ddd |
: x(0), y(0), z(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T3DPointT(T _x, T _y, T _z)
|
|
Toshihiro Shimizu |
890ddd |
: x(_x), y(_y), z(_z) {}
|
|
Toshihiro Shimizu |
890ddd |
T3DPointT(const TPointT<t> &_p, T _z)</t>
|
|
Toshihiro Shimizu |
890ddd |
: x(_p.x), y(_p.y), z(_z) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T3DPointT(const T3DPointT &_p)
|
|
Toshihiro Shimizu |
890ddd |
: x(_p.x), y(_p.y), z(_p.z) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT &operator=(const T3DPointT &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x = a.x;
|
|
Toshihiro Shimizu |
890ddd |
y = a.y;
|
|
Toshihiro Shimizu |
890ddd |
z = a.z;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT &operator+=(const T3DPointT &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x += a.x;
|
|
Toshihiro Shimizu |
890ddd |
y += a.y;
|
|
Toshihiro Shimizu |
890ddd |
z += a.z;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT &operator-=(const T3DPointT &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x -= a.x;
|
|
Toshihiro Shimizu |
890ddd |
y -= a.y;
|
|
Toshihiro Shimizu |
890ddd |
z -= a.z;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT operator+(const T3DPointT &a) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return T3DPointT(x + a.x, y + a.y, z + a.z);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT operator-(const T3DPointT &a) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return T3DPointT(x - a.x, y - a.y, z - a.z);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT operator-() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return T3DPointT(-x, -y, -z);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator==(const T3DPointT &p) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x == p.x && y == p.y && z == p.z;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator!=(const T3DPointT &p) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x != p.x || y != p.y || z != p.z;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
3bfa54 |
inline std::ostream &operator<<(std::ostream &out, const T3DPointT<t> &p)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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>
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT<t> operator*(T a, const T3DPointT<t> &p)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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>
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT<t> operator*(const T3DPointT<t> &p, T a)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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 |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
This helper function returns the square of the absolute value of the specified point (a TPointI)
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T norm2(const T3DPointT<t> &p)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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>
|
|
Toshihiro Shimizu |
890ddd |
inline T norm(const T3DPointT<t> &p)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
return std::sqrt(norm2(p));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointD normalize(const T3DPointD &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double n = norm(p);
|
|
Toshihiro Shimizu |
890ddd |
assert(n != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
return (1.0 / n) * p;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointD convert(const T3DPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return T3DPointD(p.x, p.y, p.z);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPoint convert(const T3DPointD &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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>
|
|
Toshihiro Shimizu |
890ddd |
inline T tdistance(const T3DPointT<t> &p1, const T3DPointT<t> &p2)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return norm<t>(p2 - p1);</t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T tdistance2(const T3DPointT<t> &p1, const T3DPointT<t> &p2)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return norm2<t>(p2 - p1);</t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T3DPointT<t> cross(const T3DPointT<t> &a, const T3DPointT<t> &b)</t></t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return T3DPointT<t>(a.y * b.z - b.y * a.z,</t>
|
|
Toshihiro Shimizu |
890ddd |
a.z * b.x - b.z * a.x,
|
|
Toshihiro Shimizu |
890ddd |
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 |
*/
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TThickPoint : public TPointD
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
double thick;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint()
|
|
Toshihiro Shimizu |
890ddd |
: TPointD(), thick(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint(double _x, double _y, double _thick = 0)
|
|
Toshihiro Shimizu |
890ddd |
: TPointD(_x, _y), thick(_thick) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint(const TPointD &_p, double _thick = 0)
|
|
Toshihiro Shimizu |
890ddd |
: TPointD(_p.x, _p.y), thick(_thick) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint(const T3DPointD &_p)
|
|
Toshihiro Shimizu |
890ddd |
: TPointD(_p.x, _p.y), thick(_p.z) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint(const TThickPoint &_p)
|
|
Toshihiro Shimizu |
890ddd |
: TPointD(_p.x, _p.y), thick(_p.thick) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint &operator=(const TThickPoint &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x = a.x;
|
|
Toshihiro Shimizu |
890ddd |
y = a.y;
|
|
Toshihiro Shimizu |
890ddd |
thick = a.thick;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint &operator+=(const TThickPoint &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x += a.x;
|
|
Toshihiro Shimizu |
890ddd |
y += a.y;
|
|
Toshihiro Shimizu |
890ddd |
thick += a.thick;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint &operator-=(const TThickPoint &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x -= a.x;
|
|
Toshihiro Shimizu |
890ddd |
y -= a.y;
|
|
Toshihiro Shimizu |
890ddd |
thick -= a.thick;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint operator+(const TThickPoint &a) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TThickPoint(x + a.x, y + a.y, thick + a.thick);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint operator-(const TThickPoint &a) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TThickPoint(x - a.x, y - a.y, thick - a.thick);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint operator-() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TThickPoint(-x, -y, -thick);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator==(const TThickPoint &p) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x == p.x && y == p.y && thick == p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator!=(const TThickPoint &p) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x != p.x || y != p.y || thick != p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline double operator*(const TThickPoint &a, const TThickPoint &b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return a.x * b.x + a.y * b.y + a.thick * b.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint operator*(double a, const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TThickPoint(a * p.x, a * p.y, a * p.thick);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint operator*(const TThickPoint &p, double a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TThickPoint(a * p.x, a * p.y, a * p.thick);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointD
|
|
Toshihiro Shimizu |
890ddd |
This helper function converts a TThickPoint into a TPointD
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TPointD convert(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPointD(p.x, p.y);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TThickPoint
|
|
Toshihiro Shimizu |
890ddd |
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 |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline double tdistance2(const TThickPoint &p1, const TThickPoint &p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return norm2(convert(p2 - p1));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TThickPoint
|
|
Toshihiro Shimizu |
890ddd |
This helper function returns the distance between two thick points
|
|
Toshihiro Shimizu |
890ddd |
(only x and y are used)
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline double tdistance(const TThickPoint &p1, const TThickPoint &p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return norm(convert(p2 - p1));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
inline std::ostream &operator<<(std::ostream &out, const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "(" << p.x << ", " << p.y << ", " << p.thick << ")";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
//! This is a template class representing a generic vector in a plane, i.e. a point.
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
It is a data structure with two objects in it representing coordinate of the point and
|
|
Toshihiro Shimizu |
890ddd |
the basic operations on it.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TDimensionT
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
T lx, ly;
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Constructs a vector of two elements, i.e. a point in a plane.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT() : lx(), ly() {}
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT(T _lx, T _ly) : lx(_lx), ly(_ly) {}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Copy constructor.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT(const TDimensionT &d) : lx(d.lx), ly(d.ly) {}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Vector addition.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT &operator+=(TDimensionT a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
lx += a.lx;
|
|
Toshihiro Shimizu |
890ddd |
ly += a.ly;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Difference of two vectors.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT &operator-=(TDimensionT a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
lx -= a.lx;
|
|
Toshihiro Shimizu |
890ddd |
ly -= a.ly;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Addition of two vectors.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT operator+(TDimensionT a) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT ris(*this);
|
|
Toshihiro Shimizu |
890ddd |
return ris += a;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Vector difference.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT operator-(TDimensionT a) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT ris(*this);
|
|
Toshihiro Shimizu |
890ddd |
return ris -= a;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Compare vectors and returns \e true if are equals element by element.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
bool operator==(const TDimensionT &d) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return lx == d.lx && ly == d.ly;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Compare vectors and returns \e true if are not equals element by element.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
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 |
3bfa54 |
inline std::ostream &operator<<(std::ostream &out, const TDimensionT<t> &p)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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.
|
|
Toshihiro Shimizu |
890ddd |
/*!\arg \a x0 specifies the x-coordinate of the bottom-left corner of a rectangle.
|
|
Toshihiro Shimizu |
890ddd |
\arg \a y0 specifies the y-coordinate of the bottom-left corner of a rectangle.
|
|
Toshihiro Shimizu |
890ddd |
\arg \a x1 specifies the x-coordinate of the upper-right corner of a rectangle.
|
|
Toshihiro Shimizu |
890ddd |
\arg \a y1 specifies the y-coordinate of the upper-right corner of a rectangle.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TRectT
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
/*! if x0>x1 || y0>y1 then rect is empty
|
|
Toshihiro Shimizu |
890ddd |
if x0==y1 && y0==y1 and rect is a TRectD then rect is empty */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T x0, y0;
|
|
Toshihiro Shimizu |
890ddd |
T x1, y1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! makes an empty rect */
|
|
Toshihiro Shimizu |
890ddd |
TRectT();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectT(T _x0, T _y0, T _x1, T _y1)
|
|
Toshihiro Shimizu |
890ddd |
: x0(_x0), y0(_y0), x1(_x1), y1(_y1){};
|
|
Toshihiro Shimizu |
890ddd |
TRectT(const TRectT &rect)
|
|
Toshihiro Shimizu |
890ddd |
: x0(rect.x0), y0(rect.y0), x1(rect.x1), y1(rect.y1){};
|
|
Toshihiro Shimizu |
890ddd |
TRectT(const TPointT<t> &p0, const TPointT<t> &p1) // non importa l'ordine</t></t>
|
|
Toshihiro Shimizu |
890ddd |
: x0(tmin((T)p0.x, (T)p1.x)),
|
|
Toshihiro Shimizu |
890ddd |
y0(tmin((T)p0.y, (T)p1.y)),
|
|
Toshihiro Shimizu |
890ddd |
x1(tmax((T)p0.x, (T)p1.x)),
|
|
Toshihiro Shimizu |
890ddd |
y1(tmax((T)p0.y, (T)p1.y)){};
|
|
Toshihiro Shimizu |
890ddd |
TRectT(const TPointT<t> &bottomLeft, const TDimensionT<t> &d);</t></t>
|
|
Toshihiro Shimizu |
890ddd |
TRectT(const TDimensionT<t> &d);</t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void empty();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! TRectD is empty if and only if (x0>x1 || y0>y1) || (x0==y1 && y0==y1);
|
|
Toshihiro Shimizu |
890ddd |
TRectI is empty if x0>x1 || y0>y1 */
|
|
Toshihiro Shimizu |
890ddd |
bool isEmpty() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T getLx() const;
|
|
Toshihiro Shimizu |
890ddd |
T getLy() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TDimensionT<t> getSize() const</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TDimensionT<t>(getLx(), getLy());</t>
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointT<t> getP00() const { return TPointT<t>(x0, y0); };</t></t>
|
|
Toshihiro Shimizu |
890ddd |
TPointT<t> getP10() const { return TPointT<t>(x1, y0); };</t></t>
|
|
Toshihiro Shimizu |
890ddd |
TPointT<t> getP01() const { return TPointT<t>(x0, y1); };</t></t>
|
|
Toshihiro Shimizu |
890ddd |
TPointT<t> getP11() const { return TPointT<t>(x1, y1); };</t></t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!Returns the union of two source rectangles.
|
|
Toshihiro Shimizu |
890ddd |
/*!The union is the smallest rectangle that contains both source rectangles.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> operator+(const TRectT<t> &rect) const</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{ // unione
|
|
Toshihiro Shimizu |
890ddd |
if (isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
else if (rect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return TRectT<t>(</t>
|
|
Toshihiro Shimizu |
890ddd |
tmin((T)x0, (T)rect.x0), tmin((T)y0, (T)rect.y0),
|
|
Toshihiro Shimizu |
890ddd |
tmax((T)x1, (T)rect.x1), tmax((T)y1, (T)rect.y1));
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> &operator+=(const TRectT<t> &rect)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{ // unione
|
|
Toshihiro Shimizu |
890ddd |
return *this = *this + rect;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> &operator*=(const TRectT<t> &rect)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{ // intersezione
|
|
Toshihiro Shimizu |
890ddd |
return *this = *this * rect;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Returns the intersection of two existing rectangles.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
The intersection is the largest rectangle contained in both existing rectangles.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> operator*(const TRectT<t> &rect) const</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{ // intersezione
|
|
Toshihiro Shimizu |
890ddd |
if (isEmpty() || rect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return TRectT<t>();</t>
|
|
Toshihiro Shimizu |
890ddd |
else if (rect.x1 < x0 || x1 < rect.x0 || rect.y1 < y0 || y1 < rect.y0)
|
|
Toshihiro Shimizu |
890ddd |
return TRectT<t>();</t>
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return TRectT<t>(</t>
|
|
Toshihiro Shimizu |
890ddd |
tmax((T)x0, (T)rect.x0), tmax((T)y0, (T)rect.y0),
|
|
Toshihiro Shimizu |
890ddd |
tmin((T)x1, (T)rect.x1), tmin((T)y1, (T)rect.y1));
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> &operator+=(const TPointT<t> &p)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{ // spostamento
|
|
Toshihiro Shimizu |
890ddd |
x0 += p.x;
|
|
Toshihiro Shimizu |
890ddd |
y0 += p.y;
|
|
Toshihiro Shimizu |
890ddd |
x1 += p.x;
|
|
Toshihiro Shimizu |
890ddd |
y1 += p.y;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> &operator-=(const TPointT<t> &p)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x0 -= p.x;
|
|
Toshihiro Shimizu |
890ddd |
y0 -= p.y;
|
|
Toshihiro Shimizu |
890ddd |
x1 -= p.x;
|
|
Toshihiro Shimizu |
890ddd |
y1 -= p.y;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> operator+(const TPointT<t> &p) const</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> ris(*this);</t>
|
|
Toshihiro Shimizu |
890ddd |
return ris += p;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> operator-(const TPointT<t> &p) const</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> ris(*this);</t>
|
|
Toshihiro Shimizu |
890ddd |
return ris -= p;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator==(const TRectT<t> &r) const</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x0 == r.x0 && y0 == r.y0 && x1 == r.x1 && y1 == r.y1;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator!=(const TRectT<t> &r) const</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x0 != r.x0 || y0 != r.y0 || x1 != r.x1 || y1 != r.y1;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool contains(const TPointT<t> &p) const</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x0 <= p.x && p.x <= x1 && y0 <= p.y && p.y <= y1;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool contains(const TRectT<t> &b) const</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x0 <= b.x0 && x1 >= b.x1 && y0 <= b.y0 && y1 >= b.y1;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool overlaps(const TRectT<t> &b) const</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return x0 <= b.x1 && x1 >= b.x0 &&
|
|
Toshihiro Shimizu |
890ddd |
y0 <= b.y1 && y1 >= b.y0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> enlarge(T dx, T dy) const</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
return TRectT<t>(x0 - dx, y0 - dy, x1 + dx, y1 + dy);</t>
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> enlarge(T d) const { return enlarge(d, d); };</t>
|
|
Toshihiro Shimizu |
890ddd |
TRectT<t> enlarge(TDimensionT<t> d) const</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return enlarge(d.lx, d.ly);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
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
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TRectT
|
|
Toshihiro Shimizu |
890ddd |
Convert a TRectD into a TRect
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TRect convert(const TRectD &r)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TRect(
|
|
Toshihiro Shimizu |
890ddd |
(int)(r.x0 + 0.5), (int)(r.y0 + 0.5),
|
|
Toshihiro Shimizu |
890ddd |
(int)(r.x1 + 0.5), (int)(r.y1 + 0.5));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TRectT
|
|
Toshihiro Shimizu |
890ddd |
Convert a TRect into a TRectD
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TRectD convert(const TRect &r)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TRectD(r.x0, r.y0, r.x1, r.y1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// template?
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TRectT
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TRectD boundingBox(const TPointD &p0, const TPointD &p1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TRectD(tmin(p0.x, p1.x), tmin(p0.y, p1.y),
|
|
Toshihiro Shimizu |
890ddd |
tmax(p0.x, p1.x), tmax(p0.y, p1.y));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TRectT
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TRectD boundingBox(
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p0,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p1,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TRectD(tmin(p0.x, p1.x, p2.x), tmin(p0.y, p1.y, p2.y),
|
|
Toshihiro Shimizu |
890ddd |
tmax(p0.x, p1.x, p2.x), tmax(p0.y, p1.y, p2.y));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\relates TRectT
|
|
Toshihiro Shimizu |
890ddd |
\relates TPointT
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
inline TRectD boundingBox(
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p0,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p1,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p2,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p3)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TRectD(
|
|
Toshihiro Shimizu |
890ddd |
tmin(p0.x, p1.x, p2.x, p3.x),
|
|
Toshihiro Shimizu |
890ddd |
tmin(p0.y, p1.y, p2.y, p3.y),
|
|
Toshihiro Shimizu |
890ddd |
tmax(p0.x, p1.x, p2.x, p3.x),
|
|
Toshihiro Shimizu |
890ddd |
tmax(p0.y, p1.y, p2.y, p3.y));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline TRectT<int>::TRectT() : x0(0), y0(0), x1(-1), y1(-1) {}</int>
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline TRectT<int>::TRectT(const TPointT<int> &bottomLeft, const TDimensionT<int> &d)</int></int></int>
|
|
Toshihiro Shimizu |
890ddd |
: x0(bottomLeft.x), y0(bottomLeft.y), x1(bottomLeft.x + d.lx - 1), y1(bottomLeft.y + d.ly - 1){};
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline TRectT<int>::TRectT(const TDimensionT<int> &d)</int></int>
|
|
Toshihiro Shimizu |
890ddd |
: x0(0), y0(0), x1(d.lx - 1), y1(d.ly - 1){};
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline bool TRectT<int>::isEmpty() const { return x0 > x1 || y0 > y1; }</int>
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline void TRectT<int>::empty()</int>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x0 = y0 = 0;
|
|
Toshihiro Shimizu |
890ddd |
x1 = y1 = -1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline int TRectT<int>::getLx() const { return x1 >= x0 ? x1 - x0 + 1 : 0; }</int>
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline int TRectT<int>::getLy() const { return y1 >= y0 ? y1 - y0 + 1 : 0; }</int>
|
|
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 <>
|
|
Toshihiro Shimizu |
890ddd |
inline TRectT<double>::TRectT(const TPointT<double> &bottomLeft, const TDimensionT<double> &d)</double></double></double>
|
|
Toshihiro Shimizu |
890ddd |
: x0(bottomLeft.x), y0(bottomLeft.y), x1(bottomLeft.x + d.lx), y1(bottomLeft.y + d.ly){};
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline TRectT<double>::TRectT(const TDimensionT<double> &d)</double></double>
|
|
Toshihiro Shimizu |
890ddd |
: x0(0.0), y0(0.0), x1(d.lx), y1(d.ly){};
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Michał Janiszewski |
b1cc3c |
inline bool TRectT<double>::isEmpty() const { return (x0 == x1 && y0 == y1) || x0 > x1 || y0 > y1; }</double>
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline void TRectT<double>::empty() { x0 = y0 = x1 = y1 = 0; }</double>
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline double TRectT<double>::getLx() const { return x1 >= x0 ? x1 - x0 : 0; }</double>
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
inline double TRectT<double>::getLy() const { return y1 >= y0 ? y1 - y0 : 0; }</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TRectD &operator*=(TRectD &rect, double factor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
rect.x0 *= factor;
|
|
Toshihiro Shimizu |
890ddd |
rect.y0 *= factor;
|
|
Toshihiro Shimizu |
890ddd |
rect.x1 *= factor;
|
|
Toshihiro Shimizu |
890ddd |
rect.y1 *= factor;
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TRectD operator*(const TRectD &rect, double factor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRectD result(rect);
|
|
Toshihiro Shimizu |
890ddd |
return result *= factor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TRectD &operator/=(TRectD &rect, double factor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(factor != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
return rect *= (1.0 / factor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TRectD operator/(const TRectD &rect, double factor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(factor != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
TRectD result(rect);
|
|
Toshihiro Shimizu |
890ddd |
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 |
3bfa54 |
inline std::ostream &operator<<(std::ostream &out, const TRectT<t> &r)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "(" << r.x0 << "," << r.y0
|
|
Toshihiro Shimizu |
890ddd |
<< ";" << r.x1 << "," << r.y1 << ")";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace TConsts
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
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 |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
//!This is the base class for the affine transformations.
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
This class performs basic manipulations of affine transformations.
|
|
Toshihiro Shimizu |
890ddd |
An affine transformation is a linear transformation followed by a translation.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\f$ x \mapsto \bf{A} x + b \f$
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\f$ \bf{A} \f$ is a \f$ 2X2 \f$ matrix.
|
|
Toshihiro Shimizu |
890ddd |
In a matrix notation:
|
|
Toshihiro Shimizu |
890ddd |
\f$ \left(\begin{array}{c} \vec{y} \\ 1 \end{array}\right) =
|
|
Toshihiro Shimizu |
890ddd |
\left( \begin{array}{cc} \bf{A} & \vec{b} \\ \vec{0} & 1 \end{array}\right)
|
|
Toshihiro Shimizu |
890ddd |
\left(\begin{array}{c}\vec{x} \\ 1 \end{array} \right) \f$
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TAffine
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
double a11, a12, a13;
|
|
Toshihiro Shimizu |
890ddd |
double a21, a22, a23;
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
By default the object is initialized with a null matrix and a null translation vector.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TAffine() : a11(1.0), a12(0.0), a13(0.0),
|
|
Toshihiro Shimizu |
890ddd |
a21(0.0), a22(1.0), a23(0.0){};
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Initializes the internal matrix and vector of translation with the user values.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TAffine(
|
|
Toshihiro Shimizu |
890ddd |
double p11, double p12, double p13,
|
|
Toshihiro Shimizu |
890ddd |
double p21, double p22, double p23) : a11(p11), a12(p12), a13(p13),
|
|
Toshihiro Shimizu |
890ddd |
a21(p21), a22(p22), a23(p23){};
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Copy constructor.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TAffine(const TAffine &a) : a11(a.a11), a12(a.a12), a13(a.a13),
|
|
Toshihiro Shimizu |
890ddd |
a21(a.a21), a22(a.a22), a23(a.a23){};
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Assignment operator.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TAffine &operator=(const TAffine &a);
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
a11 = a.a11; a12 = a.a12; a13 = a.a13;
|
|
Toshihiro Shimizu |
890ddd |
a21 = a.a21; a22 = a.a22; a23 = a.a23;
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Matrix multiplication.
|
|
Toshihiro Shimizu |
890ddd |
\f$\left(\begin{array}{cc}\bf{A}&\vec{a}\\\vec{0}&1\end{array}\right)
|
|
Toshihiro Shimizu |
890ddd |
\left(\begin{array}{cc}\bf{B}&\vec{b}\\\vec{0}&1\end{array}\right)\f$
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TAffine operator*(const TAffine &b) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TAffine (
|
|
Toshihiro Shimizu |
890ddd |
a11 * b.a11 + a12 * b.a21,
|
|
Toshihiro Shimizu |
890ddd |
a11 * b.a12 + a12 * b.a22,
|
|
Toshihiro Shimizu |
890ddd |
a11 * b.a13 + a12 * b.a23 + a13,
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
a21 * b.a11 + a22 * b.a21,
|
|
Toshihiro Shimizu |
890ddd |
a21 * b.a12 + a22 * b.a22,
|
|
Toshihiro Shimizu |
890ddd |
a21 * b.a13 + a22 * b.a23 + a23);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TAffine operator*=(const TAffine &b);
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return *this = *this * b;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Retruns the inverse tansformation as:
|
|
Toshihiro Shimizu |
890ddd |
\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 |
|
|
Toshihiro Shimizu |
890ddd |
TAffine inv() const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if(a12 == 0.0 && a21 == 0.0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(a11 != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
assert(a22 != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
double inv_a11 = 1.0/a11;
|
|
Toshihiro Shimizu |
890ddd |
double inv_a22 = 1.0/a22;
|
|
Toshihiro Shimizu |
890ddd |
return TAffine(inv_a11,0, -a13 * inv_a11,
|
|
Toshihiro Shimizu |
890ddd |
0,inv_a22, -a23 * inv_a22);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else if(a11 == 0.0 && a22 == 0.0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(a12 != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
assert(a21 != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
double inv_a21 = 1.0/a21;
|
|
Toshihiro Shimizu |
890ddd |
double inv_a12 = 1.0/a12;
|
|
Toshihiro Shimizu |
890ddd |
return TAffine(0, inv_a21, -a23 * inv_a21,
|
|
Toshihiro Shimizu |
890ddd |
inv_a12, 0, -a13 * inv_a12);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double d = 1./det();
|
|
Toshihiro Shimizu |
890ddd |
return TAffine(a22*d,-a12*d, (a12*a23-a22*a13)*d,
|
|
Toshihiro Shimizu |
890ddd |
-a21*d, a11*d, (a21*a13-a11*a23)*d);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double det() const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp{
|
|
Toshihiro Shimizu |
890ddd |
return a11*a22-a12*a21;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Returns \e true if all elements are equals.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
bool operator==(const TAffine &a) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return a11==a.a11 && a12==a.a12 && a13==a.a13 &&
|
|
Toshihiro Shimizu |
890ddd |
a21==a.a21 && a22==a.a22 && a23==a.a23;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Returns \e true if at least one element is different.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator!=(const TAffine &a) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return a11!=a.a11 || a12!=a.a12 || a13!=a.a13 ||
|
|
Toshihiro Shimizu |
890ddd |
a21!=a.a21 || a22!=a.a22 || a23!=a.a23;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Returns \e true if the transformation is an identity,
|
|
Toshihiro Shimizu |
890ddd |
i.e in the error limit \e err leaves the vectors unchanged.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isIdentity(double err = 1.e-8) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return ((a11-1.0)*(a11-1.0)+(a22-1.0)*(a22-1.0)+
|
|
Toshihiro Shimizu |
890ddd |
a12*a12+a13*a13+a21*a21+a23*a23) < err;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Returns \e true if in the error limits \e err \f$\bf{A}\f$ is the identity matrix.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isTranslation(double err = 1.e-8) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return ((a11-1.0)*(a11-1.0)+(a22-1.0)*(a22-1.0)+
|
|
Toshihiro Shimizu |
890ddd |
a12*a12+a21*a21) < err;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Returns \e true if in the error limits the matrix \f$\bf{A}\f$ is of the form:
|
|
Toshihiro Shimizu |
890ddd |
\f$\left(\begin{array}{cc}a&b\\-b&a\end{array}\right)\f$ .
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isIsotropic(double err = 1.e-8) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return areAlmostEqual(a11, a22, err) && areAlmostEqual(a12, -a21, err);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Retruns the transfomed point.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TPointD operator*(const TPointD &p) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TPointD(p.x*a11+p.y*a12+a13, p.x*a21+p.y*a22+a23);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Retruns the transformed box of the bounding box.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TRectD operator*(const TRectD &rect) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (rect != TConsts::infiniteRectD)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPointD p1= *this * rect.getP00(),
|
|
Toshihiro Shimizu |
890ddd |
p2= *this * rect.getP01(),
|
|
Toshihiro Shimizu |
890ddd |
p3= *this * rect.getP10(),
|
|
Toshihiro Shimizu |
890ddd |
p4= *this * rect.getP11();
|
|
Toshihiro Shimizu |
890ddd |
return TRectD(tmin(p1.x,p2.x,p3.x,p4.x), tmin(p1.y,p2.y,p3.y,p4.y),
|
|
Toshihiro Shimizu |
890ddd |
tmax(p1.x,p2.x,p3.x,p4.x), tmax(p1.y,p2.y,p3.y,p4.y));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return TConsts::infiniteRectD;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Returns a translated matrix that change the vector (u,v) in (x,y).
|
|
Toshihiro Shimizu |
890ddd |
\n It returns a matrix of the form:
|
|
Toshihiro Shimizu |
890ddd |
\f$\left(\begin{array}{ccc}\bf{A}&\vec{x}-\bf{A} \vec{u}\\
|
|
Toshihiro Shimizu |
890ddd |
\vec{0}&1\end{array}\right)\f$
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TAffine place(double u, double v, double x, double y) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TAffine(a11, a12, x - (a11 * u + a12 * v),
|
|
Toshihiro Shimizu |
890ddd |
a21, a22, y - (a21 * u + a22 * v));
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
See above.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TAffine place(const TPointD &pIn, const TPointD &pOut) const;
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TAffine(a11, a12, pOut.x - (a11 * pIn.x + a12 * pIn.y),
|
|
Toshihiro Shimizu |
890ddd |
a21, a22, pOut.y - (a21 * pIn.x + a22 * pIn.y));
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//template <>
|
|
Toshihiro Shimizu |
890ddd |
inline bool areAlmostEqual(const TPointD &a, const TPointD &b, double err = TConsts::epsilon)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return tdistance2(a, b) < err * err;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//template <>
|
|
Toshihiro Shimizu |
890ddd |
inline bool areAlmostEqual(const TRectD &a, const TRectD &b, double err = TConsts::epsilon)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return areAlmostEqual(a.getP00(), b.getP00(), err) &&
|
|
Toshihiro Shimizu |
890ddd |
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 |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TTranslation : public TAffine
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TTranslation(){};
|
|
Toshihiro Shimizu |
890ddd |
TTranslation(double x, double y) : TAffine(1, 0, x, 0, 1, y){};
|
|
Toshihiro Shimizu |
890ddd |
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 |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TRotation : public TAffine
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TRotation(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! makes a rotation matrix of "degrees" degrees counterclockwise
|
|
Toshihiro Shimizu |
890ddd |
on the origin */
|
|
Toshihiro Shimizu |
890ddd |
TRotation(double degrees);
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double rad, sn, cs;
|
|
Toshihiro Shimizu |
890ddd |
int idegrees = (int)degrees;
|
|
Toshihiro Shimizu |
890ddd |
if ((double)idegrees == degrees && idegrees % 90 == 0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
switch ((idegrees / 90) & 3)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
case 0: sn = 0; cs = 1; break;
|
|
Toshihiro Shimizu |
890ddd |
case 1: sn = 1; cs = 0; break;
|
|
Toshihiro Shimizu |
890ddd |
case 2: sn = 0; cs = -1; break;
|
|
Toshihiro Shimizu |
890ddd |
case 3: sn = -1; cs = 0; break;
|
|
Toshihiro Shimizu |
890ddd |
default: sn = 0; cs = 0; break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
rad = degrees * (TConsts::pi_180);
|
|
Toshihiro Shimizu |
890ddd |
sn = sin (rad);
|
|
Toshihiro Shimizu |
890ddd |
cs = cos (rad);
|
|
Toshihiro Shimizu |
890ddd |
if (sn == 1 || sn == -1)
|
|
Toshihiro Shimizu |
890ddd |
cs = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (cs == 1 || cs == -1)
|
|
Toshihiro Shimizu |
890ddd |
sn = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
a11=cs;a12= -sn;a21= -a12;a22=a11;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! makes a rotation matrix of "degrees" degrees counterclockwise
|
|
Toshihiro Shimizu |
890ddd |
on the given center */
|
|
Toshihiro Shimizu |
890ddd |
TRotation(const TPointD ¢er, double degrees);
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TAffine a = TTranslation(center) * TRotation(degrees) * TTranslation(-center);
|
|
Toshihiro Shimizu |
890ddd |
a11 = a.a11; a12 = a.a12; a13 = a.a13;
|
|
Toshihiro Shimizu |
890ddd |
a21 = a.a21; a22 = a.a22; a23 = a.a23;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TScale : public TAffine
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TScale(){};
|
|
Toshihiro Shimizu |
890ddd |
TScale(double sx, double sy) : TAffine(sx, 0, 0, 0, sy, 0){};
|
|
Toshihiro Shimizu |
890ddd |
TScale(double s) : TAffine(s, 0, 0, 0, s, 0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TScale(const TPointD ¢er, double sx, double sy);
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TAffine a = TTranslation(center) * TScale(sx,sy) * TTranslation(-center);
|
|
Toshihiro Shimizu |
890ddd |
a11 = a.a11; a12 = a.a12; a13 = a.a13;
|
|
Toshihiro Shimizu |
890ddd |
a21 = a.a21; a22 = a.a22; a23 = a.a23;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TScale(const TPointD ¢er, double s);
|
|
Toshihiro Shimizu |
890ddd |
/*Sposto in tgeometry.cpp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TAffine a = TTranslation(center) * TScale(s) * TTranslation(-center);
|
|
Toshihiro Shimizu |
890ddd |
a11 = a.a11; a12 = a.a12; a13 = a.a13;
|
|
Toshihiro Shimizu |
890ddd |
a21 = a.a21; a22 = a.a22; a23 = a.a23;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TShear : public TAffine
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TShear(){};
|
|
Toshihiro Shimizu |
890ddd |
TShear(double sx, double sy) : TAffine(1, sx, 0, sy, 1, 0){};
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline bool areEquals(const TAffine &a,
|
|
Toshihiro Shimizu |
890ddd |
const TAffine &b,
|
|
Toshihiro Shimizu |
890ddd |
double err = 1e-8)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return fabs(a.a11 - b.a11) < err &&
|
|
Toshihiro Shimizu |
890ddd |
fabs(a.a12 - b.a12) < err &&
|
|
Toshihiro Shimizu |
890ddd |
fabs(a.a13 - b.a13) < err &&
|
|
Toshihiro Shimizu |
890ddd |
fabs(a.a21 - b.a21) < err &&
|
|
Toshihiro Shimizu |
890ddd |
fabs(a.a22 - b.a22) < err &&
|
|
Toshihiro Shimizu |
890ddd |
fabs(a.a23 - b.a23) < err;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TAffine inv(const TAffine &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return a.inv();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
inline std::ostream &operator<<(std::ostream &out, const TAffine &a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "(" << a.a11 << ", " << a.a12 << ", " << a.a13
|
|
Toshihiro Shimizu |
890ddd |
<< ";" << a.a21 << ", " << a.a22 << ", " << a.a23 << ")";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif // __T_GEOMETRY_INCLUDED__
|