unit tests: move fake_path to separate file

This commit is contained in:
Jiri Drbalek 2016-09-06 15:15:28 +00:00
parent 4f008c6f2f
commit 237022719a
3 changed files with 95 additions and 99 deletions

View file

@ -0,0 +1,93 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
// mapnik
#include <mapnik/vertex.hpp>
// stl
#include <vector>
#include <tuple>
namespace detail
{
template <typename T>
struct fake_path
{
using coord_type = std::tuple<T, T, unsigned>;
using cont_type = std::vector<coord_type>;
cont_type vertices_;
typename cont_type::iterator itr_;
fake_path(std::initializer_list<T> l)
: fake_path(l.begin(), l.size())
{
}
fake_path(std::vector<T> const &v, bool make_invalid = false)
: fake_path(v.begin(), v.size(), make_invalid)
{
}
template <typename Itr>
fake_path(Itr itr, size_t sz, bool make_invalid = false)
{
size_t num_coords = sz >> 1;
vertices_.reserve(num_coords + (make_invalid ? 1 : 0));
if (make_invalid)
{
vertices_.push_back(std::make_tuple(0,0,mapnik::SEG_END));
}
for (size_t i = 0; i < num_coords; ++i)
{
T x = *itr++;
T y = *itr++;
unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO;
vertices_.push_back(std::make_tuple(x, y, cmd));
}
itr_ = vertices_.begin();
}
unsigned vertex(T *x, T *y)
{
if (itr_ == vertices_.end())
{
return mapnik::SEG_END;
}
*x = std::get<0>(*itr_);
*y = std::get<1>(*itr_);
unsigned cmd = std::get<2>(*itr_);
++itr_;
return cmd;
}
void rewind(unsigned)
{
itr_ = vertices_.begin();
}
};
}
using fake_path = detail::fake_path<double>;

View file

@ -1,5 +1,6 @@
#include "catch.hpp"
#include "fake_path.hpp"
// mapnik
#include <mapnik/vertex_cache.hpp>
@ -7,53 +8,6 @@
// stl
#include <iostream>
#include <vector>
#include <tuple>
struct fake_path
{
using coord_type = std::tuple<double, double, unsigned>;
using cont_type = std::vector<coord_type>;
cont_type vertices_;
cont_type::iterator itr_;
fake_path(std::initializer_list<double> l)
: fake_path(l.begin(), l.size()) {
}
fake_path(std::vector<double> const &v)
: fake_path(v.begin(), v.size()) {
}
template <typename Itr>
fake_path(Itr itr, size_t sz) {
size_t num_coords = sz >> 1;
vertices_.reserve(num_coords);
for (size_t i = 0; i < num_coords; ++i) {
double x = *itr++;
double y = *itr++;
unsigned cmd = (i == 0) ? agg::path_cmd_move_to : agg::path_cmd_line_to;
vertices_.push_back(std::make_tuple(x, y, cmd));
}
itr_ = vertices_.begin();
}
unsigned vertex(double *x, double *y) {
if (itr_ == vertices_.end()) {
return agg::path_cmd_stop;
}
*x = std::get<0>(*itr_);
*y = std::get<1>(*itr_);
unsigned cmd = std::get<2>(*itr_);
++itr_;
return cmd;
}
void rewind(unsigned) {
itr_ = vertices_.begin();
}
};
double dist(mapnik::pixel_position const &a,
mapnik::pixel_position const &b)

View file

@ -1,66 +1,15 @@
#include "catch.hpp"
#include "fake_path.hpp"
// mapnik
#include <mapnik/vertex.hpp>
#include <mapnik/offset_converter.hpp>
// stl
#include <iostream>
#include <vector>
#include <tuple>
namespace offset_test {
struct fake_path
{
using coord_type = std::tuple<double, double, unsigned>;
using cont_type = std::vector<coord_type>;
cont_type vertices_;
cont_type::iterator itr_;
fake_path(std::initializer_list<double> l)
: fake_path(l.begin(), l.size()) {
}
fake_path(std::vector<double> const &v, bool make_invalid = false)
: fake_path(v.begin(), v.size(), make_invalid) {
}
template <typename Itr>
fake_path(Itr itr, size_t sz, bool make_invalid = false) {
size_t num_coords = sz >> 1;
vertices_.reserve(num_coords + (make_invalid ? 1 : 0));
if (make_invalid)
{
vertices_.push_back(std::make_tuple(0,0,mapnik::SEG_END));
}
for (size_t i = 0; i < num_coords; ++i) {
double x = *itr++;
double y = *itr++;
unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO;
vertices_.push_back(std::make_tuple(x, y, cmd));
}
itr_ = vertices_.begin();
}
unsigned vertex(double *x, double *y) {
if (itr_ == vertices_.end()) {
return mapnik::SEG_END;
}
*x = std::get<0>(*itr_);
*y = std::get<1>(*itr_);
unsigned cmd = std::get<2>(*itr_);
++itr_;
return cmd;
}
void rewind(unsigned) {
itr_ = vertices_.begin();
}
};
static double DELTA_BUFF = 0.5;
double dist(double x0, double y0, double x1, double y1)