// ====================================================================== // // 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/Plane_d.C // revision : $Revision$ // revision_date : $Date$ // author(s) : Herve Brönnimann // coordinator : INRIA Sophia-Antipolis (Mariette.Yvinec@sophia.inria.fr) // // ====================================================================== #ifndef CGAL_CARTESIAN_PLANE_D_C #define CGAL_CARTESIAN_PLANE_D_C #ifndef CGAL_CARTESIAN_REDEFINE_NAMES_D_H #define CGAL_CTAG #endif #ifdef CGAL_CFG_TYPENAME_BUG #define typename #endif #include #include #include // #include #include CGAL_BEGIN_NAMESPACE template < class R > inline void PlaneCd:: new_rep(int dim) { PTR = new _d_tuple(dim+1); } template < class R > inline void PlaneCd:: new_rep(typename PlaneCd::const_iterator hb, typename PlaneCd::const_iterator he) { int dim = he-hb-1; new_rep(dim); std::copy_n(hb,dim+1,begin()); } template < class R > inline void PlaneCd:: new_rep(typename PlaneCd::const_iterator hb, typename PlaneCd::const_iterator he, const typename PlaneCd::RT &w) { int dim = he-hb-1; new_rep(dim); std::copy_n(hb,dim,begin()); *(begin()+dim+1) = w; } template < class R > inline PlaneCd:: PlaneCd(int dim) { new_rep(dim); } template < class R > inline PlaneCd:: PlaneCd(const PlaneCd &p) : Handle(p) {} template < class R > CGAL_KERNEL_INLINE PlaneCd:: PlaneCd(const typename PlaneCd::Point_d &p, const typename PlaneCd::Direction_d &d) { PlaneCd h = plane_from_point_direction(p,d); new_rep(h.begin(),h.end()); } template < class R > CGAL_KERNEL_INLINE PlaneCd:: PlaneCd(const typename PlaneCd::Point_d &p, const typename PlaneCd::Vector_d &v) { PlaneCd h = plane_from_point_direction(p,v.direction()); new_rep(h.begin(),h.end()); } template < class R > inline PlaneCd::~PlaneCd() {} template < class R > inline PlaneCd &PlaneCd:: operator=(const PlaneCd &p) { Handle::operator=(p); return *this; } template < class R > CGAL_KERNEL_INLINE bool PlaneCd:: operator==(const PlaneCd &h) const { if (dimension() != h.dimension()) return false; if (ptr() == h.ptr()) return true; // identical return is_positively_proportionalCd(begin(),end(),h.begin()); } template < class R > inline bool PlaneCd:: operator!=(const PlaneCd &p) const { return !(*this == p); } template < class R > inline long PlaneCd::id() const { return (long) PTR; } template < class R > inline typename PlaneCd::RT PlaneCd::operator[](int i) const { return *(begin()+i); } template < class R > inline typename PlaneCd::Point_d PlaneCd::point(int i) const { return point_on_plane(*this,i); } template < class R > inline typename PlaneCd::Point_d PlaneCd:: projection(const typename PlaneCd::Point_d &p) const { return projection_plane(p, *this); } template < class R > inline typename PlaneCd::Vector_d PlaneCd::orthogonal_vector() const { return Vector_d(dimension(),begin(),end()-1); } template < class R > inline typename PlaneCd::Direction_d PlaneCd::orthogonal_direction() const { return Direction_d(dimension(),begin(),end()-1); } template < class R > typename PlaneCd::Vector_d PlaneCd::base(int i) const { return point(i+1)-point(0); } template < class R > inline typename PlaneCd::Line_d PlaneCd:: perpendicular_line(const typename PlaneCd::Point_d &p) const { return Line_d(p, orthogonal_direction()); } template < class R > inline PlaneCd PlaneCd::opposite() const { Self h(dimension()); std::transform(begin(),end(),h.begin(),std::negate()); return h; } template < class R > PlaneCd PlaneCd:: transform(const typename PlaneCd::Aff_transformation_d& t) const { return t.transform(*this); } template < class R > inline Oriented_side PlaneCd:: oriented_side(const typename PlaneCd::Point_d &p) const { return side_of_oriented_plane(*this,p); } template < class R > inline bool PlaneCd:: has_on_boundary(const typename PlaneCd::Point_d &p) const { return oriented_side(p) == ON_ORIENTED_BOUNDARY; } template < class R > inline bool PlaneCd:: has_on(const typename PlaneCd::Point_d &p) const { return has_on_boundary(p); } template < class R > inline bool PlaneCd:: has_on_positive_side(const typename PlaneCd::Point_d &p) const { return oriented_side(p) == ON_POSITIVE_SIDE; } template < class R > inline bool PlaneCd:: has_on_negative_side(const typename PlaneCd::Point_d &p) const { return oriented_side(p) == ON_NEGATIVE_SIDE; } template < class R > inline bool PlaneCd:: is_degenerate() const { return orthogonal_vector() == NULL_VECTOR; } #ifndef CGAL_NO_OSTREAM_INSERT_PLANECD template < class R > std::ostream & operator<<(std::ostream &os, const PlaneCd &h) { typedef typename R::FT FT; // normalize but do it with a copy in order to keep h as const PlaneCd m( h ); FT norm = std::inner_product(m.begin(),m.end()-1,m.begin(),FT(0)); std::transform(m.begin(),m.end(),m.begin(), std::bind2nd(std::divides(),CGAL::sqrt(norm))); print_d prt(&os); if (os.iword(IO::mode)==IO::PRETTY) os << "PlaneCd("; prt(m.dimension()); if (os.iword(IO::mode)==IO::PRETTY) { os << ", ("; prt.reset(); } std::for_each(m.begin(),m.end(),prt); if (os.iword(IO::mode)==IO::PRETTY) os << "))"; return os; } #endif // CGAL_NO_OSTREAM_INSERT_PLANECD #ifndef CGAL_NO_ISTREAM_EXTRACT_PLANECD template < class R > std::istream & operator>>(std::istream &is, PlaneCd &p) { int dim; typename R::FT h; switch(is.iword(IO::mode)) { case IO::ASCII : break; case IO::BINARY : break; default: std::cerr << "" << std::endl; std::cerr << "Stream must be in ascii or binary mode" << std::endl; break; } if (is) p = PlaneCd(dim, h, h+dim+1); return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_PLANECD CGAL_END_NAMESPACE #ifdef CGAL_CFG_TYPENAME_BUG #undef typename #endif #endif // CGAL_CARTESIAN_PLANE_D_C