1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // This file was modified by Oracle on 2018.
8 // Modifications copyright (c) 2018, Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_POLY_CROSSINGS_MULTIPLY_HPP
20 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_POLY_CROSSINGS_MULTIPLY_HPP
23 #include <boost/geometry/core/access.hpp>
24 #include <boost/geometry/core/coordinate_type.hpp>
25 #include <boost/geometry/util/select_calculation_type.hpp>
28 namespace boost { namespace geometry
31 namespace strategy { namespace within
35 \brief Within detection using cross counting,
37 \tparam Point \tparam_point
38 \tparam PointOfSegment \tparam_segment_point
39 \tparam CalculationType \tparam_calculation
40 \see http://tog.acm.org/resources/GraphicsGems/gemsiv/ptpoly_haines/ptinpoly.c
41 \note Does NOT work correctly for point ON border
44 [link geometry.reference.algorithms.within.within_3_with_strategy within (with strategy)]
51 typename PointOfSegment = Point,
52 typename CalculationType = void
54 class crossings_multiply
56 typedef typename select_calculation_type
61 >::type calculation_type;
71 friend class crossings_multiply;
82 typedef Point point_type;
83 typedef PointOfSegment segment_point_type;
84 typedef flags state_type;
86 static inline bool apply(Point const& point,
87 PointOfSegment const& seg1, PointOfSegment const& seg2,
90 calculation_type const tx = get<0>(point);
91 calculation_type const ty = get<1>(point);
92 calculation_type const x0 = get<0>(seg1);
93 calculation_type const y0 = get<1>(seg1);
94 calculation_type const x1 = get<0>(seg2);
95 calculation_type const y1 = get<1>(seg2);
100 state.yflag0 = y0 >= ty;
104 bool yflag1 = y1 >= ty;
105 if (state.yflag0 != yflag1)
107 if ( ((y1-ty) * (x0-x1) >= (x1-tx) * (y0-y1)) == yflag1 )
109 state.inside_flag = ! state.inside_flag;
112 state.yflag0 = yflag1;
116 static inline int result(flags const& state)
118 return state.inside_flag ? 1 : -1;
124 }} // namespace strategy::within
127 }} // namespace boost::geometry
130 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_POLY_CROSSINGS_MULTIPLY_HPP
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams