cpp_tests : start porting to mapnik-geometry

This commit is contained in:
artemp 2015-03-11 18:16:22 +01:00
parent f72291650b
commit a5d51af51c
5 changed files with 46 additions and 43 deletions

View file

@ -49,9 +49,10 @@ int main(int argc, char** argv)
mapnik::transcoder tr("utf-8");
mapnik::value_unicode_string ustr = tr.transcode("hello world!");
feature->put("name",ustr);
auto pt = std::make_unique<mapnik::geometry_type>(mapnik::new_geometry::geometry_types::Point);
pt->move_to(128,128);
feature->add_geometry(pt.release());
//auto pt = std::make_unique<mapnik::geometry_type>(mapnik::new_geometry::geometry_types::Point);
//pt->move_to(128,128);
mapnik::new_geometry::point pt(128,128);
feature->set_geometry(std::move(pt));
mapnik::parameters params;
params["type"]="memory";

View file

@ -20,7 +20,7 @@
// stl
#include <stdexcept>
#if 0 // FIXME
struct output_geometry_backend
{
output_geometry_backend(mapnik::geometry_container & paths, mapnik::geometry_type::types type)
@ -132,6 +132,8 @@ boost::optional<std::string> polygon_bbox_clipping(mapnik::box2d<double> bbox,
return boost::optional<std::string>();
}
#endif
int main(int argc, char** argv)
{
std::vector<std::string> args;
@ -145,6 +147,7 @@ int main(int argc, char** argv)
try
{
#if 0
// LineString/bbox clipping
{
std::string wkt_in("LineString(0 0,200 200)");
@ -186,7 +189,7 @@ int main(int argc, char** argv)
BOOST_TEST_EQ(*result, std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50))"));
//BOOST_TEST_EQ(*result,std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50,50 50))"));
}
#endif
}
catch (std::exception const & ex)
{

View file

@ -1,7 +1,9 @@
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
#include <mapnik/geometry.hpp>
#include <mapnik/geom_util.hpp>
#include <mapnik/geometry_impl.hpp>
#include <mapnik/geometry_adapters.hpp>
#include <mapnik/geometry_centroid.hpp>
//#include <mapnik/geom_util.hpp>
#include <vector>
#include <algorithm>
@ -17,37 +19,28 @@ int main(int argc, char** argv)
try
{
// reused these for simplicity
double x,y;
mapnik::geometry_type pt(mapnik::new_geometry::geometry_types::Point);
// single point
pt.move_to(10,10);
mapnik::new_geometry::point centroid;
{
mapnik::vertex_adapter va(pt);
BOOST_TEST( mapnik::label::centroid(va, x, y) );
BOOST_TEST( x == 10 );
BOOST_TEST( y == 10 );
// single point
mapnik::new_geometry::point pt(10,10);
BOOST_TEST( mapnik::new_geometry::centroid(pt, centroid));
BOOST_TEST( pt.x == centroid.x);
BOOST_TEST( pt.y == centroid.y);
}
// two points
pt.move_to(20,20);
{
mapnik::vertex_adapter va(pt);
BOOST_TEST( mapnik::label::centroid(va, x, y) );
BOOST_TEST_EQ( x, 15 );
BOOST_TEST_EQ( y, 15 );
}
// line with two verticies
mapnik::geometry_type line(mapnik::new_geometry::geometry_types::LineString);
line.move_to(0,0);
line.line_to(50,50);
mapnik::vertex_adapter va(line);
BOOST_TEST( mapnik::label::centroid(va, x, y) );
BOOST_TEST( x == 25 );
BOOST_TEST( y == 25 );
// linestring with three consecutive verticies
{
mapnik::new_geometry::line_string line;
line.add_coord(0, 0);
line.add_coord(25, 25);
line.add_coord(50, 50);
BOOST_TEST(mapnik::new_geometry::centroid(line, centroid));
BOOST_TEST( centroid.x == 25 );
BOOST_TEST( centroid.y == 25 );
}
// 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)))
#if 0
// hit tests
{
mapnik::geometry_type pt_hit(mapnik::new_geometry::geometry_types::Point);
@ -66,6 +59,7 @@ int main(int argc, char** argv)
BOOST_TEST( !mapnik::label::hit_test(va, 1, 1, 0) );
BOOST_TEST( mapnik::label::hit_test(va, 1, 1, 1.001) );
}
#endif
}
catch (std::exception const & ex)
{

View file

@ -17,6 +17,7 @@
// Convenience method for test cases
void simplify(std::string const& wkt_in, double tolerance, std::string const& method, std::string const& expected)
{
#if 0 // FIXME
//grab the geom
mapnik::geometry_container multi_input;
if (!mapnik::from_wkt(wkt_in , multi_input))
@ -42,6 +43,7 @@ void simplify(std::string const& wkt_in, double tolerance, std::string const& me
std::string wkt_out;
BOOST_TEST(mapnik::to_wkt(multi_out, wkt_out));
BOOST_TEST_EQ(wkt_out, expected);
#endif
}
int main(int argc, char** argv)

View file

@ -3,6 +3,8 @@
#include <mapnik/params.hpp>
#include <mapnik/wkb.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/geometry_is_valid.hpp>
#include <mapnik/geometry_is_simple.hpp>
#include <mapnik/feature_factory.hpp>
#include <vector>
#include <algorithm>
@ -62,17 +64,17 @@ int main(int argc, char** argv)
mapnik::context_ptr ctx(new mapnik::context_type);
mapnik::feature_ptr feature = mapnik::feature_factory::create(ctx, 1);
// test of parsing wks geometries
// test of parsing wkb geometries
try {
// spatialite blob
BOOST_TEST(
mapnik::geometry_utils::from_wkb(feature->paths(),
(const char*)sp_valid_blob,
sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]),
mapnik::wkbSpatiaLite)
);
// spatialite blob
mapnik::new_geometry::geometry geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob,
sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]),
mapnik::wkbSpatiaLite);
BOOST_TEST(mapnik::new_geometry::is_valid(geom) && mapnik::new_geometry::is_simple(geom));
#if 0 // FIXME
BOOST_TEST(
mapnik::geometry_utils::from_wkb(feature->paths(),
(const char*)sp_valid_blob,
@ -108,7 +110,8 @@ int main(int argc, char** argv)
sizeof(sq_invalid_blob) / sizeof(sq_invalid_blob[0]),
mapnik::wkbGeneric) == false
);
#endif
} catch (std::exception const& ex) {
BOOST_TEST(false);
std::clog << "threw: " << ex.what() << "\n";