// ====================================================================== // // Copyright (c) 2000 The CGAL Consortium // // This software and related documentation is part of an INTERNAL release // of the Computational Geometry Algorithms Library (CGAL). It is not // intended for general use. // // ---------------------------------------------------------------------- // // release : // release_date : // // file : include/CGAL/Cartesian/Point_d.C // revision : $Revision$ // revision_date : $Date$ // author(s) : Herve Bronnimann // coordinator : INRIA Sophia-Antipolis (Mariette.Yvinec@sophia.inria.fr) // // ====================================================================== #ifndef CGAL_CARTESIAN_POINT_D_C #define CGAL_CARTESIAN_POINT_D_C #include #include #include #ifndef CGAL_CTAG #define CGAL_CTAG #endif #ifdef CGAL_CFG_TYPENAME_BUG #define typename #endif CGAL_BEGIN_NAMESPACE template < class R > PointCd::PointCd(int dim) { PTR = new _d_tuple(dim); } template < class R > PointCd:: PointCd(const PointCd &p) : Handle(p) {} template < class R > inline PointCd:: PointCd(const typename PointCd::Vector_d &v) : Handle((const Handle&)v) { } template < class R > CGAL_KERNEL_INLINE PointCd:: PointCd(int dim, const Origin &) { CGAL_kernel_precondition (dim>=0); PTR = new _d_tuple(dim); std::fill(begin(), end(), FT(0)); } template < class R > inline PointCd::~PointCd() {} template < class R > inline PointCd & PointCd::operator=(const PointCd &p) { Handle::operator=(p); return *this; } template < class R > inline bool PointCd::operator==(const PointCd& p) const { if (dimension() != p.dimension()) return false; if (ptr() == p.ptr()) return true; // identical return std::equal(begin(),end(),p.begin()); } template < class R > inline bool PointCd::operator!=(const PointCd& p) const { return !(*this == p); } template < class R > inline bool PointCd::operator==(const Origin&) const { const_iterator non_zero = find_if(begin(),end(), bind1st(not_equal_to(),FT(0))); return non_zero == end(); } template < class R > inline bool PointCd::operator!=(const Origin&) const { return !(*this == p); } template < class R > inline long PointCd::id() const { return (long)PTR; } template < class R > CGAL_KERNEL_INLINE typename PointCd::FT PointCd::cartesian(int i) const { CGAL_kernel_precondition ( (i>=0) && (i inline typename PointCd::FT PointCd::homogeneous(int i) const { CGAL_kernel_precondition ( (i>=0) && (i<=dimension()) ); return (i==dimension()) ? FT(1) : cartesian(i); } template < class R > inline typename PointCd::FT PointCd::operator[](int i) const { return cartesian(i); } template < class R > inline PointCd PointCd:: transform(const PointCd::Aff_transformation_d &t) const { return t.transform(*this); } #ifndef NO_OSTREAM_INSERT_POINTCD template < class R > std::ostream& operator<<(std::ostream& os, const PointCd &p) { typedef typename R::FT FT; print_d prt(&os); if (os.iword(IO::mode)==IO::PRETTY) os << "PointCd("; prt(p.dimension()); if (os.iword(IO::mode)==IO::PRETTY) { os << ", ("; prt.reset(); } std::for_each(p.begin(),p.end(),prt); if (os.iword(IO::mode)==IO::PRETTY) os << "))"; return os; } #endif // NO_OSTREAM_INSERT_POINTCD #ifndef NO_ISTREAM_EXTRACT_POINTCD template < class R > std::istream& operator>>(std::istream& is, PointCd &p) { int d=0, i; typedef typename PointCd::FT FT; FT *e=0; switch(is.iword(IO::mode)) { case IO::ASCII : is >> d; e = new FT[d]; for (i=0; i < d; ++i) { is >> e[i]; } break; case IO::BINARY : read(is, d); e = new FT[d]; for (i=0; i(d, e, e+d); delete[] e; return is; } #endif // NO_ISTREAM_EXTRACT_POINTCD CGAL_END_NAMESPACE #ifdef CGAL_CFG_TYPENAME_BUG #undef typename #endif #endif // CGAL_CARTESIAN_POINT_D_C