// ====================================================================== // // 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/Segment_d.C // revision : $Revision$ // revision_date : $Date$ // author(s) : Andreas.Fabri@sophia.inria.fr // 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 #include #ifndef CGAL_CARTESIAN_SEGMENT_D_C #define CGAL_CARTESIAN_SEGMENT_D_C CGAL_BEGIN_NAMESPACE template < class R > inline _Twotuple< typename SegmentCd::Point_d > * SegmentCd::ptr() const { return (_Twotuple< Point_d >*)PTR; } template < class R > SegmentCd:: SegmentCd() { PTR = new _Twotuple< Point_d >; } template < class R > SegmentCd:: SegmentCd(const SegmentCd &s) : Handle((Handle&)s) {} template < class R > SegmentCd:: SegmentCd(const typename SegmentCd::Point_d &sp, const typename SegmentCd::Point_d &ep) { CGAL_kernel_precondition( sp.dimension() == ep.dimension() ); PTR = new _Twotuple< Point_d >(sp, ep); } template < class R > inline SegmentCd::~SegmentCd() {} template < class R > SegmentCd & SegmentCd::operator=(const SegmentCd &s) { Handle::operator=(s); return *this; } template < class R > inline bool SegmentCd::operator==(const SegmentCd &s) const { if (ptr() == s.ptr()) return true; // identical return (source() == s.source()) && (target() == s.target()); } template < class R > inline bool SegmentCd::operator!=(const SegmentCd &s) const { return !(*this == s); } template < class R > long SegmentCd::id() const { return (long) PTR; } template < class R > typename SegmentCd::Point_d SegmentCd::start() const { return ptr()->e0; } template < class R > typename SegmentCd::Point_d SegmentCd::end() const { return ptr()->e1; } template < class R > typename SegmentCd::Point_d SegmentCd::source() const { return ptr()->e0; } template < class R > typename SegmentCd::Point_d SegmentCd::target() const { return ptr()->e1; } template < class R > inline typename SegmentCd::Point_d SegmentCd::min() const { return (lexicographically_d_smaller(source(),target())) ? source() : target(); } template < class R > inline typename SegmentCd::Point_d SegmentCd::max() const { return (lexicographically_d_smaller(source(),target())) ? target() : source(); } template < class R > inline typename SegmentCd::Point_d SegmentCd::vertex(int i) const { return (i%2 == 0) ? source() : target(); } template < class R > inline typename SegmentCd::Point_d SegmentCd::point(int i) const { return (i%2 == 0) ? source() : target(); } template < class R > inline typename SegmentCd::Point_d SegmentCd::operator[](int i) const { return vertex(i); } template < class R > inline typename SegmentCd::FT SegmentCd::squared_length() const { return squared_distance(target(), source()); } template < class R > inline typename SegmentCd::Direction_d SegmentCd::direction() const { return Direction_d( target() - source() ); } template < class R > inline typename SegmentCd::Line_d SegmentCd::supporting_line() const { return Line_d(*this); } template < class R > inline SegmentCd SegmentCd::opposite() const { return SegmentCd(target(), source()); } template < class R > inline SegmentCd SegmentCd:: transform(const typename SegmentCd::Aff_transformation_d &t) const { return SegmentCd(t.transform(source()), t.transform(target())); } template < class R > inline bool SegmentCd::is_degenerate() const { return source() == target(); } /* template < class R > inline Bbox_d SegmentCd::bbox() const { return source().bbox() + target().bbox(); } */ template < class R > bool SegmentCd:: has_on(const typename SegmentCd::Point_d &p) const { return are_ordered_along_line(source(), p, target()); } template < class R > inline bool SegmentCd:: collinear_has_on(const typename SegmentCd::Point_d &p) const { return collinear_are_ordered_along_line(source(), p, target()); } #ifndef CGAL_NO_OSTREAM_INSERT_SEGMENTCd template < class R > std::ostream & operator<<(std::ostream &os, const SegmentCd &s) { switch(os.iword(IO::mode)) { case IO::ASCII : return os << s.source() << ' ' << s.target(); case IO::BINARY : return os << s.source() << s.target(); default: return os << "SegmentCd(" << s.source() << ", " << s.target() << ")"; } } #endif // CGAL_NO_OSTREAM_INSERT_SEGMENTCd #ifndef CGAL_NO_ISTREAM_EXTRACT_SEGMENTCd template < class R > std::istream & operator>>(std::istream &is, SegmentCd &s) { typename SegmentCd::Point_d p, q; is >> p >> q; if (is) s = SegmentCd(p, q); return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_SEGMENTCd CGAL_END_NAMESPACE #ifdef CGAL_CFG_TYPENAME_BUG #undef typename #endif #endif // CGAL_CARTESIAN_SEGMENT_D_C