// ====================================================================== // // 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/RayS3.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_RAYS3_H #define CGAL_RAYS3_H #include CGAL_BEGIN_NAMESPACE template < class FT > class RayS3 { public: RayS3() {} RayS3(const PointS3& sp, const PointS3& secondp); RayS3(const PointS3& sp, const DirectionS3& d); bool operator==(const RayS3& r) const; bool operator!=(const RayS3& r) const; PointS3 start() const; PointS3 source() const; PointS3 second_point() const; PointS3 point(int i) const; DirectionS3 direction() const; LineS3 supporting_line() const; RayS3 opposite() const; RayS3 transform(const Aff_transformationS3& t) const; bool is_degenerate() const; bool has_on(const PointS3& p) const; bool collinear_has_on(const PointS3& p) const; // private: PointS3 e0; PointS3 e1; }; template < class FT > RayS3::RayS3(const PointS3& sp, const PointS3& secondp) { e0 = sp; e1 = secondp; } template < class FT > RayS3::RayS3(const PointS3& sp, const DirectionS3& d) { e0 = sp; e1 = sp + d.vector(); } template < class FT > inline bool RayS3::operator==(const RayS3& r) const { return (source() == r.source()) && (direction() == r.direction()); } template < class FT > inline bool RayS3::operator!=(const RayS3& r) const { return !(*this == r); } template < class FT > PointS3 RayS3::start() const { return e0; } template < class FT > PointS3 RayS3::source() const { return e0; } template < class FT > PointS3 RayS3::second_point() const { return e1; } template < class FT > PointS3 RayS3::point(int i) const { CGAL_kernel_precondition( i >= 0 ); if (i == 0) return e0; if (i == 1) return e1; return source() + FT(i) * (second_point() - source()); } template < class FT > inline DirectionS3 RayS3::direction() const { return DirectionS3( second_point() - source() ); } template < class FT > inline LineS3 RayS3::supporting_line() const { return LineS3(*this); } template < class FT > inline RayS3 RayS3::opposite() const { return RayS3( source(), - direction() ); } template < class FT > inline RayS3 RayS3::transform(const Aff_transformationS3& t) const { return RayS3(t.transform(source()), t.transform(second_point())); } template < class FT > bool RayS3::has_on(const PointS3& p) const { return (p == source()) || ( collinear(source(), p, second_point()) && ( DirectionS3(p - source()) == direction() )); } template < class FT > inline bool RayS3::is_degenerate() const { return source() == second_point(); } template < class FT > inline bool RayS3::collinear_has_on(const PointS3& p) const { CGAL_kernel_exactness_precondition( collinear(source(), p, second_point()) ); Comparison_result cx = compare_x(source(), second_point()); if (cx != EQUAL) return cx != compare_x(p, source()); Comparison_result cy = compare_y(source(), second_point()); if (cy != EQUAL) return cy != compare_y(p, source()); Comparison_result cz = compare_z(source(), second_point()); if (cz != EQUAL) return cz != compare_z(p, source()); return true; // p == source() } #ifndef CGAL_NO_OSTREAM_INSERT_RAYS3 template < class FT > std::ostream& operator<<(std::ostream& os, const RayS3& r) { switch(os.iword(IO::mode)) { case IO::ASCII : return os << r.start() << ' ' << r.direction(); case IO::BINARY : return os<< r.start() << r.direction(); default: return os << "RayS3(" << r.start() << ", " << r.direction() << ")"; } } #endif // CGAL_NO_OSTREAM_INSERT_RAYS3 #ifndef CGAL_NO_ISTREAM_EXTRACT_RAYS3 template < class FT > std::istream& operator>>(std::istream& is, RayS3& r) { PointS3 p; DirectionS3 d; is >> p >> d; r = RayS3(p, d); return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_RAYS3 CGAL_END_NAMESPACE #endif