2012-08-22 20:33:24 +00:00
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
|
|
|
#include <iostream>
|
2015-03-24 12:32:05 +00:00
|
|
|
#include <mapnik/geometry.hpp>
|
2015-03-11 17:16:22 +00:00
|
|
|
#include <mapnik/geometry_adapters.hpp>
|
|
|
|
#include <mapnik/geometry_centroid.hpp>
|
2013-05-25 00:21:55 +00:00
|
|
|
#include <vector>
|
2013-05-25 23:04:40 +00:00
|
|
|
#include <algorithm>
|
2012-08-22 20:33:24 +00:00
|
|
|
|
2013-05-25 00:21:55 +00:00
|
|
|
int main(int argc, char** argv)
|
2012-08-22 20:33:24 +00:00
|
|
|
{
|
2013-05-25 00:21:55 +00: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();
|
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// reused these for simplicity
|
2015-03-24 13:21:28 +00:00
|
|
|
mapnik::geometry::point centroid;
|
2015-02-06 15:45:51 +00:00
|
|
|
{
|
2015-03-11 17:16:22 +00:00
|
|
|
// single point
|
2015-03-24 13:21:28 +00:00
|
|
|
mapnik::geometry::point pt(10,10);
|
|
|
|
BOOST_TEST( mapnik::geometry::centroid(pt, centroid));
|
2015-03-11 17:16:22 +00:00
|
|
|
BOOST_TEST( pt.x == centroid.x);
|
|
|
|
BOOST_TEST( pt.y == centroid.y);
|
2015-02-06 15:45:51 +00:00
|
|
|
}
|
2015-03-11 17:16:22 +00:00
|
|
|
|
|
|
|
// linestring with three consecutive verticies
|
2015-02-06 15:45:51 +00:00
|
|
|
{
|
2015-03-24 13:21:28 +00:00
|
|
|
mapnik::geometry::line_string line;
|
2015-03-11 17:16:22 +00:00
|
|
|
line.add_coord(0, 0);
|
|
|
|
line.add_coord(25, 25);
|
|
|
|
line.add_coord(50, 50);
|
2015-03-24 13:21:28 +00:00
|
|
|
BOOST_TEST(mapnik::geometry::centroid(line, centroid));
|
2015-03-11 17:16:22 +00:00
|
|
|
BOOST_TEST( centroid.x == 25 );
|
|
|
|
BOOST_TEST( centroid.y == 25 );
|
2015-02-06 15:45:51 +00:00
|
|
|
}
|
2014-10-21 02:55:11 +00: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)))
|
2015-03-11 17:16:22 +00:00
|
|
|
#if 0
|
2014-10-21 02:55:11 +00:00
|
|
|
// hit tests
|
2015-02-06 15:45:51 +00:00
|
|
|
{
|
2015-03-24 13:21:28 +00:00
|
|
|
mapnik::geometry_type pt_hit(mapnik::geometry::geometry_types::Point);
|
2015-02-06 15:45:51 +00:00
|
|
|
pt_hit.move_to(10,10);
|
|
|
|
mapnik::vertex_adapter va(pt_hit);
|
|
|
|
BOOST_TEST( mapnik::label::hit_test(va, 10, 10, 0.1) );
|
|
|
|
BOOST_TEST( !mapnik::label::hit_test(va, 9, 9, 0) );
|
|
|
|
BOOST_TEST( mapnik::label::hit_test(va, 9, 9, 1.5) );
|
|
|
|
}
|
|
|
|
{
|
2015-03-24 13:21:28 +00:00
|
|
|
mapnik::geometry_type line_hit(mapnik::geometry::geometry_types::LineString);
|
2015-02-06 15:45:51 +00:00
|
|
|
line_hit.move_to(0,0);
|
|
|
|
line_hit.line_to(50,50);
|
|
|
|
mapnik::vertex_adapter va(line_hit);
|
|
|
|
BOOST_TEST( mapnik::label::hit_test(va, 0, 0, 0.001) );
|
|
|
|
BOOST_TEST( !mapnik::label::hit_test(va, 1, 1, 0) );
|
|
|
|
BOOST_TEST( mapnik::label::hit_test(va, 1, 1, 1.001) );
|
|
|
|
}
|
2015-03-11 17:16:22 +00:00
|
|
|
#endif
|
2014-10-21 02:55:11 +00:00
|
|
|
}
|
|
|
|
catch (std::exception const & ex)
|
|
|
|
{
|
|
|
|
std::clog << ex.what() << "\n";
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2013-11-20 04:01:34 +00:00
|
|
|
|
2012-08-22 20:33:24 +00:00
|
|
|
if (!::boost::detail::test_errors()) {
|
2013-05-25 00:21:55 +00: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 20:33:24 +00:00
|
|
|
::boost::detail::report_errors_remind().called_report_errors_function = true;
|
|
|
|
} else {
|
|
|
|
return ::boost::report_errors();
|
|
|
|
}
|
|
|
|
}
|