// ====================================================================== // // 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 : SegmentH3.h // package : H3 // revision : $Revision$ // revision_date : $Date$ // author(s) : Stefan Schirra // // // coordinator : MPI, Saarbruecken () // ====================================================================== #ifndef CGAL_SEGMENTH3_H #define CGAL_SEGMENTH3_H #include CGAL_BEGIN_NAMESPACE template < class R > class Segment_repH3 : public Ref_counted { public: Segment_repH3() {} Segment_repH3(const PointH3& sp, const PointH3& ep) : startpoint(sp), endpoint(ep) {} const PointH3 & start() const { return startpoint; } const PointH3 & end() const { return endpoint; } private: PointH3 startpoint, endpoint; }; template < class R > class Simple_Segment_repH3 { public: Simple_Segment_repH3() {} Simple_Segment_repH3(const PointH3& sp, const PointH3& ep) : startpoint(sp), endpoint(ep) {} const PointH3 & start() const { return startpoint; } const PointH3 & end() const { return endpoint; } private: PointH3 startpoint, endpoint; }; template < class R_ > class SegmentH3 : public R_::Segment_handle_3 { public: typedef R_ R; typedef typename R::RT RT; typedef typename R::FT FT; typedef typename R::Segment_handle_3 Segment_handle_3_; typedef typename Segment_handle_3_::element_type Segment_ref_3; SegmentH3() : Segment_handle_3_(Segment_ref_3()) {} SegmentH3( const PointH3& sp, const PointH3& ep) : Segment_handle_3_(Segment_ref_3(sp, ep)) {} const PointH3 & source() const; const PointH3 & target() const; const PointH3 & start() const; const PointH3 & end() const; const PointH3 & min() const; const PointH3 & max() const; const PointH3 & vertex(int i) const; const PointH3 & point(int i) const; const PointH3 & operator[](int i) const; FT squared_length() const; DirectionH3 direction() const; LineH3 supporting_line() const; SegmentH3 opposite() const; SegmentH3 transform( const Aff_transformationH3 & t) const; Bbox_3 bbox() const; bool has_on(const PointH3 p) const; bool collinear_has_on(const PointH3 p) const; bool is_degenerate() const; bool operator==(const SegmentH3& s) const; bool operator!=(const SegmentH3& s) const; }; template < class R > inline const PointH3 & SegmentH3::source() const { return Ptr()->start(); } template < class R > inline const PointH3 & SegmentH3::target() const { return Ptr()->end(); } template < class R > inline const PointH3 & SegmentH3::start() const { return Ptr()->start(); } template < class R > inline const PointH3 & SegmentH3::end() const { return Ptr()->end(); } template < class R > CGAL_KERNEL_INLINE const PointH3 & SegmentH3::min() const { return lexicographically_xyz_smaller(target(),source()) ? target() : source(); } template < class R > CGAL_KERNEL_INLINE const PointH3 & SegmentH3::max() const { return lexicographically_xyz_smaller_or_equal(source(),target()) ? target() : source(); } template < class R > inline const PointH3 & SegmentH3::vertex(int i) const { return ( i%2 == 0 ) ? start() : end() ; } template < class R > inline const PointH3 & SegmentH3::point(int i) const { return ( i%2 == 0 ) ? start() : end() ; } template < class R > inline const PointH3 & SegmentH3::operator[](int i) const { return ( i%2 == 0 ) ? start() : end() ; } template < class R > CGAL_KERNEL_INLINE typename SegmentH3::FT SegmentH3::squared_length() const { return (Ptr()->end() - Ptr()->start()) * (Ptr()->end() - Ptr()->start()) ; } template < class R > CGAL_KERNEL_INLINE DirectionH3 SegmentH3::direction() const { return DirectionH3( Ptr()->end() - Ptr()->start() ); } template < class R > CGAL_KERNEL_INLINE LineH3 SegmentH3::supporting_line() const { return LineH3(Ptr()->start(), Ptr()->end()); } template < class R > CGAL_KERNEL_INLINE SegmentH3 SegmentH3::opposite() const { return SegmentH3(Ptr()->end(), Ptr()->start()); } template < class R > CGAL_KERNEL_INLINE SegmentH3 SegmentH3:: transform( const Aff_transformationH3& t) const { return SegmentH3(t.transform(Ptr()->start()), t.transform(Ptr()->end()) ); } template < class R > CGAL_KERNEL_INLINE Bbox_3 SegmentH3::bbox() const { return source().bbox() + target().bbox(); } #ifndef CGAL_NO_OSTREAM_INSERT_SEGMENTH3 template < class R > std::ostream &operator<<(std::ostream &os, const SegmentH3 &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 << "SegmentH3(" << s.source() << ", " << s.target() << ")"; } } #endif // CGAL_NO_OSTREAM_INSERT_SEGMENTH3 #ifndef CGAL_NO_ISTREAM_EXTRACT_SEGMENTH3 template < class R > std::istream &operator>>(std::istream &is, SegmentH3 &s) { PointH3 p, q; is >> p >> q; s = SegmentH3(p, q); return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_SEGMENTH3 template < class R > inline bool SegmentH3::is_degenerate() const { return source()==target(); } template < class R > CGAL_KERNEL_INLINE bool SegmentH3::has_on(const PointH3 p) const { return( ( p == start() ) || ( p == end() ) || ( ( collinear(p,source(),target() ) &&( DirectionH3( p - Ptr()->start()) != DirectionH3( p - Ptr()->end())) ) ) ); } template < class R > CGAL_KERNEL_INLINE bool SegmentH3::collinear_has_on(const PointH3 p) const { return( ( p == start() ) || ( p == end() ) || ( DirectionH3( p - Ptr()->start()) != DirectionH3( p - Ptr()->end()) ) ); } template < class R > CGAL_KERNEL_INLINE bool SegmentH3::operator==(const SegmentH3& s) const { return ( (start() == s.start() ) &&(end() == s.end() ) ); } template < class R > inline bool SegmentH3::operator!=(const SegmentH3& s) const { return ( !operator==(s) ); } CGAL_END_NAMESPACE #endif // CGAL_SEGMENTH3_H