Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TCG_POINT_H
Toshihiro Shimizu 890ddd
#define TCG_POINT_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*************************************************************
Toshihiro Shimizu 890ddd
//    tcg Generic Point Class
Toshihiro Shimizu 890ddd
//*************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace tcg {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
  The Point class models a point in a bidimensional vector space. It has 2
Shinya Kitaoka 120a6e
  members,
Toshihiro Shimizu 890ddd
  x and y, representing its coordinates, and a constructor prototype:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
    Point_class(const value_type& x, const value_type& y);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
struct PointT {
Shinya Kitaoka 120a6e
  typedef T value_type;
Shinya Kitaoka 120a6e
  value_type x, y;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  PointT() : x(0), y(0) {}
Shinya Kitaoka 120a6e
  PointT(const value_type &x_, const value_type &y_) : x(x_), y(y_) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool operator==(const PointT &other) const {
Shinya Kitaoka 120a6e
    return (x == other.x) && (y == other.y);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  bool operator!=(const PointT &other) const { return !operator==(other); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
//    Common typedefs
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef PointT<int> Point;</int>
Toshihiro Shimizu 890ddd
typedef PointT<int> PointI;</int>
Toshihiro Shimizu 890ddd
typedef PointT<double> PointD;</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*************************************************************
Toshihiro Shimizu 890ddd
//    tcg Generic Point Traits
Toshihiro Shimizu 890ddd
//*************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename p=""></typename>
Toshihiro Shimizu 890ddd
struct point_traits {
Shinya Kitaoka 120a6e
  typedef P point_type;
Shinya Kitaoka 120a6e
  typedef typename P::value_type value_type;
Shinya Kitaoka 120a6e
  typedef typename P::value_type float_type;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  inline static value_type x(const point_type &p) { return p.x; }
Shinya Kitaoka 120a6e
  inline static value_type y(const point_type &p) { return p.y; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
struct point_traits<pointi> {</pointi>
Shinya Kitaoka 120a6e
  typedef PointI point_type;
Shinya Kitaoka 120a6e
  typedef PointI::value_type value_type;
Shinya Kitaoka 120a6e
  typedef double float_type;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  inline static value_type x(const point_type &p) { return p.x; }
Shinya Kitaoka 120a6e
  inline static value_type y(const point_type &p) { return p.y; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace tcg
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // TCG_POINT_H