// ============================================================================ // // 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 : // // source : ddim_points.fw // file : include/CGAL/PointCd.h // revision : 2.2.3 // revision_date : 14 Sep 1999 // author(s) : Sven Schoenherr, Bernd Gaertner // coordinator : INRIA, Sophia-Antipolis (Mariette.Yvinec@sophia.inria.fr) // // ============================================================================ #ifndef CGAL_POINTCD_H #define CGAL_POINTCD_H #include CGAL_BEGIN_NAMESPACE template < class FT > class DACd; template < class FT > class PointCd : public Handle { friend class DACd; public: PointCd (); PointCd (int dim, const Origin&); PointCd (const PointCd &p); template PointCd (int dim, InputIterator first, InputIterator last) { CGAL_kernel_precondition( dim >= 0); PTR = new _d_tuple(dim); FT* o; FT* 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 ) { FT h = *(i++); CGAL_kernel_precondition( !CGAL_NTS is_zero (h) ); CGAL_kernel_precondition( i == last ); for ( o=e; o < e+dim; *(o++) /= h ) ; // if ( h != FT(1) ) { for ( o=e; o < e+dim; *(o++) /= h ) {}; } } } ~PointCd(); PointCd &operator=(const PointCd &p); bool operator==(const PointCd &p) const; bool operator!=(const PointCd &p) const; unsigned long id() const; FT homogeneous (int i) const; FT cartesian (int i) const; FT operator[] (int i) const; const FT* begin() const; const FT* end() const; int dimension () const; private: const _d_tuple* ptr() const; }; template < class FT > CGAL_KERNEL_INLINE const _d_tuple* PointCd::ptr() const { return static_cast<_d_tuple*>(PTR); } CGAL_END_NAMESPACE #include #include CGAL_BEGIN_NAMESPACE template < class FT > CGAL_KERNEL_INLINE PointCd::PointCd() { PTR = new _d_tuple(); } template < class FT > CGAL_KERNEL_INLINE PointCd::PointCd(int dim, const Origin &) { CGAL_kernel_precondition (dim>=0); PTR = new _d_tuple(dim); FT *e = ptr()->e, *i; for (i=e; i CGAL_KERNEL_INLINE PointCd::PointCd(const PointCd &p) : Handle(static_cast(p)) {} template < class FT > inline PointCd::~PointCd() {} template < class FT > inline PointCd &PointCd::operator=(const PointCd &p) { Handle::operator=(p); return *this; } template < class FT > inline bool PointCd::operator==(const PointCd& p) const { int d = dimension(); if (d != p.dimension()) return false; FT *e = ptr()->e, *ep = p.ptr()->e; FT *i, *j; for (i=e, j=ep; i inline bool PointCd::operator!=(const PointCd& p) const { return !(*this == p); } template < class FT > inline unsigned long PointCd::id() const { return reinterpret_cast(PTR); } template < class FT > inline FT PointCd::homogeneous(int i) const { CGAL_kernel_precondition ( (i>=0) && (i<=dimension()) ); if (ie[i]; else return FT(1); } template < class FT > CGAL_KERNEL_INLINE FT PointCd::cartesian(int i) const { CGAL_kernel_precondition ( (i>=0) && (ie[i]; } template < class FT > inline FT PointCd::operator[](int i) const { return cartesian(i); } template < class FT > inline int PointCd::dimension() const { return ptr()->d; } template < class FT > inline const FT* PointCd::begin() const { return ptr()->e; } template < class FT > inline const FT* PointCd::end() const { return ptr()->e + dimension(); } #ifndef CGAL_NO_OSTREAM_INSERT_POINTCD template < class FT > std::ostream& operator<<(std::ostream& os, const PointCd &p) { int d = p.dimension(), i; switch(os.iword(IO::mode)) { case IO::ASCII : os << d << ' '; for (i=0; i std::istream& operator>>(std::istream& is, PointCd &p) { int d=0, i; FT* e; 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 // CGAL_NO_ISTREAM_EXTRACT_POINTCD CGAL_END_NAMESPACE #endif // CGAL_POINTCD_H