fix clipping test and drop rule cache tests

This commit is contained in:
Dane Springmeyer 2013-09-18 18:47:28 -07:00
parent 722aa4ae14
commit 7070856f9c
2 changed files with 22 additions and 229 deletions

View file

@ -1 +1 @@
MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))
POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190))

View file

@ -14,7 +14,6 @@
#include <set>
#include <stdexcept>
// boost
#include <boost/version.hpp>
#include <boost/shared_ptr.hpp>
@ -409,205 +408,6 @@ struct test8
}
};
#include <mapnik/rule_cache.hpp>
#if BOOST_VERSION >= 105300
#include <boost/container/vector.hpp>
#include <boost/move/utility.hpp>
class rule_cache_move
{
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(rule_cache_move)
public:
typedef std::vector<rule const*> rule_ptrs;
rule_cache_move()
: if_rules_(),
else_rules_(),
also_rules_() {}
rule_cache_move(BOOST_RV_REF(rule_cache_move) rhs) // move ctor
: if_rules_(boost::move(rhs.if_rules_)),
else_rules_(boost::move(rhs.else_rules_)),
also_rules_(boost::move(rhs.also_rules_))
{}
rule_cache_move& operator=(BOOST_RV_REF(rule_cache_move) rhs) // move assign
{
std::swap(if_rules_, rhs.if_rules_);
std::swap(else_rules_,rhs.else_rules_);
std::swap(also_rules_, rhs.also_rules_);
return *this;
}
void add_rule(rule const& r)
{
if (r.has_else_filter())
{
else_rules_.push_back(&r);
}
else if (r.has_also_filter())
{
also_rules_.push_back(&r);
}
else
{
if_rules_.push_back(&r);
}
}
rule_ptrs const& get_if_rules() const
{
return if_rules_;
}
rule_ptrs const& get_else_rules() const
{
return else_rules_;
}
rule_ptrs const& get_also_rules() const
{
return also_rules_;
}
private:
rule_ptrs if_rules_;
rule_ptrs else_rules_;
rule_ptrs also_rules_;
};
struct test9
{
unsigned iter_;
unsigned threads_;
unsigned num_rules_;
unsigned num_styles_;
std::vector<rule> rules_;
explicit test9(unsigned iterations,
unsigned threads,
unsigned num_rules,
unsigned num_styles) :
iter_(iterations),
threads_(threads),
num_rules_(num_rules),
num_styles_(num_styles),
rules_() {
mapnik::rule r("test");
for (unsigned i=0;i<num_rules_;++i) {
rules_.push_back(r);
}
}
bool validate()
{
return true;
}
void operator()()
{
for (unsigned i=0;i<iter_;++i) {
boost::container::vector<rule_cache_move> rule_caches;
for (unsigned i=0;i<num_styles_;++i) {
rule_cache_move rc;
for (unsigned i=0;i<num_rules_;++i) {
rc.add_rule(rules_[i]);
}
rule_caches.push_back(boost::move(rc));
}
}
}
};
#endif
class rule_cache_heap
{
public:
typedef std::vector<rule const*> rule_ptrs;
rule_cache_heap()
: if_rules_(),
else_rules_(),
also_rules_() {}
void add_rule(rule const& r)
{
if (r.has_else_filter())
{
else_rules_.push_back(&r);
}
else if (r.has_also_filter())
{
also_rules_.push_back(&r);
}
else
{
if_rules_.push_back(&r);
}
}
rule_ptrs const& get_if_rules() const
{
return if_rules_;
}
rule_ptrs const& get_else_rules() const
{
return else_rules_;
}
rule_ptrs const& get_also_rules() const
{
return also_rules_;
}
private:
rule_ptrs if_rules_;
rule_ptrs else_rules_;
rule_ptrs also_rules_;
};
struct test10
{
unsigned iter_;
unsigned threads_;
unsigned num_rules_;
unsigned num_styles_;
std::vector<rule> rules_;
explicit test10(unsigned iterations,
unsigned threads,
unsigned num_rules,
unsigned num_styles) :
iter_(iterations),
threads_(threads),
num_rules_(num_rules),
num_styles_(num_styles),
rules_() {
mapnik::rule r("test");
for (unsigned i=0;i<num_rules_;++i) {
rules_.push_back(r);
}
}
bool validate()
{
return true;
}
void operator()()
{
for (unsigned i=0;i<iter_;++i) {
boost::ptr_vector<rule_cache_heap> rule_caches;
for (unsigned i=0;i<num_styles_;++i) {
std::auto_ptr<rule_cache_heap> rc(new rule_cache_heap);
for (unsigned i=0;i<num_rules_;++i) {
rc->add_rule(rules_[i]);
}
rule_caches.push_back(rc);
}
}
}
};
#include <mapnik/wkt/wkt_factory.hpp>
#include "agg_conv_clipper.h"
#include "agg_path_storage.h"
@ -648,7 +448,8 @@ struct test11
ps.line_to(extent_.maxx(), extent_.maxy());
ps.line_to(extent_.maxx(), extent_.miny());
ps.close_polygon();
for (unsigned i=0;i<iter_;++i) {
for (unsigned i=0;i<iter_;++i)
{
BOOST_FOREACH (geometry_type & geom , paths)
{
poly_clipper clipped(geom,ps,
@ -659,7 +460,7 @@ struct test11
clipped.rewind(0);
unsigned cmd;
double x,y;
while ((cmd = geom.vertex(&x, &y)) != SEG_END) {}
while ((cmd = clipped.vertex(&x, &y)) != SEG_END) {}
}
}
}
@ -704,7 +505,7 @@ struct test12
poly_clipper clipped(extent_, geom);
unsigned cmd;
double x,y;
while ((cmd = geom.vertex(&x, &y)) != SEG_END) {}
while ((cmd = clipped.vertex(&x, &y)) != SEG_END) {}
}
}
}
@ -858,20 +659,16 @@ int main( int argc, char** argv)
benchmark(runner,"expression parsing by re-using grammar");
}
{
#if BOOST_VERSION >= 105300
test9 runner(1000,10,200,50);
benchmark(runner,"rule caching using boost::move");
#else
std::clog << "not running: 'rule caching using boost::move'\n";
#endif
}
// TODO - consider bring back rule cache benchmarks after c++11 is in master
// previously test 9/10
{
test10 runner(1000,10,200,50);
benchmark(runner,"rule caching using heap allocation");
}
// polygon/rect clipping
// IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190))
// RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106))
// OUT (expected)
// POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190))
mapnik::box2d<double> clipping_box(181,106,631,470);
{
std::string filename_("benchmark/data/polygon.wkt");
std::ifstream in(filename_.c_str(),std::ios_base::in | std::ios_base::binary);
@ -879,23 +676,19 @@ int main( int argc, char** argv)
throw std::runtime_error("could not open: '" + filename_ + "'");
std::string wkt_in( (std::istreambuf_iterator<char>(in) ),
(std::istreambuf_iterator<char>()) );
mapnik::box2d<double> clipping_box(0,0,40,40);
test11 runner(100000,10,wkt_in,clipping_box);
test11 runner(10000,10,wkt_in,clipping_box);
benchmark(runner,"clipping polygon with agg_conv_clipper");
}
{
std::string filename_("benchmark/data/polygon.wkt");
std::ifstream in(filename_.c_str(),std::ios_base::in | std::ios_base::binary);
if (!in.is_open())
throw std::runtime_error("could not open: '" + filename_ + "'");
std::string wkt_in( (std::istreambuf_iterator<char>(in) ),
(std::istreambuf_iterator<char>()) );
mapnik::box2d<double> clipping_box(0,0,40,40);
test12 runner(100000,10,wkt_in,clipping_box);
test12 runner(10000,10,wkt_in,clipping_box);
benchmark(runner,"clipping polygon with mapnik::polygon_clipper");
}