mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-11 13:34:10 +00:00
[test][algorithms] factor-out common code
This commit is contained in:
parent
2438af55b3
commit
a68bcb3b13
@ -42,6 +42,13 @@
|
||||
#include <boost/geometry/algorithms/is_valid.hpp>
|
||||
#include <boost/geometry/algorithms/is_simple.hpp>
|
||||
|
||||
#include "from_wkt.hpp"
|
||||
|
||||
#ifdef GEOMETRY_TEST_DEBUG
|
||||
#include "pretty_print_geometry.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace bg = ::boost::geometry;
|
||||
|
||||
typedef bg::model::point<double, 2, bg::cs::cartesian> point_type;
|
||||
@ -57,61 +64,6 @@ typedef bg::model::multi_polygon<open_ccw_polygon_type> multi_polygon_type;
|
||||
// box
|
||||
typedef bg::model::box<point_type> box_type;
|
||||
|
||||
template <typename Geometry>
|
||||
Geometry from_wkt(std::string const& wkt)
|
||||
{
|
||||
Geometry g;
|
||||
bg::read_wkt(wkt, g);
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifdef GEOMETRY_TEST_DEBUG
|
||||
template <typename Geometry, typename Tag = typename bg::tag<Geometry>::type>
|
||||
struct pretty_print_geometry
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Geometry const& geometry)
|
||||
{
|
||||
os << bg::wkt(geometry);
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Box>
|
||||
struct pretty_print_geometry<Box, bg::box_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Box const& box)
|
||||
{
|
||||
return os << "BOX" << bg::dsv(box);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Segment>
|
||||
struct pretty_print_geometry<Segment, bg::segment_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Segment const& segment)
|
||||
{
|
||||
return os << "SEGMENT" << bg::dsv(segment);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Ring>
|
||||
struct pretty_print_geometry<Ring, bg::ring_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Ring const& ring)
|
||||
{
|
||||
return os << "RING" << bg::dsv(ring);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
@ -31,15 +31,14 @@
|
||||
|
||||
#include <boost/geometry/io/wkt/read.hpp>
|
||||
|
||||
#ifdef GEOMETRY_TEST_DEBUG
|
||||
#include <boost/geometry/core/tag.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
#include <boost/geometry/algorithms/is_valid.hpp>
|
||||
|
||||
#include <boost/geometry/io/wkt/write.hpp>
|
||||
#include <boost/geometry/io/dsv/write.hpp>
|
||||
#include "from_wkt.hpp"
|
||||
|
||||
#ifdef GEOMETRY_TEST_DEBUG
|
||||
#include "pretty_print_geometry.hpp"
|
||||
#endif
|
||||
|
||||
#include <boost/geometry/algorithms/is_valid.hpp>
|
||||
|
||||
namespace bg = ::boost::geometry;
|
||||
|
||||
@ -63,62 +62,6 @@ typedef bg::model::polygon<point_type,true,true> closed_cw_polygon_type;
|
||||
typedef bg::model::multi_point<point_type> multi_point_type;
|
||||
|
||||
|
||||
template <typename Geometry>
|
||||
Geometry from_wkt(std::string const& wkt)
|
||||
{
|
||||
Geometry g;
|
||||
bg::read_wkt(wkt, g);
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifdef GEOMETRY_TEST_DEBUG
|
||||
template <typename Geometry, typename Tag = typename bg::tag<Geometry>::type>
|
||||
struct pretty_print_geometry
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Geometry const& geometry)
|
||||
{
|
||||
os << bg::wkt(geometry);
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Box>
|
||||
struct pretty_print_geometry<Box, bg::box_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Box const& box)
|
||||
{
|
||||
return os << "BOX" << bg::dsv(box);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Segment>
|
||||
struct pretty_print_geometry<Segment, bg::segment_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Segment const& segment)
|
||||
{
|
||||
return os << "SEGMENT" << bg::dsv(segment);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Ring>
|
||||
struct pretty_print_geometry<Ring, bg::ring_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Ring const& ring)
|
||||
{
|
||||
return os << "RING" << bg::dsv(ring);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
65
test/algorithms/pretty_print_geometry.hpp
Normal file
65
test/algorithms/pretty_print_geometry.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
// Unit Tests
|
||||
|
||||
// Copyright (c) 2014, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
|
||||
// Licensed under the Boost Software License version 1.0.
|
||||
// http://www.boost.org/users/license.html
|
||||
|
||||
#ifndef BOOST_GEOMETRY_TEST_PRETTY_PRINT_GEOMETRY_HPP
|
||||
#define BOOST_GEOMETRY_TEST_PRETTY_PRINT_GEOMETRY_HPP
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/geometry/core/tag.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/io/dsv/write.hpp>
|
||||
#include <boost/geometry/io/wkt/write.hpp>
|
||||
|
||||
|
||||
template <typename Geometry, typename Tag = typename bg::tag<Geometry>::type>
|
||||
struct pretty_print_geometry
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Geometry const& geometry)
|
||||
{
|
||||
os << bg::wkt(geometry);
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Box>
|
||||
struct pretty_print_geometry<Box, bg::box_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Box const& box)
|
||||
{
|
||||
return os << "BOX" << bg::dsv(box);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Segment>
|
||||
struct pretty_print_geometry<Segment, bg::segment_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Segment const& segment)
|
||||
{
|
||||
return os << "SEGMENT" << bg::dsv(segment);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Ring>
|
||||
struct pretty_print_geometry<Ring, bg::ring_tag>
|
||||
{
|
||||
static inline std::ostream&
|
||||
apply(std::ostream& os, Ring const& ring)
|
||||
{
|
||||
return os << "RING" << bg::dsv(ring);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_TEST_PRETTY_PRINT_GEOMETRY_HPP
|
Loading…
x
Reference in New Issue
Block a user