mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-11 13:34:10 +00:00
[test][centroid] Add test for very long Linestring for which the centroid cannot be calculated.
This commit is contained in:
parent
a7d8da4249
commit
9f5608d5e9
@ -82,6 +82,31 @@ void test_2d()
|
||||
test_centroid<bg::model::linestring<P> >("LINESTRING(1 1, 1 1)", 1.0, 1.0);
|
||||
test_centroid<bg::model::linestring<P> >("LINESTRING(1 1)", 1.0, 1.0);
|
||||
|
||||
{
|
||||
bg::model::linestring<P> ls;
|
||||
// LINESTRING(1 -1,1e308 -1e308,0.0001 0.000)
|
||||
bg::append(ls, P(1, -1));
|
||||
typedef typename bg::coordinate_type<P>::type coord_type;
|
||||
//double m = 1.0e308;
|
||||
coord_type m = (std::numeric_limits<coord_type>::max)();
|
||||
bg::append(ls, P(coord_type(m), coord_type(-m)));
|
||||
bg::append(ls, P(coord_type(0.0001), coord_type(0.000)));
|
||||
if (BOOST_GEOMETRY_CONDITION((boost::is_same<typename bg::coordinate_type<P>::type, double>::value)))
|
||||
{
|
||||
// for doubles the INF is detected and the calculation stopped
|
||||
// currently for Geometries for which the centroid can't be calculated
|
||||
// the first Point is returned
|
||||
test_centroid<bg::model::linestring<P> >(ls, 1.0, -1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// for floats internally the double is used to store intermediate results
|
||||
// this type is capable to store MAX_FLT and "correctly" calculate the centroid
|
||||
// test_centroid<bg::model::linestring<P> >(ls, m/3, -m/3);
|
||||
// the result is around (1.7e38 -1.7e38)
|
||||
}
|
||||
}
|
||||
|
||||
test_centroid<bg::model::segment<P> >("LINESTRING(1 1, 3 3)", 2.0, 2.0);
|
||||
|
||||
test_centroid<bg::model::ring<P> >(
|
||||
|
@ -60,11 +60,8 @@ void test_with_other_calculation_type(Geometry const& geometry, Point& c1)
|
||||
}
|
||||
|
||||
template <typename Geometry, typename Point, typename T>
|
||||
void test_centroid(std::string const& wkt, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
|
||||
void test_centroid(Geometry const& geometry, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
|
||||
{
|
||||
Geometry geometry;
|
||||
bg::read_wkt(wkt, geometry);
|
||||
|
||||
Point c1;
|
||||
|
||||
bg::centroid(geometry, c1);
|
||||
@ -86,6 +83,21 @@ void test_centroid(std::string const& wkt, T const& d1, T const& d2, T const& d3
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename Geometry, typename Point, typename T>
|
||||
void test_centroid(std::string const& wkt, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
|
||||
{
|
||||
Geometry geometry;
|
||||
bg::read_wkt(wkt, geometry);
|
||||
|
||||
test_centroid<Geometry, Point>(geometry, d1, d2, d3, d4, d5);
|
||||
}
|
||||
|
||||
template <typename Geometry, typename T>
|
||||
void test_centroid(Geometry const& geometry, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
|
||||
{
|
||||
test_centroid<Geometry, typename bg::point_type<Geometry>::type>(geometry, d1, d2, d3, d4, d5);
|
||||
}
|
||||
|
||||
template <typename Geometry, typename T>
|
||||
void test_centroid(std::string const& wkt, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user