Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:32:21

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