// ====================================================================== // // Copyright (c) 1999 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 : PointHd.h // package : _d // revision : $Revision$ // revision_date : $Date$ // author(s) : Sven Schoenherr // Bernd Gaertner // // coordinator : MPI, Saarbruecken () // ====================================================================== #ifndef CGAL_POINTHD_H #define CGAL_POINTHD_H #include CGAL_BEGIN_NAMESPACE template < class FT, class RT> class DAHd; template < class FT, class RT > class PointHd : public Handle { friend class DAHd; public: PointHd (); PointHd (int dim, const Origin&); PointHd (const PointHd &p); template PointHd (int dim, InputIterator first, InputIterator last) { CGAL_kernel_precondition( dim >= 0 ); PTR = new _d_tuple( dim, false); RT* o; RT* e = ptr()->e; InputIterator i; for (i = first, o = e; ( i < last )&&( o < e+dim ); *(o++) = *(i++) ) {}; CGAL_kernel_precondition ( o == e+dim ); if (i < last) { RT h = *(i++); CGAL_kernel_precondition( !CGAL_NTS is_zero (h) ); CGAL_kernel_precondition( i == last ); *o = h; } else { *o = RT(1); } } ~PointHd(); PointHd& operator=(const PointHd &p); bool operator==(const PointHd &p) const; bool operator!=(const PointHd &p) const; int id() const; RT homogeneous (int i) const; FT cartesian (int i) const; FT operator[] (int i) const; const RT* begin() const; const RT* end() const; int dimension () const; private: const _d_tuple* ptr() const; }; template < class FT, class RT > CGAL_KERNEL_INLINE const _d_tuple* PointHd::ptr() const { return (_d_tuple*)PTR; } CGAL_END_NAMESPACE #include #include CGAL_BEGIN_NAMESPACE template < class FT, class RT > CGAL_KERNEL_INLINE PointHd::PointHd() { PTR = new _d_tuple(); } template < class FT, class RT > CGAL_KERNEL_INLINE PointHd::PointHd(int dim, const Origin &) { CGAL_kernel_precondition( dim >= 0); PTR = new _d_tuple(dim,false); RT* e = ptr()->e; FT* i; for (i=e; i CGAL_KERNEL_INLINE PointHd::PointHd(const PointHd &p) : Handle((Handle&)p) {} template < class FT, class RT > inline PointHd::~PointHd() {} template < class FT, class RT > inline PointHd& PointHd::operator=(const PointHd &p) { Handle::operator=(p); return *this; } template < class FT, class RT > inline bool PointHd::operator==(const PointHd& p) const { int d = dimension(); if (d != p.dimension()) return false; RT* e = ptr()->e; RT* ep = p.ptr()->e; RT h = e[d], hp = ep[d]; RT* i; RT* j; for ( i=e, j=ep; i inline bool PointHd::operator!=(const PointHd& p) const { return !(*this == p); } template < class FT, class RT > inline int PointHd::id() const { return (int)PTR; } template < class FT, class RT > inline RT PointHd::homogeneous(int i) const { CGAL_kernel_precondition ( (i>=0) && (i<=dimension()) ); return ptr()->e[i]; } template < class FT, class RT > CGAL_KERNEL_INLINE FT PointHd::cartesian(int i) const { CGAL_kernel_precondition ( (i>=0) && (ie[i])/FT(ptr()->e[dimension()]); } template < class FT, class RT > inline FT PointHd::operator[](int i) const { return cartesian(i); } template < class FT, class RT > inline int PointHd::dimension() const { return ptr()->d; } template < class FT, class RT > inline const RT* PointHd::begin() const { return ptr()->e; } template < class FT, class RT > inline const RT* PointHd::end() const { return ptr()->e + dimension() + 1; } #ifndef CGAL_NO_OSTREAM_INSERT_POINTHD template < class FT, class RT > std::ostream& operator<<(std::ostream& os, const PointHd& p) { int d = p.dimension(); int i; switch(os.iword(IO::mode)) { case IO::ASCII : os << d << ' '; for (i=0; i std::istream& operator>>(std::istream& is, PointHd &p) { int d=0, i; RT* e; switch(is.iword(IO::mode)) { case IO::ASCII : is >> d; e = new RT[d+1]; for (i=0; i> e[i]; } break; case IO::BINARY : read(is, d); e = new RT[d+1]; for (i=0; i( d, e, e+d+1); delete[] e; return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_POINTHD CGAL_END_NAMESPACE #endif // CGAL_POINTHD_H