// revision : $Revision$ // revision_date : $Date$ // author(s) : Andreas Fabri, Herve Bronnimann #ifndef CGAL_CARTESIAN_LINE_2_C #define CGAL_CARTESIAN_LINE_2_C #include #include #ifndef CGAL_CARTESIAN_REDEFINE_NAMES_2_H #define CGAL_CTAG #endif #ifdef CGAL_CFG_TYPENAME_BUG #define typename #endif CGAL_BEGIN_NAMESPACE template < class R > inline _Threetuple::FT>* LineC2::ptr() const { return (_Threetuple*)PTR; } template < class R > CGAL_KERNEL_INLINE void LineC2::new_rep(const typename LineC2::FT &a, const typename LineC2::FT &b, const typename LineC2::FT &c) { PTR = new _Threetuple (a, b, c); } template < class R > CGAL_KERNEL_INLINE void LineC2::new_rep(const typename LineC2::Point_2 &p, const typename LineC2::Point_2 &q) { LineC2 l = line_from_points(p,q); new_rep(l.a(), l.b(), l.c()); } template < class R > inline LineC2::LineC2() { PTR = new _Threetuple; } template < class R > inline LineC2::LineC2(const LineC2 &l) : Handle((Handle&)l) {} template < class R > inline LineC2::LineC2(const typename LineC2::Point_2 &p, const typename LineC2::Point_2 &q) { new_rep(p, q); } template < class R > inline LineC2::LineC2(const typename LineC2::FT &a, const typename LineC2::FT &b, const typename LineC2::FT &c) { new_rep(a, b, c); } template < class R > inline LineC2::LineC2(const typename LineC2::Segment_2 &s) { new_rep(s.start(), s.end()); } template < class R > inline LineC2::LineC2(const typename LineC2::Ray_2 &r) { new_rep(r.start(), r.second_point()); } template < class R > CGAL_KERNEL_INLINE LineC2::LineC2(const typename LineC2::Point_2 &p, const typename LineC2::Direction_2 &d) { LineC2 l = line_from_point_direction(p,d); new_rep(l.a(), l.b(), l.c()); } template < class R > inline LineC2::~LineC2() {} template < class R > CGAL_KERNEL_INLINE LineC2 & LineC2::operator=(const LineC2 &l) { Handle::operator=(l); return *this; } template < class R > CGAL_KERNEL_MEDIUM_INLINE bool LineC2::operator==(const LineC2 &l) const { if ( id() == l.id() ) return true; return equal_line(*this,l); } template < class R > inline bool LineC2::operator!=(const LineC2 &l) const { return !(*this == l); } template < class R > inline int LineC2::id() const { return (int) PTR; } template < class R > inline typename LineC2::FT LineC2::a() const { return ptr()->e0; } template < class R > inline typename LineC2::FT LineC2::b() const { return ptr()->e1; } template < class R > inline typename LineC2::FT LineC2::c() const { return ptr()->e2; } template < class R > CGAL_KERNEL_INLINE typename LineC2::FT LineC2::x_at_y(const typename LineC2::FT &y) const { CGAL_kernel_precondition_msg( (a() != FT(0)), "Line::x_at_y(const typename LineC2::FT &y) is undefined for horizontal line" ); return line_x_at_y(*this,y); } template < class R > CGAL_KERNEL_INLINE typename LineC2::FT LineC2::y_at_x(const typename LineC2::FT &x) const { CGAL_kernel_precondition_msg( (b() != FT(0)), "Line::x_at_y(const typename LineC2::FT &y) is undefined for vertical line"); return line_y_at_x(*this,x); } template < class R > inline LineC2 LineC2:: perpendicular(const typename LineC2::Point_2 &p) const { return LineC2( -b(), a(), b() * p.x() - a() * p.y()); } template < class R > inline LineC2 LineC2::opposite() const { return LineC2( -a(), -b(), -c() ); } template < class R > CGAL_KERNEL_MEDIUM_INLINE typename LineC2::Point_2 LineC2::point(int i) const { return line_get_point(*this,i); } template < class R > CGAL_KERNEL_INLINE typename LineC2::Point_2 LineC2::point() const { return line_get_point(*this,0); } template < class R > CGAL_KERNEL_MEDIUM_INLINE typename LineC2::Point_2 LineC2:: projection(const typename LineC2::Point_2 &p) const { if (is_horizontal()) return Point_2(p.x(), -c()/b()); if (is_vertical()) return Point_2( -c()/a(), p.y()); FT ab = a()/b(), ba = b()/a(), ca = c()/a(); FT y = ( -p.x() + ab*p.y() - ca ) / ( ba + ab ); return Point_2(-ba * y - ca, y); } template < class R > inline typename LineC2::Direction_2 LineC2::direction() const { return Direction_2( b(), -a() ); } template < class R > CGAL_KERNEL_INLINE Oriented_side LineC2:: oriented_side(const typename LineC2::Point_2 &p) const { return side_of_oriented_line(*this,p); } template < class R > inline bool LineC2:: has_on_boundary(const typename LineC2::Point_2 &p) const { return oriented_side(p) == ON_ORIENTED_BOUNDARY; } template < class R > inline bool LineC2:: has_on_positive_side(const typename LineC2::Point_2 &p) const { return oriented_side(p) == ON_POSITIVE_SIDE; } template < class R > CGAL_KERNEL_INLINE bool LineC2:: has_on_negative_side(const typename LineC2::Point_2 &p) const { return oriented_side(p) == ON_NEGATIVE_SIDE; } template < class R > inline bool LineC2::is_horizontal() const { return a() == LineC2::FT(0) ; } template < class R > inline bool LineC2::is_vertical() const { return b() == FT(0) ; } template < class R > inline bool LineC2::is_degenerate() const { return (a() == FT(0)) && (b() == FT(0)) ; } template < class R > inline LineC2 LineC2:: transform(const typename LineC2::Aff_transformation_2 &t) const { return LineC2(t.transform(point(0)), t.transform(direction())); } #ifndef CGAL_NO_OSTREAM_INSERT_LINEC2 template < class R > std::ostream & operator<<(std::ostream &os, const LineC2 &l) { switch(os.iword(IO::mode)) { case IO::ASCII : return os << l.a() << ' ' << l.b() << ' ' << l.c(); case IO::BINARY : write(os, l.a()); write(os, l.b()); write(os, l.c()); return os; default: return os << "LineC2(" << l.a() << ", " << l.b() << ", " << l.c() <<')'; } } #endif // CGAL_NO_OSTREAM_INSERT_LINEC2 #ifndef CGAL_NO_ISTREAM_EXTRACT_LINEC2 template < class R > std::istream & operator>>(std::istream &is, LineC2 &p) { typename LineC2::FT a, b, c; switch(is.iword(IO::mode)) { case IO::ASCII : is >> a >> b >> c; break; case IO::BINARY : read(is, a); read(is, b); read(is, c); break; default: std::cerr << "" << std::endl; std::cerr << "Stream must be in ascii or binary mode" << std::endl; break; } p = LineC2(a, b, c); return is; } #endif // CGAL_NO_ISTREAM_EXTRACT_LINEC2 CGAL_END_NAMESPACE #ifdef CGAL_CFG_TYPENAME_BUG #undef typename #endif #endif // CGAL_CARTESIAN_LINE_2_C