[test][overlaps] Add Box/Box case testing machine epsilon handling.

This commit is contained in:
Adam Wulkiewicz
2015-08-05 01:11:34 +02:00
parent 5e3a5e9d0e
commit e20af985e5
2 changed files with 43 additions and 10 deletions

View File

@@ -43,6 +43,20 @@ void test_3d()
test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1 1, 3 3 3)", "BOX(4 4 4,6 6 6)", false);
}
template <typename P>
void test_eps()
{
typedef typename bg::coordinate_type<P>::type coord_type;
coord_type const eps = std::numeric_limits<coord_type>::epsilon();
bg::model::box<P> b1(P(0, 0), P(1, 1));
bg::model::box<P> b2(P(-1, -1), P(eps/2, eps/2));
test_geometry(b1, b2,
"box(P(0, 0), P(1, 1))", "box(P(-1, -1), P(eps/2, eps/2))",
false);
}
template <typename P>
void test_2d()
{
@@ -53,9 +67,11 @@ int test_main( int , char* [] )
{
test_2d<bg::model::d2::point_xy<int> >();
test_2d<bg::model::d2::point_xy<double> >();
test_eps<bg::model::d2::point_xy<double> >();
#if defined(HAVE_TTMATH)
test_2d<bg::model::d2::point_xy<ttmath_big> >();
test_eps<bg::model::d2::point_xy<ttmath_big> >();
#endif
//test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();

View File

@@ -2,6 +2,12 @@
// Unit Test
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2015.
// Modifications copyright (c) 2015 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -22,15 +28,12 @@
template <typename Geometry1, typename Geometry2>
void test_geometry(std::string const& wkt1,
std::string const& wkt2, bool expected)
void test_geometry(Geometry1 const& geometry1,
Geometry2 const& geometry2,
std::string const& wkt1,
std::string const& wkt2,
bool expected)
{
Geometry1 geometry1;
Geometry2 geometry2;
bg::read_wkt(wkt1, geometry1);
bg::read_wkt(wkt2, geometry2);
bool detected = bg::overlaps(geometry1, geometry2);
BOOST_CHECK_MESSAGE(detected == expected,
@@ -42,11 +45,25 @@ void test_geometry(std::string const& wkt1,
detected = bg::overlaps(geometry2, geometry1);
BOOST_CHECK_MESSAGE(detected == expected,
"overlaps: " << wkt1
<< " with " << wkt2
"overlaps: " << wkt2
<< " with " << wkt1
<< " -> Expected: " << expected
<< " detected: " << detected);
}
template <typename Geometry1, typename Geometry2>
void test_geometry(std::string const& wkt1,
std::string const& wkt2,
bool expected)
{
Geometry1 geometry1;
Geometry2 geometry2;
bg::read_wkt(wkt1, geometry1);
bg::read_wkt(wkt2, geometry2);
test_geometry(geometry1, geometry2, wkt1, wkt2, expected);
}
#endif