1 // Boost.Geometry
2
3 // Copyright (c) 2015 Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #include <geometry_test_common.hpp>
12
13 #include <boost/geometry/geometries/geometries.hpp>
14 #include <boost/geometry/geometries/point_xy.hpp>
15
16 #include <boost/range/value_type.hpp>
17 #include <boost/type_traits/is_same.hpp>
18
19 template <typename Container>
20 struct pusher
21 : public Container
22 {
23 typedef typename Container::value_type value_type;
pusherpusher24 pusher(value_type const& val)
25 {
26 this->push_back(val);
27 }
28
operator ()pusher29 pusher & operator()(value_type const& val)
30 {
31 this->push_back(val);
32 return *this;
33 }
34 };
35
36 template <typename Geometry,
37 typename Tag = typename bg::tag<Geometry>::type,
38 typename Coord = typename bg::coordinate_type<Geometry>::type>
39 struct nan_case_generator
40 {
applynan_case_generator41 static void apply(Geometry & , std::string & )
42 {}
43 };
44
45 template <typename Geometry>
46 struct nan_case_generator<Geometry, bg::multi_linestring_tag, double>
47 {
applynan_case_generator48 static void apply(Geometry & geometry, std::string & wkt)
49 {
50 typedef typename boost::range_value<Geometry>::type ls;
51 typedef typename bg::point_type<Geometry>::type P;
52 typedef typename bg::coordinate_type<Geometry>::type coord_t;
53 coord_t nan = std::numeric_limits<coord_t>::quiet_NaN();
54
55 wkt = "MULTILINESTRING((3.1e+307 1,-nan -nan),(3.1e+307 1,-nan -nan),(3.1e+307 1,5.1e+307 6e+307,nan nan),(-nan -nan,nan nan),(-nan -nan,-1 -3.97843,-1 3.28571,-1 47.6364),(3 78.5455,3 2),(nan nan,3 12.9689),(3 -2,-nan -nan),(3 2,3 12.9689,3 78.5455),(-1 4.29497e+09,-1 7,-nan -nan),(9 5,-nan -nan),(-nan -nan,9 60.8755,9 124.909),(nan nan,1 6.87195e+10,-nan -nan),(nan nan,4 86.2727,4 20.9533),(4 -5,-nan -nan),(4 -5,-nan -nan),(4 -5,-nan -nan),(4 -5,1.1e+308 2.1e+307,nan nan),(-nan -nan,-1 -8),(-nan -nan,-9 -4))";
56
57 typedef pusher<Geometry> ml;
58 typedef pusher<ls> l;
59 geometry = ml(l(P(3.1e+307, 1))(P(-nan, -nan)))
60 (l(P(3.1e+307, 1))(P(-nan, -nan)))
61 (l(P(3.1e+307, 1))(P(5.1e+307, 6e+307))(P(nan, nan)))
62 (l(P(-nan, -nan))(P(nan, nan)))
63 (l(P(-nan, -nan))(P(-1, -3.97843))(P(-1, 3.28571))(P(-1, 47.6364)))
64 (l(P(3, 78.5455))(P(3, 2)))
65 (l(P(nan, nan))(P(3, 12.9689)))
66 (l(P(3, -2))(P(-nan, -nan)))
67 (l(P(3, 2))(P(3, 12.9689))(P(3, 78.5455)))
68 (l(P(-1, 4.29497e+09))(P(-1, 7))(P(-nan, -nan)))
69 (l(P(9, 5))(P(-nan, -nan)))
70 (l(P(-nan, -nan))(P(9, 60.8755))(P(9, 124.909)))
71 (l(P(nan, nan))(P(1, 6.87195e+10))(P(-nan, -nan)))
72 (l(P(nan, nan))(P(4, 86.2727))(P(4, 20.9533)))
73 (l(P(4, -5))(P(-nan, -nan)))
74 (l(P(4, -5))(P(-nan, -nan)))
75 (l(P(4, -5))(P(-nan, -nan)))
76 (l(P(4, -5))(P(1.1e+308, 2.1e+307))(P(nan, nan)))
77 (l(P(-nan, -nan))(P(-1, -8)))
78 (l(P(-nan, -nan))(P(-9, -4)));
79 }
80 };
81
82 template <typename Geometry>
83 struct nan_case_generator<Geometry, bg::multi_point_tag, double>
84 {
applynan_case_generator85 static void apply(Geometry & geometry, std::string & wkt)
86 {
87 typedef typename bg::point_type<Geometry>::type P;
88 typedef typename bg::coordinate_type<Geometry>::type coord_t;
89 coord_t nan = std::numeric_limits<coord_t>::quiet_NaN();
90
91 wkt = "MULTIPOINT((3.1e+307 1),(-nan -nan),(3.1e+307 1),(-nan -nan),(3.1e+307 1),(5.1e+307 6e+307),(nan nan),(-nan -nan),(nan nan),(-nan -nan),(-1 -3.97843),(-1 3.28571),(-1 47.6364),(3 78.5455),(3 2),(nan nan),(3 12.9689),(3 -2),(-nan -nan),(3 2),(3 12.9689),(3 78.5455),(-1 4.29497e+09),(-1 7),(-nan -nan),(9 5),(-nan -nan),(-nan -nan),(9 60.8755),(9 124.909),(nan nan),(1 6.87195e+10),(-nan -nan),(nan nan),(4 86.2727),(4 20.9533),(4 -5),(-nan -nan),(4 -5),(-nan -nan),(4 -5),(-nan -nan),(4 -5),(1.1e+308 2.1e+307),(nan nan),(-nan -nan),(-1 -8),(-nan -nan),(-9 -4))";
92
93 typedef pusher<Geometry> mp;
94 geometry = mp(P(3.1e+307, 1))(P(-nan, -nan))
95 (P(3.1e+307, 1))(P(-nan, -nan))
96 (P(3.1e+307, 1))(P(5.1e+307, 6e+307))(P(nan, nan))
97 (P(-nan, -nan))(P(nan, nan))
98 (P(-nan, -nan))(P(-1, -3.97843))(P(-1, 3.28571))(P(-1, 47.6364))
99 (P(3, 78.5455))(P(3, 2))
100 (P(nan, nan))(P(3, 12.9689))
101 (P(3, -2))(P(-nan, -nan))
102 (P(3, 2))(P(3, 12.9689))(P(3, 78.5455))
103 (P(-1, 4.29497e+09))(P(-1, 7))(P(-nan, -nan))
104 (P(9, 5))(P(-nan, -nan))
105 (P(-nan, -nan))(P(9, 60.8755))(P(9, 124.909))
106 (P(nan, nan))(P(1, 6.87195e+10))(P(-nan, -nan))
107 (P(nan, nan))(P(4, 86.2727))(P(4, 20.9533))
108 (P(4, -5))(P(-nan, -nan))
109 (P(4, -5))(P(-nan, -nan))
110 (P(4, -5))(P(-nan, -nan))
111 (P(4, -5))(P(1.1e+308, 2.1e+307))(P(nan, nan))
112 (P(-nan, -nan))(P(-1, -8))
113 (P(-nan, -nan))(P(-9, -4));
114 }
115 };
116
117 template <typename Geometry>
nan_case(Geometry & geometry,std::string & wkt)118 void nan_case(Geometry & geometry, std::string & wkt)
119 {
120 nan_case_generator<Geometry>::apply(geometry, wkt);
121 }
122
123 template <typename Geometry>
124 struct is_nan_case_supported
125 {
126 typedef typename bg::coordinate_type<Geometry>::type coord_t;
127
128 static const bool value = boost::is_same<coord_t, double>::value
129 && std::numeric_limits<coord_t>::has_quiet_NaN;
130 };
131