tahoma2d/toonz/sources/include/tcg/point.h

68 lines
1.8 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TCG_POINT_H
#define TCG_POINT_H
//*************************************************************
// tcg Generic Point Class
//*************************************************************
2016-06-15 18:43:10 +12:00
namespace tcg {
2016-03-19 06:57:51 +13:00
/*!
2016-06-15 18:43:10 +12:00
The Point class models a point in a bidimensional vector space. It has 2
members,
2016-03-19 06:57:51 +13:00
x and y, representing its coordinates, and a constructor prototype:
Point_class(const value_type& x, const value_type& y);
*/
template <typename T>
struct PointT {
2016-06-15 18:43:10 +12:00
typedef T value_type;
value_type x, y;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PointT() : x(0), y(0) {}
PointT(const value_type &x_, const value_type &y_) : x(x_), y(y_) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool operator==(const PointT &other) const {
return (x == other.x) && (y == other.y);
}
bool operator!=(const PointT &other) const { return !operator==(other); }
2016-03-19 06:57:51 +13:00
};
//******************************************************************************
// Common typedefs
//******************************************************************************
typedef PointT<int> Point;
typedef PointT<int> PointI;
typedef PointT<double> PointD;
//*************************************************************
// tcg Generic Point Traits
//*************************************************************
template <typename P>
struct point_traits {
2016-06-15 18:43:10 +12:00
typedef P point_type;
typedef typename P::value_type value_type;
typedef typename P::value_type float_type;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
inline static value_type x(const point_type &p) { return p.x; }
inline static value_type y(const point_type &p) { return p.y; }
2016-03-19 06:57:51 +13:00
};
template <>
struct point_traits<PointI> {
2016-06-15 18:43:10 +12:00
typedef PointI point_type;
typedef PointI::value_type value_type;
typedef double float_type;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
inline static value_type x(const point_type &p) { return p.x; }
inline static value_type y(const point_type &p) { return p.y; }
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
} // namespace tcg
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
#endif // TCG_POINT_H