// ====================================================================== // // 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 : 2000, October 15 // // source : webS3/S3.lw // file : include/CGAL/SimpleCartesian/SegmentS3.h // package : S3 (1.7) // maintainer : Stefan Schirra // revision : 1.7 // revision_date : 15 Oct 2000 // author(s) : Stefan Schirra // based on code by // Andreas Fabri and // Herve Brönnimann // // coordinator : MPI, Saarbrücken // ====================================================================== #ifndef CGAL_SEGMENTS3_H #define CGAL_SEGMENTS3_H #include #include #include CGAL_BEGIN_NAMESPACE template < class FT > class SegmentS3{ public: SegmentS3() {} SegmentS3(const PointS3& sp, const PointS3& ep) : e0(sp), e1(ep) {} bool has_on(const PointS3& p) const; bool collinear_has_on(const PointS3& p) const; bool operator==(const SegmentS3& s) const; bool operator!=(const SegmentS3& s) const; PointS3 start() const; PointS3 end() const; PointS3 source() const; PointS3 target() const; PointS3 min() const; PointS3 max() const; PointS3 vertex(int i) const; PointS3 point(int i) const; PointS3 operator[](int i) const; FT squared_length() const; DirectionS3 direction() const; LineS3 supporting_line() const; SegmentS3 opposite() const; SegmentS3 transform(const Aff_transformationS3& t) const; bool is_degenerate() const; Bbox_3 bbox() const; // private: PointS3 e0; PointS3 e1; }; template < class FT > inline bool SegmentS3::operator==(const SegmentS3& s) const { return (source() == s.source()) && (target() == s.target()); } template < class FT > inline bool SegmentS3::operator!=(const SegmentS3& s) const { return !(*this == s); } template < class FT > PointS3 SegmentS3::start() const { return e0; } template < class FT > PointS3 SegmentS3::end() const { return e1; } template < class FT > PointS3 SegmentS3::source() const { return e0; } template < class FT > PointS3 SegmentS3::target() const { return e1; } template < class FT > inline PointS3 SegmentS3::min() const { return (lexicographically_xyz_smaller(source(),target())) ? source() : target(); } template < class FT > inline PointS3 SegmentS3::max() const { return (lexicographically_xyz_smaller(source(),target())) ? target() : source(); } template < class FT > inline PointS3 SegmentS3::vertex(int i) const { return (i%2 == 0) ? source() : target(); } template < class FT > inline PointS3 SegmentS3::point(int i) const { return (i%2 == 0) ? source() : target(); } template < class FT > inline PointS3 SegmentS3::operator[](int i) const { return vertex(i); } template < class FT > inline FT SegmentS3::squared_length() const { return squared_distance(target(), source()); } template < class FT > inline DirectionS3 SegmentS3::direction() const { return DirectionS3( target() - source() ); } template < class FT > inline LineS3 SegmentS3::supporting_line() const { return LineS3(*this); } template < class FT > inline SegmentS3 SegmentS3::opposite() const { return SegmentS3(target(), source()); } template < class FT > inline SegmentS3 SegmentS3::transform(const Aff_transformationS3& t) const { return SegmentS3(t.transform(source()), t.transform(target())); } template < class FT > inline bool SegmentS3::is_degenerate() const { return source() == target(); } template < class FT > inline Bbox_3 SegmentS3::bbox() const { return source().bbox() + target().bbox(); } #ifndef CGAL_NO_OSTREAM_INSERT_SEGMENTS3 template < class FT > std::ostream& operator<<(std::ostream& os, const SegmentS3& 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 << "SegmentS3(" << s.source() << ", " << s.target() << ")"; } } #endif // CGAL_NO_OSTREAM_INSERT_SEGMENTS3 #ifndef CGAL_NO_ISTREAM_EXTRACT_SEGMENTS3 template < class FT > std::istream& operator>>(std::istream& is, SegmentS3& s) { PointS3 p, q; is >> p >> q; s = SegmentS3(p, q); return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_SEGMENTS3 template < class FT > bool SegmentS3::has_on(const PointS3& p) const { return are_ordered_along_line(source(), p, target()); } template < class FT > inline bool SegmentS3::collinear_has_on(const PointS3& p) const { return collinear_are_ordered_along_line(source(), p, target()); } CGAL_END_NAMESPACE #endif