// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_SIDE_BY_TRIANGLE_HPP #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_SIDE_BY_TRIANGLE_HPP #include #include #include #include #include #include namespace boost { namespace geometry { namespace strategy { namespace side { /*! \brief Check at which side of a segment a point lies: left of segment (> 0), right of segment (< 0), on segment (0) \ingroup strategies \tparam CalculationType \tparam_calculation */ template class side_by_triangle { public : // Template member function, because it is not always trivial // or convenient to explicitly mention the typenames in the // strategy-struct itself. // Types can be all three different. Therefore it is // not implemented (anymore) as "segment" template static inline promoted_type side_value(P1 const& p1, P2 const& p2, P const& p) { coordinate_type const x = get<0>(p); coordinate_type const y = get<1>(p); coordinate_type const sx1 = get<0>(p1); coordinate_type const sy1 = get<1>(p1); coordinate_type const sx2 = get<0>(p2); coordinate_type const sy2 = get<1>(p2); promoted_type const dx = sx2 - sx1; promoted_type const dy = sy2 - sy1; promoted_type const dpx = x - sx1; promoted_type const dpy = y - sy1; return geometry::detail::determinant ( dx, dy, dpx, dpy ); } template static inline int apply(P1 const& p1, P2 const& p2, P const& p) { typedef typename boost::mpl::if_c < boost::is_void::type::value, typename select_most_precise < typename select_most_precise < typename coordinate_type::type, typename coordinate_type::type >::type, typename coordinate_type

::type >::type, CalculationType >::type coordinate_type; // Promote float->double, small int->int typedef typename select_most_precise < coordinate_type, double >::type promoted_type; promoted_type const s = side_value(p1, p2, p); promoted_type const zero = promoted_type(); return math::equals(s, zero) ? 0 : s > zero ? 1 : -1; } }; #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS namespace services { template struct default_strategy { typedef side_by_triangle type; }; } #endif }} // namespace strategy::side }} // namespace boost::geometry #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_SIDE_BY_TRIANGLE_HPP