Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:44

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2021 Tinko Bartels, Berlin, Germany.
0004 
0005 // This file was modified by Oracle on 2023.
0006 // Modifications copyright (c) 2023 Oracle and/or its affiliates.
0007 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
0008 
0009 // Use, modification and distribution is subject to the Boost Software License,
0010 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
0012 
0013 #ifndef BOOST_GEOMETRY_STRATEGY_CARTESIAN_SIDE_ROUNDED_INPUT_HPP
0014 #define BOOST_GEOMETRY_STRATEGY_CARTESIAN_SIDE_ROUNDED_INPUT_HPP
0015 
0016 #include <limits>
0017 
0018 #include <boost/geometry/core/access.hpp>
0019 #include <boost/geometry/core/config.hpp>
0020 
0021 #include <boost/geometry/util/math.hpp>
0022 
0023 #include <boost/geometry/strategies/side.hpp>
0024 
0025 #include <boost/geometry/util/select_calculation_type.hpp>
0026 
0027 namespace boost { namespace geometry
0028 {
0029 
0030 namespace strategy { namespace side
0031 {
0032 
0033 template <typename CalculationType = void, int Coeff1 = 5, int Coeff2 = 32>
0034 struct side_rounded_input
0035 {
0036     using cs_tag = cartesian_tag;
0037 
0038     template <typename P1, typename P2, typename P>
0039     static inline int apply(P1 const& p1, P2 const& p2, P const& p)
0040     {
0041         using coor_t = typename select_calculation_type_alt<CalculationType, P1, P2, P>::type;
0042 
0043         coor_t const p1_x = geometry::get<0>(p1);
0044         coor_t const p1_y = geometry::get<1>(p1);
0045         coor_t const p2_x = geometry::get<0>(p2);
0046         coor_t const p2_y = geometry::get<1>(p2);
0047         coor_t const p_x = geometry::get<0>(p);
0048         coor_t const p_y = geometry::get<1>(p);
0049 
0050         static coor_t const eps = std::numeric_limits<coor_t>::epsilon() / 2;
0051         coor_t const det = (p1_x - p_x) * (p2_y - p_y) - (p1_y - p_y) * (p2_x - p_x);
0052         coor_t const err_bound = (Coeff1 * eps + Coeff2 * eps * eps) *
0053             (  (geometry::math::abs(p1_x) + geometry::math::abs(p_x))
0054              * (geometry::math::abs(p2_y) + geometry::math::abs(p_y))
0055              + (geometry::math::abs(p2_x) + geometry::math::abs(p_x))
0056              * (geometry::math::abs(p1_y) + geometry::math::abs(p_y)));
0057         return (det > err_bound) - (det < -err_bound);
0058     }
0059 };
0060 
0061 }} // namespace strategy::side
0062 
0063 }} // namespace boost::geometry
0064 
0065 #endif // BOOST_GEOMETRY_STRATEGY_CARTESIAN_SIDE_ROUNDED_INPUT_HPP