// (c) Copyright 2010 Terry Golubiewski, all rights reserved. #ifndef CARTESIAN_POINT_H #define CARTESIAN_POINT_H #pragma once #include namespace cartesian { template class point { public: typedef Ref ref; static const int dim = Dim; typedef Rep rep; typedef vector vector_type; private: vector_type v_; public: point(uninitialized_t) { } point() : v_() { } point(const point& p) : v_(p.v_) { } point& operator=(const point& p) { v_ = p.v_; return *this; } explicit point(const vector_type& v) : v_(v) { } template explicit point(const vector& v) { v_ = v; } const vector_type& from_origin() const { return v_; } template point(const point& p) : v_(p.from_origin()) { } template point& operator=(const point& p) { v_ = p.from_origin(); return *this; } template point(InIter first_, InIter last_) : v_(first_, last_) { } template const rep& get() const { return v_.get(); } template rep& get() { return v_.get(); } template void set(rep v) { v_.set(v); } rep& operator[](int i) { return v_[i]; } const rep& operator[](int i) const { return v_[i]; } template point& operator+=(const vector& v) { v_ += v; return *this; } template point& operator-=(const vector& v) { v_ -= v; return *this; } }; // point template inline bool operator==(const point& lhs, const point& rhs) { return (lhs.from_origin() == rhs.from_origin()); } template inline bool operator!=(const point& lhs, const point& rhs) { return !(lhs == rhs); } template inline vector::type> operator-(const point& lhs, const point& rhs) { return lhs.from_origin() - rhs.from_origin(); } template inline point::type, Ref> operator+(const point& lhs, const vector& rhs) { point::type, Ref> rval(lhs); return rval += rhs; } template inline point::type, Ref> operator+(const vector& lhs, const point& rhs) { return rhs + lhs; } class point2d: public point<2, double, void> { public: point2d(double x_, double y_) : point<2, double, void>(make_vector(x_, y_)) { } template point2d(point<2, U, void> p) : point<2, double, void>(p) { } double& x() { return get<0>(); } double& y() { return get<1>(); } const double& x() const { return get<0>(); } const double& y() const { return get<1>(); } }; // point2d class point3d: public point<3, double, void> { public: point3d(double x_, double y_, double z_=0) : point<3, double, void>(make_vector(x_, y_, z_)) { } template point3d(point<3, U, void> p) : point<3, double, void>(p) { } double& x() { return get<0>(); } double& y() { return get<1>(); } double& z() { return get<2>(); } const double& x() const { return get<0>(); } const double& y() const { return get<1>(); } const double& z() const { return get<2>(); } }; // point3d } // cartesian #endif