// ============================================================================ // // Copyright (c) 1998 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 : $CGAL_Revision: $ // release_date : $CGAL_Date: $ // // file : include/CGAL/squared_distance_utils.h // source : sqdistance_2.fw // author(s) : Geert-Jan Giezeman // // coordinator : Saarbruecken // // ============================================================================ #ifndef CGAL_SQUARED_DISTANCE_UTILS_H #define CGAL_SQUARED_DISTANCE_UTILS_H #include #include CGAL_BEGIN_NAMESPACE template bool is_null(const Vector_2 &v) { typedef typename R::RT RT; return v.hx()==RT(0) && v.hy()==RT(0); } template typename R::RT wdot(const Vector_2 &u, const Vector_2 &v) { return (u.hx()*v.hx() + u.hy()*v.hy()); } template typename R::RT wdot(const Point_2< R > &p, const Point_2< R > &q, const Point_2< R > &r) { R* pR = 0; return (wmult(pR, p.hx(),q.hw()) - wmult(pR, q.hx(),p.hw())) * (wmult(pR, r.hx(),q.hw()) - wmult(pR, q.hx(),r.hw())) + (wmult(pR, p.hy(),q.hw()) - wmult(pR, q.hy(),p.hw())) * (wmult(pR, r.hy(),q.hw()) - wmult(pR, q.hy(),r.hw())); } template typename R::RT wcross(const Vector_2 &u, const Vector_2 &v) { return (typename R::RT)(u.hx()*v.hy() - u.hy()*v.hx()); } #if defined CGAL_HOMOGENEOUS_H template inline RT wcross_impl(const Homogeneous*,const Point_2< Homogeneous > &p, const Point_2< Homogeneous > &q, const Point_2< Homogeneous > &r) { return p.hx() * (q.hy()*r.hw() - q.hw()*r.hy() ) + p.hy() * (q.hw()*r.hx() - q.hx()*r.hw() ) + p.hw() * (q.hx()*r.hy() - q.hy()*r.hx() ); } #endif // CGAL_HOMOGENEOUS_H #if defined CGAL_SIMPLE_HOMOGENEOUS_H template inline RT wcross_impl(const Simple_homogeneous*, const Point_2< Simple_homogeneous > &p, const Point_2< Simple_homogeneous > &q, const Point_2< Simple_homogeneous > &r) { return det3x3_by_formula( p.hx(), q.hx(), r.hx(), p.hy(), q.hy(), r.hy(), p.hw(), q.hw(), r.hw()); } #endif // CGAL_SIMPLE_HOMOGENEOUS_H #if defined CGAL_CARTESIAN_H template inline FT wcross_impl(const Cartesian *, const Point_2< Cartesian > &p, const Point_2< Cartesian > &q, const Point_2< Cartesian > &r) { return (q.x()-p.x())*(r.y()-q.y()) - (q.y()-p.y())*(r.x()-q.x()); } #endif // CGAL_CARTESIAN_H #if defined CGAL_SIMPLE_CARTESIAN_H template inline FT wcross_impl(const Simple_cartesian *, const Point_2< Simple_cartesian > &p, const Point_2< Simple_cartesian > &q, const Point_2< Simple_cartesian > &r) { return (q.x()-p.x())*(r.y()-q.y()) - (q.y()-p.y())*(r.x()-q.x()); } #endif // CGAL_SIMPLE_CARTESIAN_H template typename R::RT wcross(const Point_2< R > &p, const Point_2< R > &q, const Point_2< R > &r) { return wcross_impl(static_cast(0), p, q, r); } template inline bool is_acute_angle(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; return RT(wdot(u, v)) > RT(0) ; } template inline bool is_straight_angle(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; return RT(wdot(u, v)) == RT(0) ; } template inline bool is_obtuse_angle(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; return RT(wdot(u, v)) < RT(0) ; } template inline bool is_acute_angle(const Point_2 &p, const Point_2 &q, const Point_2 &r) { typedef typename R::RT RT; return RT(wdot(p, q, r)) > RT(0) ; } template inline bool is_straight_angle(const Point_2 &p, const Point_2 &q, const Point_2 &r) { typedef typename R::RT RT; return RT(wdot(p, q, r)) == RT(0) ; } template inline bool is_obtuse_angle(const Point_2 &p, const Point_2 &q, const Point_2 &r) { typedef typename R::RT RT; return RT(wdot(p, q, r)) < RT(0) ; } template Orientation orientation(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; RT wcr = wcross(u,v); return (wcr > RT(0)) ? COUNTERCLOCKWISE : (wcr < RT(0)) ? CLOCKWISE : COLLINEAR; } template inline bool counterclockwise(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; return RT(wcross(u,v)) > RT(0); } template inline bool left_turn(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; return RT(wcross(u,v)) > RT(0); } template inline bool clockwise(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; return RT(wcross(u,v)) < RT(0); } template inline bool right_turn(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; return RT(wcross(u,v)) < RT(0); } template inline bool collinear(const Vector_2 &u, const Vector_2 &v) { typedef typename R::RT RT; return RT(wcross(u,v)) == RT(0); } /* the ordertype, right_turn, left_turn and collinear routines for points are defined elsewhere. */ CGAL_END_NAMESPACE #endif // CGAL_SQUARED_DISTANCE_UTILS_H