// ====================================================================== // // 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/Simplex_d.C // revision : $Revision$ // revision_date : $Date$ // author(s) : Hervé Brönnimann // coordinator : INRIA Sophia-Antipolis (Mariette.Yvinec@sophia.inria.fr) // // ====================================================================== #ifndef CGAL_CARTESIAN_REDEFINE_NAMES_D_H #define CGAL_CTAG #endif #ifdef CGAL_CFG_TYPENAME_BUG #define typename #endif #ifndef CGAL_CARTESIAN_SIMPLEX_D_C #define CGAL_CARTESIAN_SIMPLEX_D_C #include #include #include #include CGAL_BEGIN_NAMESPACE template < class R > SimplexCd:: SimplexCd() { PTR = new _d_tuple< Point_d >; } template < class R > SimplexCd:: SimplexCd(const SimplexCd &t) : Handle(t) {} template < class R > inline SimplexCd::~SimplexCd() {} template < class R > SimplexCd & SimplexCd:: operator=(const SimplexCd &t) { Handle::operator=(t); return *this; } template < class R > struct LessCdforSimplex { bool operator() (typename R::Point_d const &p, typename R::Point_d const &q) { return lexicographically_d_smaller_or_equal(p,q); } }; template < class R > bool SimplexCd:: operator==(const SimplexCd &t) const { if ( id() == t.id() ) return true; if ( orientation() != t.orientation() ) return false; // Sort and remove duplicates from this std::vector< Point_d > V1( begin(), end() ); std::sort(V1.begin(), V1.end(), LessCdforSimplex()); V1.erase( std::unique( V1.begin(), V1.end()), V1.end()); // Sort and remove duplicates from t std::vector< Point_d > V2( t.begin(), t.end() ); std::sort(V2.begin(), V2.end(), LessCdforSimplex()); V2.erase( std::unique( V2.begin(), V2.end()), V2.end()); return V1 == V2; } template < class R > inline bool SimplexCd:: operator!=(const SimplexCd &t) const { return !(*this == t); } template < class R > inline long SimplexCd::id() const { return (long) PTR; } template < class R > typename SimplexCd::Point_d SimplexCd:: vertex(int i) const { i %= number_of_vertices(); if (i<0) i += number_of_vertices(); return *(begin()+i); } template < class R > inline typename SimplexCd::Point_d SimplexCd:: operator[](int i) const { return vertex(i); } template < class R > Orientation SimplexCd:: orientation() const { return CGAL::orientation(begin(), end(), Cartesian_tag()); } template < class R > Oriented_side SimplexCd:: oriented_side(const typename SimplexCd::Point_d &p) const { Orientation o = orientation(); if (o != ZERO) return Oriented_side(o * bounded_side(p)); CGAL_kernel_assertion (!is_degenerate()); return ON_ORIENTED_BOUNDARY; } template < class R > Bounded_side SimplexCd:: bounded_side(const typename SimplexCd::Point_d &p) const { return side_of_bounded_simplex(begin(),end(),p); } template < class R > inline bool SimplexCd::has_on_boundary (const typename SimplexCd::Point_d &p) const { return oriented_side(p) == ON_ORIENTED_BOUNDARY; } template < class R > inline bool SimplexCd::has_on_positive_side (const typename SimplexCd::Point_d &p) const { return oriented_side(p) == ON_POSITIVE_SIDE; } template < class R > inline bool SimplexCd::has_on_negative_side (const typename SimplexCd::Point_d &p) const { return oriented_side(p) == ON_NEGATIVE_SIDE; } template < class R > inline bool SimplexCd::has_on_bounded_side (const typename SimplexCd::Point_d &p) const { return bounded_side(p) == ON_BOUNDED_SIDE; } template < class R > inline bool SimplexCd::has_on_unbounded_side (const typename SimplexCd::Point_d &p) const { return bounded_side(p) == ON_UNBOUNDED_SIDE; } template < class R > bool SimplexCd::is_degenerate() const { return (orientation() == ZERO); } /* template < class R > inline Bbox_d SimplexCd::bbox() const { return vertex(0).bbox() + vertex(1).bbox() + vertex(2).bbox() + vertex(3).bbox(); } */ template < class R > inline SimplexCd SimplexCd::transform (const typename SimplexCd::Aff_transformation_d &t) const { Point_d* first = new Point_d[dimension()+1], last = first+dimension()+1; Point_d* p, q; for (p=first,q=begin(); p!=last; ++p,++q) *p = t.transform(*q); Self s = Self(first,last); delete[] first; return s; } #ifndef CGAL_NO_OSTREAM_INSERT_SIMPLEXCD template < class R > std::ostream & operator<<(std::ostream &os, const SimplexCd &t) { print_d prt(&os); if (os.iword(IO::mode)==IO::PRETTY) os << "SimplexCd("; prt(t.dimension()); if (os.iword(IO::mode)==IO::PRETTY) os << ", ("; prt.reset(); std::for_each(t.begin(),t.end(),prt); if (os.iword(IO::mode)==IO::PRETTY) os << "))"; return os; } #endif // CGAL_NO_OSTREAM_INSERT_SIMPLEXCD #ifndef CGAL_NO_ISTREAM_EXTRACT_SIMPLEXCD template < class R > std::istream & operator>>(std::istream &is, SimplexCd &t) { // FIXME : TODO return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_SIMPLEXCD CGAL_END_NAMESPACE #ifdef CGAL_CFG_TYPENAME_BUG #undef typename #endif #endif // CGAL_CARTESIAN_SIMPLEX_D_C