Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 
0007 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0008 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0009 
0010 // Use, modification and distribution is subject to the Boost Software License,
0011 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0012 // http://www.boost.org/LICENSE_1_0.txt)
0013 
0014 #ifndef BOOST_GEOMETRY_STRATEGIES_SIDE_INFO_HPP
0015 #define BOOST_GEOMETRY_STRATEGIES_SIDE_INFO_HPP
0016 
0017 #include <cmath>
0018 #include <utility>
0019 
0020 #if defined(BOOST_GEOMETRY_DEBUG_INTERSECTION) || defined(BOOST_GEOMETRY_DEBUG_ROBUSTNESS)
0021 #  include <iostream>
0022 #endif
0023 
0024 namespace boost { namespace geometry
0025 {
0026 
0027 // Silence warning C4127: conditional expression is constant
0028 #if defined(_MSC_VER)
0029 #pragma warning(push)
0030 #pragma warning(disable : 4127)
0031 #endif
0032 
0033 /*!
0034 \brief Class side_info: small class wrapping for sides (-1,0,1)
0035 */
0036 class side_info
0037 {
0038 public :
0039     inline side_info(int side_a1 = 0, int side_a2 = 0,
0040             int side_b1 = 0, int side_b2 = 0)
0041     {
0042         sides[0].first = side_a1;
0043         sides[0].second = side_a2;
0044         sides[1].first = side_b1;
0045         sides[1].second = side_b2;
0046     }
0047 
0048     template <int Which>
0049     inline void set(int first, int second)
0050     {
0051         sides[Which].first = first;
0052         sides[Which].second = second;
0053     }
0054 
0055     template <int Which, int Index>
0056     inline void correct_to_zero()
0057     {
0058         if (Index == 0)
0059         {
0060             sides[Which].first = 0;
0061         }
0062         else
0063         {
0064             sides[Which].second = 0;
0065         }
0066     }
0067 
0068     template <int Which, int Index>
0069     inline int get() const
0070     {
0071         return Index == 0 ? sides[Which].first : sides[Which].second;
0072     }
0073 
0074 
0075     // Returns true if both lying on the same side WRT the other
0076     // (so either 1,1 or -1-1)
0077     template <int Which>
0078     inline bool same() const
0079     {
0080         return sides[Which].first * sides[Which].second == 1;
0081     }
0082 
0083     inline bool collinear() const
0084     {
0085         return sides[0].first == 0
0086             && sides[0].second == 0
0087             && sides[1].first == 0
0088             && sides[1].second == 0;
0089     }
0090 
0091     inline bool crossing() const
0092     {
0093         return sides[0].first * sides[0].second == -1
0094             && sides[1].first * sides[1].second == -1;
0095     }
0096 
0097     inline bool touching() const
0098     {
0099         return (sides[0].first * sides[1].first == -1
0100             && sides[0].second == 0 && sides[1].second == 0)
0101             || (sides[1].first * sides[0].first == -1
0102             && sides[1].second == 0 && sides[0].second == 0);
0103     }
0104 
0105     template <int Which>
0106     inline bool one_touching() const
0107     {
0108         // This is normally a situation which can't occur:
0109         // If one is completely left or right, the other cannot touch
0110         return one_zero<Which>()
0111             && sides[1 - Which].first * sides[1 - Which].second == 1;
0112     }
0113 
0114     inline bool meeting() const
0115     {
0116         // Two of them (in each segment) zero, two not
0117         return one_zero<0>() && one_zero<1>();
0118     }
0119 
0120     template <int Which>
0121     inline bool zero() const
0122     {
0123         return sides[Which].first == 0 && sides[Which].second == 0;
0124     }
0125 
0126     template <int Which>
0127     inline bool one_zero() const
0128     {
0129         return (sides[Which].first == 0 && sides[Which].second != 0)
0130             || (sides[Which].first != 0 && sides[Which].second == 0);
0131     }
0132 
0133     inline bool one_of_all_zero() const
0134     {
0135         int const sum = std::abs(sides[0].first)
0136                 + std::abs(sides[0].second)
0137                 + std::abs(sides[1].first)
0138                 + std::abs(sides[1].second);
0139         return sum == 3;
0140     }
0141 
0142 
0143     template <int Which>
0144     inline int zero_index() const
0145     {
0146         return sides[Which].first == 0 ? 0 : 1;
0147     }
0148 
0149 #if defined(BOOST_GEOMETRY_DEBUG_INTERSECTION) || defined(BOOST_GEOMETRY_DEBUG_ROBUSTNESS)
0150     inline void debug() const
0151     {
0152         std::cout << sides[0].first << " "
0153             << sides[0].second << " "
0154             << sides[1].first << " "
0155             << sides[1].second
0156             << std::endl;
0157     }
0158 #endif
0159 
0160     inline void reverse()
0161     {
0162         std::swap(sides[0], sides[1]);
0163     }
0164 
0165 //private :
0166     std::pair<int, int> sides[2];
0167 
0168 };
0169 
0170 #if defined(_MSC_VER)
0171 #pragma warning(pop)
0172 #endif
0173 
0174 }} // namespace boost::geometry
0175 
0176 
0177 #endif // BOOST_GEOMETRY_STRATEGIES_SIDE_INFO_HPP