diff --git a/test/geometry_to_crc.hpp b/test/geometry_to_crc.hpp new file mode 100644 index 000000000..439df0dd8 --- /dev/null +++ b/test/geometry_to_crc.hpp @@ -0,0 +1,37 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2021 Barend Gehrels, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef GEOMETRY_TEST_GEOMETRY_TO_CRC_HPP +#define GEOMETRY_TEST_GEOMETRY_TO_CRC_HPP + +#include + +#include + +#include +#include + +// Convenience function for tests, it generates a 4 character CRC of a geometry +// which can be used in filenames and/or testcases such as 'nores_37f6' +template +inline std::string geometry_to_crc(Geometry const& geometry) +{ + std::ostringstream out1; + out1 << bg::wkt(geometry); + + const std::string str = out1.str(); + + boost::crc_ccitt_type result; + result.process_bytes(str.data(), str.length()); + + std::ostringstream out2; + out2 << std::setw(4) << std::setfill('0') << std::hex << result.checksum(); + return out2.str(); +} + +#endif // GEOMETRY_TEST_GEOMETRY_TO_CRC_HPP diff --git a/test/robustness/overlay/buffer/recursive_polygons_buffer.cpp b/test/robustness/overlay/buffer/recursive_polygons_buffer.cpp index f78434347..3fe64a3bc 100644 --- a/test/robustness/overlay/buffer/recursive_polygons_buffer.cpp +++ b/test/robustness/overlay/buffer/recursive_polygons_buffer.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -39,14 +38,16 @@ #include #include +#include #include #include struct buffer_settings : public common_settings { - int join_code; - double distance; + int join_code{1}; + double distance{1.0}; + int points_per_circle{32}; // MySQL also uses 32 points in a circle for buffer }; namespace bg = boost::geometry; @@ -54,8 +55,7 @@ namespace bg = boost::geometry; template void create_svg(std::string const& filename , Geometry1 const& mp - , Geometry2 const& buffer - ) + , Geometry2 const& buffer) { typedef typename boost::geometry::point_type::type point_type; @@ -77,16 +77,13 @@ void create_svg(std::string const& filename mapper.map(mp, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:3"); mapper.map(buffer, "stroke-opacity:0.9;stroke:rgb(0,0,0);fill:none;stroke-width:1"); - - //mapper.map(intersection,"opacity:0.6;stroke:rgb(0,128,0);stroke-width:5"); } - - - template bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon const& buffer, Settings const& settings) { + using polygon_type = typename boost::range_value::type; + bool result = true; // Area of buffer must be larger than of original polygon @@ -101,8 +98,7 @@ bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon cons // Verify if all points are IN the buffer if (result) { - typedef typename boost::range_value::type polygon_type; - BOOST_FOREACH(polygon_type const& polygon, mp) + for (auto const& polygon : mp) { typename bg::point_type::type point; bg::point_on_border(point, polygon); @@ -133,27 +129,31 @@ bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon cons wkt = true; } + std::string filename; + + { + // Generate a unique name + std::ostringstream out; + out << "rec_pol_buffer_" << geometry_to_crc(mp) + << "_" << string_from_type::type>::name() + #if defined(BOOST_GEOMETRY_USE_RESCALING) + << "_rescaled" + #endif + << "."; + filename = out.str(); + } + if (svg) { - std::ostringstream filename; - filename << caseid << "_" - << string_from_type::type>::name() -#if defined(BOOST_GEOMETRY_USE_RESCALING) - << "_rescaled" -#endif - << ".svg"; - create_svg(filename.str(), mp, buffer); + create_svg(filename + "svg", mp, buffer); } if (wkt) { - std::ostringstream filename; - filename << caseid << "_" - << typeid(typename bg::coordinate_type::type).name() - << ".wkt"; - std::ofstream stream(filename.str().c_str()); + std::ofstream stream(filename + "wkt"); + // Stream input WKT stream << bg::wkt(mp) << std::endl; - stream << bg::wkt(buffer) << std::endl; + // If you need the output WKT, then stream bg::wkt(buffer) } return result; @@ -213,7 +213,7 @@ bool test_buffer(MultiPolygon& result, int& index, bg::strategy::buffer::end_round end_strategy; bg::strategy::buffer::point_circle point_strategy; bg::strategy::buffer::side_straight side_strategy; - bg::strategy::buffer::join_round join_round_strategy(32); // Compatible with MySQL + bg::strategy::buffer::join_round join_round_strategy(settings.points_per_circle); bg::strategy::buffer::join_miter join_miter_strategy; try @@ -312,8 +312,9 @@ int main(int argc, char** argv) ("seed", po::value(&seed), "Initialization seed for random generator") ("count", po::value(&count)->default_value(1), "Number of tests") ("validity", po::value(&settings.check_validity)->default_value(true), "Include testing on validity") - ("level", po::value(&level)->default_value(3), "Level to reach (higher->slower)") + ("level", po::value(&level)->default_value(3), "Level to reach (higher -> slower)") ("distance", po::value(&settings.distance)->default_value(1.0), "Distance (1.0)") + ("ppc", po::value(&settings.points_per_circle)->default_value(32), "Points per circle (32)") ("form", po::value(&form)->default_value("box"), "Form of the polygons (box, triangle)") ("join", po::value(&join)->default_value("round"), "Form of the joins (round, miter)") ("ccw", po::value(&ccw)->default_value(false), "Counter clockwise polygons")