[geometry]: [extensions] fixed/added tests for nsphere. [index] added nsphere to benchmark_experimental.cpp (for now commented out).

[SVN r84853]
This commit is contained in:
Adam Wulkiewicz 2013-06-20 21:42:23 +00:00
parent f0b813285f
commit f7c5895e5c
7 changed files with 147 additions and 15 deletions

View File

@ -18,6 +18,9 @@ test-suite boost-geometry-extensions-nsphere
[ run point_type.cpp ]
[ run within.cpp ]
[ run nsphere_in_box.cpp ]
[ run point_in_nsphere.cpp ]
[ run disjoint.cpp ]
[ run index_content.cpp ]
[ run index_margin.cpp ]

View File

@ -12,8 +12,7 @@
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/extensions/nsphere/algorithms/area.hpp>
#include <boost/geometry/extensions/nsphere/geometries/nsphere.hpp>
#include <boost/geometry/extensions/nsphere/nsphere.hpp>
template <typename P, typename T>
@ -21,9 +20,9 @@ void test_area_circle()
{
bg::model::nsphere<P, T> c;
bg::set<0>(c.center(), 0);
bg::set<1>(c.center(), 0);
c.radius(2);
bg::set<0>(c, 0);
bg::set<1>(c, 0);
bg::set_radius<0>(c, 2);
double d = bg::area(c);
BOOST_CHECK_CLOSE(d, 4 * 3.1415926535897932384626433832795, 0.001);

View File

@ -10,9 +10,7 @@
#include <geometry_test_common.hpp>
#include <boost/geometry/extensions/nsphere/core/access.hpp>
#include <boost/geometry/extensions/nsphere/geometries/concepts/nsphere_concept.hpp>
#include <boost/geometry/extensions/nsphere/geometries/nsphere.hpp>
#include <boost/geometry/extensions/nsphere/nsphere.hpp>
#include <boost/geometry/algorithms/detail/assign_values.hpp>
#include <boost/geometry/core/cs.hpp>

View File

@ -0,0 +1,63 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
//
// 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)
#include <geometry_test_common.hpp>
#include <boost/geometry/extensions/nsphere/nsphere.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/io/wkt/read.hpp>
typedef bg::model::d2::point_xy<double> point_type;
typedef bg::model::nsphere<point_type, double> circle_type;
typedef bg::model::box<point_type> box_type;
template <typename Geometry>
void test_circle(std::string const& wkt_geometry, bool expected_within, bool expected_covered_by)
{
circle_type circle(point_type(1.0, 1.0), 3.0);
//bg::assign(circle, 1.0, 1.0, 3.0);
Geometry geometry;
bg::read_wkt(wkt_geometry, geometry);
bool detected = bg::within(circle, geometry);
BOOST_CHECK_MESSAGE(detected == expected_within,
"circle (1,1) with radius 3 within : " << wkt_geometry
<< " -> Expected: " << expected_within
<< " detected: " << detected);
detected = bg::covered_by(circle, geometry);
BOOST_CHECK_MESSAGE(detected == expected_covered_by,
"circle (1,1) with radius 3 covered_by : " << wkt_geometry
<< " -> Expected: " << expected_covered_by
<< " detected: " << detected);
}
void test_circles()
{
test_circle<box_type>("BOX(1 1, 1.1 1.1)", false, false);
test_circle<box_type>("BOX(2 1, 4 4)", false, false);
test_circle<box_type>("BOX(-2 -2, 4 4)", false, true);
test_circle<box_type>("BOX(-2.1 -2.1, 4.1 4.1)", true, true);
}
int test_main( int , char* [] )
{
test_circles();
return 0;
}

View File

@ -0,0 +1,61 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
//
// 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)
#include <geometry_test_common.hpp>
#include <boost/geometry/extensions/nsphere/nsphere.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/io/wkt/read.hpp>
typedef bg::model::d2::point_xy<double> point_type;
typedef bg::model::nsphere<point_type, double> circle_type;
template <typename Geometry>
void test_circle(std::string const& wkt_geometry, bool expected_within, bool expected_covered_by)
{
circle_type circle(point_type(1.0, 1.0), 3.0);
Geometry geometry;
bg::read_wkt(wkt_geometry, geometry);
bool detected = bg::within(geometry, circle);
BOOST_CHECK_MESSAGE(detected == expected_within,
"circle (1,1) with radius 3 containing : " << wkt_geometry
<< " -> Expected: " << expected_within
<< " detected: " << detected);
detected = bg::covered_by(geometry, circle);
BOOST_CHECK_MESSAGE(detected == expected_covered_by,
"circle (1,1) with radius 3 covering : " << wkt_geometry
<< " -> Expected: " << expected_covered_by
<< " detected: " << detected);
}
void test_circles()
{
test_circle<point_type>("POINT(1 1)", true, true);
test_circle<point_type>("POINT(1 4)", false, true);
test_circle<point_type>("POINT(4 1)", false, true);
test_circle<point_type>("POINT(4 4)", false, false);
}
int test_main( int , char* [] )
{
test_circles();
return 0;
}

View File

@ -22,12 +22,11 @@ void test_circle(std::string const& wkt_geometry, bool expected)
{
typedef bg::model::nsphere<bg::model::d2::point_xy<double>, double> circle_type;
circle_type circle;
bg::assign(circle, 1.0, 1.0, 3.0);
bg::assign_values(circle, 1.0, 1.0, 3.0);
Geometry geometry;
bg::read_wkt(wkt_geometry, geometry);
/* todo: fix
bool detected = bg::within(geometry, circle);
BOOST_CHECK_MESSAGE(detected == expected,
@ -35,7 +34,6 @@ void test_circle(std::string const& wkt_geometry, bool expected)
<< " in circle (1,1) with radius 3"
<< " -> Expected: " << expected
<< " detected: " << detected);
*/
}
@ -47,8 +45,8 @@ void test_circles()
test_circle<P>("POINT(2 1)", true);
test_circle<P>("POINT(12 1)", false);
test_circle<bg::model::linestring<P> >("LINESTRING(1 1,2 1,2 2)", true);
test_circle<bg::model::linestring<P> >("LINESTRING(1 1,2 1,2 2,10 10)", false);
//test_circle<bg::model::linestring<P> >("LINESTRING(1 1,2 1,2 2)", true);
//test_circle<bg::model::linestring<P> >("LINESTRING(1 1,2 1,2 2,10 10)", false);
}

View File

@ -45,6 +45,16 @@ struct generate_value<P>
static inline P apply(float x, float y) { return P(x, y); }
};
//#include <boost/geometry/extensions/nsphere/nsphere.hpp>
//typedef bg::model::nsphere<P, double> NS;
//typedef NS V;
//
//template <>
//struct generate_value<NS>
//{
// static inline NS apply(float x, float y) { return NS(P(x, y), 0.5); }
//};
template <typename I1, typename I2, typename O>
void mycopy(I1 first, I2 last, O o)
{
@ -101,9 +111,9 @@ int main()
std::cout << "randomized\n";
}
//typedef bgi::rtree<V, bgi::linear<16, 4> > RT;
typedef bgi::rtree<V, bgi::linear<16, 4> > RT;
//typedef bgi::rtree<V, bgi::quadratic<16, 4> > RT;
typedef bgi::rtree<V, bgi::rstar<16, 4> > RT;
//typedef bgi::rtree<V, bgi::rstar<16, 4> > RT;
std::cout << "sizeof rtree: " << sizeof(RT) << std::endl;