2012-08-22 22:33:24 +02:00
|
|
|
#include <boost/version.hpp>
|
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
#include <mapnik/geometry.hpp>
|
|
|
|
#include <mapnik/geom_util.hpp>
|
2013-05-25 02:21:55 +02:00
|
|
|
#include <vector>
|
2013-05-26 01:04:40 +02:00
|
|
|
#include <algorithm>
|
2012-08-22 22:33:24 +02:00
|
|
|
|
2013-05-25 02:21:55 +02:00
|
|
|
int main(int argc, char** argv)
|
2012-08-22 22:33:24 +02:00
|
|
|
{
|
2013-05-25 02:21:55 +02:00
|
|
|
std::vector<std::string> args;
|
|
|
|
for (int i=1;i<argc;++i)
|
|
|
|
{
|
|
|
|
args.push_back(argv[i]);
|
|
|
|
}
|
|
|
|
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
|
|
|
|
2012-08-22 22:33:24 +02:00
|
|
|
// reused these for simplicity
|
|
|
|
double x,y;
|
|
|
|
|
|
|
|
// single point
|
2013-09-20 05:19:01 +02:00
|
|
|
mapnik::geometry_type pt(mapnik::geometry_type::types::Point);
|
2012-08-22 22:33:24 +02:00
|
|
|
pt.move_to(10,10);
|
|
|
|
BOOST_TEST( mapnik::label::centroid(pt, x, y) );
|
|
|
|
BOOST_TEST( x == 10 );
|
|
|
|
BOOST_TEST( y == 10 );
|
2013-03-15 02:33:59 +01:00
|
|
|
|
2012-08-22 22:33:24 +02:00
|
|
|
// two points
|
|
|
|
pt.move_to(20,20);
|
|
|
|
BOOST_TEST( mapnik::label::centroid(pt, x, y) );
|
|
|
|
BOOST_TEST_EQ( x, 15 );
|
|
|
|
BOOST_TEST_EQ( y, 15 );
|
|
|
|
|
|
|
|
// line with two verticies
|
2013-09-20 05:19:01 +02:00
|
|
|
mapnik::geometry_type line(mapnik::geometry_type::types::LineString);
|
2012-08-22 22:33:24 +02:00
|
|
|
line.move_to(0,0);
|
2013-11-20 05:01:34 +01:00
|
|
|
line.line_to(50,50);
|
2012-08-22 22:33:24 +02:00
|
|
|
BOOST_TEST( mapnik::label::centroid(line, x, y) );
|
|
|
|
BOOST_TEST( x == 25 );
|
|
|
|
BOOST_TEST( y == 25 );
|
2013-03-15 02:33:59 +01:00
|
|
|
|
2012-11-21 02:58:39 +01:00
|
|
|
// TODO - centroid and interior should be equal but they appear not to be (check largest)
|
|
|
|
// MULTIPOLYGON(((-52 40,-60 32,-68 40,-60 48,-52 40)),((-60 50,-80 30,-100 49.9999999999999,-80.0000000000001 70,-60 50)),((-52 60,-60 52,-68 60,-60 68,-52 60)))
|
|
|
|
|
2013-11-20 05:01:34 +01:00
|
|
|
// hit tests
|
2013-11-21 22:23:27 +01:00
|
|
|
mapnik::geometry_type pt_hit(mapnik::geometry_type::types::Point);
|
2013-11-20 05:01:34 +01:00
|
|
|
pt_hit.move_to(10,10);
|
|
|
|
BOOST_TEST( mapnik::label::hit_test(pt_hit, 10, 10, 0.1) );
|
|
|
|
BOOST_TEST( !mapnik::label::hit_test(pt_hit, 9, 9, 0) );
|
|
|
|
BOOST_TEST( mapnik::label::hit_test(pt_hit, 9, 9, 1.5) );
|
2013-11-21 22:23:27 +01:00
|
|
|
mapnik::geometry_type line_hit(mapnik::geometry_type::types::LineString);
|
2013-11-20 05:01:34 +01:00
|
|
|
line_hit.move_to(0,0);
|
|
|
|
line_hit.line_to(50,50);
|
|
|
|
BOOST_TEST( mapnik::label::hit_test(line_hit, 0, 0, 0.001) );
|
|
|
|
BOOST_TEST( !mapnik::label::hit_test(line_hit, 1, 1, 0) );
|
|
|
|
BOOST_TEST( mapnik::label::hit_test(line_hit, 1, 1, 1.001) );
|
|
|
|
|
2012-08-22 22:33:24 +02:00
|
|
|
if (!::boost::detail::test_errors()) {
|
2013-05-25 02:21:55 +02:00
|
|
|
if (quiet) std::clog << "\x1b[1;32m.\x1b[0m";
|
|
|
|
else std::clog << "C++ label algorithms: \x1b[1;32m✓ \x1b[0m\n";
|
2012-08-22 22:33:24 +02:00
|
|
|
#if BOOST_VERSION >= 104600
|
|
|
|
::boost::detail::report_errors_remind().called_report_errors_function = true;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
return ::boost::report_errors();
|
|
|
|
}
|
|
|
|
}
|