// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
-// Copyright (c) 2015-2020, Oracle and/or its affiliates.
+// Copyright (c) 2015-2022, Oracle and/or its affiliates.
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
#include <iostream>
#include <string>
-#include <geometry_test_common.hpp>
-#include <from_wkt.hpp>
-
#include <boost/numeric/conversion/bounds.hpp>
-#include <boost/type_traits/is_same.hpp>
+#include <from_wkt.hpp>
+#include <geometry_test_common.hpp>
+#include "test_envelope_expand_on_spheroid.hpp"
+
+#include <boost/geometry/algorithms/convert.hpp>
+#include <boost/geometry/algorithms/envelope.hpp>
+#include <boost/geometry/algorithms/reverse.hpp>
#include <boost/geometry/core/coordinate_dimension.hpp>
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>
-
#include <boost/geometry/geometries/geometries.hpp>
-
-#include <boost/geometry/util/condition.hpp>
-
+#include <boost/geometry/index/detail/algorithms/is_valid.hpp>
#include <boost/geometry/io/dsv/write.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
-
-#include <boost/geometry/algorithms/convert.hpp>
-#include <boost/geometry/algorithms/envelope.hpp>
-#include <boost/geometry/algorithms/reverse.hpp>
-
-#include <boost/geometry/index/detail/algorithms/is_valid.hpp>
-
-#include "test_envelope_expand_on_spheroid.hpp"
-
-//TEMP
-#include <boost/geometry/strategies/envelope/geographic.hpp>
-#include <boost/geometry/strategies/envelope/spherical.hpp>
+#include <boost/geometry/util/condition.hpp>
+#include <boost/geometry/util/type_traits.hpp>
template <typename FormulaPolicy, typename CS_Tag>
typedef bg::strategy::envelope::spherical_box box_strategy_t;
typedef bg::strategy::envelope::geographic<FormulaPolicy, bg::srs::spheroid<double>, double> strategy_t;
- typename boost::mpl::if_c
+ std::conditional_t
<
- boost::is_same<typename bg::tag<Geometry>::type, bg::point_tag>::value,
+ std::is_same<typename bg::tag<Geometry>::type, bg::point_tag>::value,
point_strategy_t,
- typename boost::mpl::if_c
+ std::conditional_t
<
- boost::is_same<typename bg::tag<Geometry>::type, bg::multi_point_tag>::value,
+ std::is_same<typename bg::tag<Geometry>::type, bg::multi_point_tag>::value,
multi_point_strategy_t,
- typename boost::mpl::if_c
+ std::conditional_t
<
- boost::is_same<typename bg::tag<Geometry>::type, bg::box_tag>::value,
+ std::is_same<typename bg::tag<Geometry>::type, bg::box_tag>::value,
box_strategy_t,
strategy_t
- >::type
- >::type
- >::type strategy;
+ >
+ >
+ > strategy;
bg::envelope(geometry, detected, strategy);
}
// test the reverse of a geometry if it is either linear or ring
-template <typename Geometry, typename Tag = typename bg::tag<Geometry>::type>
+template <typename Geometry>
struct test_reverse_geometry
{
- static bool const is_linear =
- boost::is_same<Tag, bg::segment_tag>::value
- || boost::is_same<Tag, bg::linestring_tag>::value
- || boost::is_same<Tag, bg::multi_linestring_tag>::value;
+ static bool const is_linear = bg::util::is_linear<Geometry>::value;
// currently disable rings
static bool const is_ring = false;
- // static bool const is_ring = boost::is_same<Tag, bg::ring_tag>::value;
+ // static bool const is_ring = bg::util::is_ring<Geometry>::value;
- typedef typename boost::mpl::if_c
- <
- is_linear || is_ring,
- boost::true_type,
- boost::false_type
- >::type type;
-
- static bool const value = type::value;
+ static bool const value = (is_linear || is_ring);
};
template
from_wkt<G>("LINESTRING(-170 0,160 0)"),
160, 0, 190, 0);
+ // https://github.com/boostorg/geometry/issues/935
+ tester::apply("github_issue_935",
+ from_wkt<G>("LINESTRING(4.5055430885891123e-05 -2.7518149670422367e-06,\
+ 4.5055130529987143e-05 8.2400127103300943e-07,\
+ 4.5054830174083163e-05 4.3998175091082556e-06)"),
+ 4.5054830174083163e-05, -2.7518149670422367e-06,
+ 4.5055430885891123e-05, 4.3998175091082556e-06);
+
+
double eps = std::numeric_limits<double>::epsilon();
double heps = eps / 2;
from_wkt<G>("LINESTRING(-170 0,160 0)"),
160, 0, 190, 0);
+ // https://github.com/boostorg/geometry/issues/935
+ tester::apply("github_issue_935",
+ from_wkt<G>("LINESTRING(4.5055430885891123e-05 -2.7518149670422367e-06,\
+ 4.5055130529987143e-05 8.2400127103300943e-07,\
+ 4.5054830174083163e-05 4.3998175091082556e-06)"),
+ 4.5054830174083163e-05, -2.7518149670422367e-06,
+ 4.5055430885891123e-05, 4.3998175091082556e-06);
+
double eps = std::numeric_limits<double>::epsilon();
double heps = eps / 2;
typedef bg::model::box<point_type> B;
typedef test_envelope_on_sphere_or_spheroid<G, B> tester;
- //double const eps = std::numeric_limits<double>::epsilon();
+ double const eps = std::numeric_limits<double>::epsilon();
tester::apply("r01cw",
from_wkt<G>("POLYGON((0 10,0 45,50 10,0 10))"),
0, 10, 50, 45);
-#if 0
+
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that contains both the north and south poles in its interior
tester::apply("r01cw-r",
from_wkt<G>("POLYGON((0 10,50 10,0 45,0 10))"),
-180, -90, 180, 90);
+#endif
// ring that contains the north pole in its interior
tester::apply("r02cw",
-180, -90, 180, -10);
// -180, -19.42540014068282, 180, 90);
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that has the north pole as vertex and contains the south pole
tester::apply("r04cw",
from_wkt<G>("POLYGON((0 0,-50 90,-50 0,0 0))"),
-180, -90, 180, 90);
+#endif
// ring that has the north pole as vertex
tester::apply("r04cw-r",
from_wkt<G>("POLYGON((0 0,-50 0,-50 90,0 0))"),
-50, 0, 0, 90);
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that goes through the south pole and contains the north pole
tester::apply("r09cw",
from_wkt<G>("POLYGON((0 0,0 -90,50 0,0 0))"),
-180, -90, 180, 90);
+#endif
// ring that goes through the south pole
tester::apply("r09cw-r",
from_wkt<G>("POLYGON((100 45,0 45,-100 45,-100 90,100 45))"),
-100, 45, 100, 90);
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that represents the complement of a spherical cap
// near the north pole
tester::apply("r13cw-r",
from_wkt<G>("POLYGON((-100 45,0 45,100 45,100 90,-100 45))"),
-180, -90, 180, 90);
+#endif
// ring that represents the complement of a spherical cap
// that touches the south pole
from_wkt<G>("POLYGON((-100 45,0 45,100 45,100 -90,-100 45))"),
-100, -90, 100, 57.26759279038765);
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that represents a spherical cap that touches the south pole
tester::apply("r14cw-r",
from_wkt<G>("POLYGON((100 45,0 45,-100 45,-100 -90,100 45))"),
-180, -90, 180, 90);
+#endif
// ring with edge that goes through the south pole
tester::apply("r15cw",
from_wkt<G>("POLYGON((-50 -80,-50 -40,-30 -40,-30 -80,-50 -80))"),
-50, -80.14892388341609, -30, -40);
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that lies in the lower hemisphere and contains both poles
tester::apply("r16-r",
from_wkt<G>("POLYGON((-50 -80,-30 -80,-30 -40,-50 -40,-50 -80))"),
tester::apply("r17cw",
from_wkt<G>("POLYGON((50 0,50 -90,100 0,50 0))"),
-180, -90, 180, 90);
+#endif
// ring that goes through the south pole
tester::apply("r17cw-r",
from_wkt<G>("POLYGON((50 0,100 0,100 -90,50 0))"),
50, -90, 100, 0);
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that goes through the south pole and contains the north pole
tester::apply("r18cw",
from_wkt<G>("POLYGON((50 0,50 -90,460 0,50 0))"),
-180, -90, 180, 90);
+#endif
// ring that goes through the south pole
tester::apply("r18cw-r",
from_wkt<G>("POLYGON((50 0,460 0,100 -90,50 0))"),
50, -90, 100, 0);
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that goes through the south pole and contains the north pole
tester::apply("r19cw",
from_wkt<G>("POLYGON((50 0,50 -90,-260 0,50 0))"),
-180, -90, 180, 90);
+#endif
// ring that goes through the south pole
tester::apply("r19cw-r",
from_wkt<G>("POLYGON((10 0,10 90,20 0,20 -90,10 0))"),
10, -90, 20, 90); // SUCCEEDS FOR WRONG REASON
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that goes through both poles
tester::apply("r20cw-r",
from_wkt<G>("POLYGON((10 0,10 -90,20 0,20 90,10 0))"),
- -180, -90, 180, 90); // FAILS NOW
+ -180, -90, 180, 90);
+#endif
// ring that goes through both poles and its boundary forms
// a great circle
from_wkt<G>("POLYGON((-10 0,-10 90,170 0,170 -90,-10 0))"),
-10, -90, 170, 90); // SUCCEEDS FOR WRONG REASON
+#ifdef BOOST_GEOMETRY_TEST_ENABLE_FAILING
// ring that goes through both poles and its boundary forms
// a great circle
tester::apply("r21cw-r",
from_wkt<G>("POLYGON((-10 0,-10 -90,170 0,170 90,-10 0))"),
- 170, -90, 350, 90); // FAILS NOW
+ 170, -90, 350, 90);
#endif
+
+ // From disjoint https://svn.boost.org/trac/boost/ticket/9162
+ // Polygons containing poles
+ tester::apply("r22cw",
+ from_wkt<G>("POLYGON((0 80,-90 80,-180 80,90 80,0 80))"),
+ -180, 80, 180, 90);
+ tester::apply("r23cw",
+ from_wkt<G>("POLYGON((0 -80,90 -80,-180 -80,-90 -80,0 -80))"),
+ -180, -90, 180, -80);
+ // Polygons greater than half of the globe
+ tester::apply("r24cw",
+ from_wkt<G>("POLYGON((0 80,90 80,-180 80,-90 80,0 80))"),
+ -180, -90, 180, 82.892923889553458);
+ tester::apply("r25cw",
+ from_wkt<G>("POLYGON((0 -80,-90 -80,-180 -80,90 -80,0 -80))"),
+ -180, -82.892923889553458, 180, 90);
+ // Normal test case
+ tester::apply("r26cw",
+ from_wkt<G>("POLYGON((30 0,30 30,90 30, 90 0, 30 0))"),
+ 30, 0, 90, 33.690067525979771);
+
+ // Invalid polygons with holes containing poles
+ tester::apply("r27cw",
+ from_wkt<G>("POLYGON((),(0 80,90 80,-180 80,-90 80,0 80))"),
+ -180, 80, 180, 90);
+ tester::apply("r28cw",
+ from_wkt<G>("POLYGON((),(0 -80,-90 -80,-180 -80,90 -80,0 -80))"),
+ -180, -90, 180, -80);
}
+BOOST_AUTO_TEST_CASE(envelope_ccw_ring)
+{
+ typedef bg::cs::spherical_equatorial<bg::degree> coordinate_system_type;
+ typedef bg::model::point<double, 2, coordinate_system_type> point_type;
+ typedef bg::model::polygon<point_type, false> G;
+ typedef bg::model::box<point_type> B;
+ typedef test_envelope_on_sphere_or_spheroid<G, B> tester;
+
+ tester::apply("r27ccw",
+ from_wkt<G>("POLYGON((),(0 80,-90 80,-180 80,90 80,0 80))"),
+ -180, 80, 180, 90);
+ tester::apply("r28ccw",
+ from_wkt<G>("POLYGON((),(0 -80,90 -80,-180 -80,-90 -80,0 -80))"),
+ -180, -90, 180, -80);
+}