// ====================================================================== // // 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, August 16 // // source : webS2/S2.lw // file : include/CGAL/SimpleCartesian/PointS2.h // package : S2 (1.7) // maintainer : Stefan Schirra // revision : 1.6 // revision_date : 27 Jun 2000 // author(s) : Stefan Schirra // based on code by // Andreas Fabri and // Herve Brönnimann // // coordinator : MPI, Saarbrücken // ====================================================================== #ifndef CGAL_POINTS2_H #define CGAL_POINTS2_H CGAL_BEGIN_NAMESPACE template < class FT > class PointS2 { public: PointS2() {} PointS2(const Origin& ) : e0(FT(0)), e1(FT(0)) {} PointS2(const FT& hx, const FT& hy, const FT& hw); PointS2(const FT& x, const FT& y); bool operator==(const PointS2& p) const; bool operator!=(const PointS2& p) const; const FT& hx() const; const FT& hy() const; FT hw() const; const FT& x() const; const FT& y() const; FT cartesian(int i) const; FT operator[](int i) const; FT homogeneous(int i) const; int dimension() const; Bbox_2 bbox() const; PointS2 transform(const Aff_transformationS2& ) const; // protected: PointS2(const VectorS2& v); FT e0; FT e1; }; CGAL_END_NAMESPACE #include #include #include #include #include CGAL_BEGIN_NAMESPACE template < class FT > CGAL_KERNEL_CTOR_INLINE PointS2::PointS2(const VectorS2& v) { e0 = v.e0; e1 = v.e1; } template < class FT > CGAL_KERNEL_CTOR_INLINE PointS2::PointS2(const FT& hx, const FT& hy, const FT& hw) { if( hw != FT(1)) { e0 = hx/hw; e1 = hy/hw; } else { e0 = hx; e1 = hy; } } template < class FT > CGAL_KERNEL_CTOR_INLINE PointS2::PointS2(const FT& x, const FT& y) { e0 = x; e1 = y; } template < class FT > inline bool PointS2::operator==(const PointS2& p) const { return ((x() == p.x()) && (y() == p.y())) ; } template < class FT > inline bool PointS2::operator!=(const PointS2& p) const { return !(*this == p); } template < class FT > inline const FT& PointS2::x() const { return e0; } template < class FT > inline const FT& PointS2::y() const { return e1 ; } template < class FT > CGAL_KERNEL_INLINE FT PointS2::cartesian(int i) const { CGAL_kernel_precondition( (i == 0) || (i == 1) ); return (i == 0) ? x() : y(); } template < class FT > inline FT PointS2::operator[](int i) const { return cartesian(i); } template < class FT > inline int PointS2::dimension() const { return 2; } template < class FT > inline const FT& PointS2::hx() const { return e0; } template < class FT > inline const FT& PointS2::hy() const { return e1; } template < class FT > inline FT PointS2::hw() const { return FT(1); } template < class FT > inline FT PointS2::homogeneous(int i) const { CGAL_kernel_precondition( (i>=0) && (i<=2) ); if (i<2) return cartesian(i); return FT(1); } template < class FT > inline PointS2 operator+(const PointS2& p, const VectorS2& v) { return PointS2(p.x() + v.x(), p.y() + v.y()) ; } template < class FT > inline PointS2 operator-(const PointS2& p, const VectorS2& v) { return PointS2(p.x() - v.x(), p.y() - v.y()) ; } template < class FT > inline PointS2 operator+(const Origin& , const VectorS2& v) { return PointS2(v) ; } template < class FT > inline PointS2 operator-(const Origin& , const VectorS2& v) { return PointS2(-v) ; } template < class FT > inline VectorS2 operator-(const PointS2& p, const PointS2& q) { return VectorS2(p.x() - q.x(), p.y() - q.y()) ; } template < class FT > inline VectorS2 operator-(const PointS2& p, const Origin& ) { return VectorS2(p) ; } template < class FT > inline VectorS2 operator-(const Origin& , const PointS2& p) { return VectorS2(-p.x(), -p.y()) ; } template < class FT > CGAL_KERNEL_INLINE PointS2 PointS2::transform( const Aff_transformationS2& t) const { return t.transform(*this); } template < class FT > CGAL_KERNEL_INLINE Bbox_2 PointS2::bbox() const { double bx = CGAL::to_double(x()); double by = CGAL::to_double(y()); return Bbox_2(bx,by, bx,by); } #ifndef CGAL_NO_OSTREAM_INSERT_POINTS2 template < class FT > std::ostream& operator<<(std::ostream& os, const PointS2& p) { switch(os.iword(IO::mode)) { case IO::ASCII : return os << p.x() << ' ' << p.y(); case IO::BINARY : write(os, p.x()); write(os, p.y()); return os; default: return os << "PointS2(" << p.x() << ", " << p.y() << ')'; } } #endif // CGAL_NO_OSTREAM_INSERT_POINTS2 #ifndef CGAL_NO_ISTREAM_EXTRACT_POINTS2 template < class FT > std::istream& operator>>(std::istream& is, PointS2& p) { FT x, y; switch(is.iword(IO::mode)) { case IO::ASCII : is >> x >> y; break; case IO::BINARY : read(is, x); read(is, y); break; default: CGAL_kernel_assertion_msg(false,"Stream must be in ascii or binary mode"); // throw ios_base::failure("Stream must be in ascii or binary mode"); } p = PointS2(x, y); return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_POINTS2 CGAL_END_NAMESPACE #endif // CGAL_POINTS2_H