diff --git a/test/algorithms/buffer/buffer.sln b/test/algorithms/buffer/buffer.sln new file mode 100644 index 000000000..d43a684b7 --- /dev/null +++ b/test/algorithms/buffer/buffer.sln @@ -0,0 +1,25 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C++ Express 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "polygon_buffer", "polygon_buffer.vcproj", "{42B6DE98-66F0-46CB-8A4C-54EB6030F07B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "linestring_buffer", "linestring_buffer.vcproj", "{02387445-E879-49F4-8264-C7CF9C6B8B9D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {42B6DE98-66F0-46CB-8A4C-54EB6030F07B}.Debug|Win32.ActiveCfg = Debug|Win32 + {42B6DE98-66F0-46CB-8A4C-54EB6030F07B}.Debug|Win32.Build.0 = Debug|Win32 + {42B6DE98-66F0-46CB-8A4C-54EB6030F07B}.Release|Win32.ActiveCfg = Release|Win32 + {42B6DE98-66F0-46CB-8A4C-54EB6030F07B}.Release|Win32.Build.0 = Release|Win32 + {02387445-E879-49F4-8264-C7CF9C6B8B9D}.Debug|Win32.ActiveCfg = Debug|Win32 + {02387445-E879-49F4-8264-C7CF9C6B8B9D}.Debug|Win32.Build.0 = Debug|Win32 + {02387445-E879-49F4-8264-C7CF9C6B8B9D}.Release|Win32.ActiveCfg = Release|Win32 + {02387445-E879-49F4-8264-C7CF9C6B8B9D}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/test/algorithms/buffer/linestring_buffer.cpp b/test/algorithms/buffer/linestring_buffer.cpp new file mode 100644 index 000000000..a4ab26db5 --- /dev/null +++ b/test/algorithms/buffer/linestring_buffer.cpp @@ -0,0 +1,60 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) test file +// +// Copyright Barend Gehrels 2010, Geodan, 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) + +//#define BOOST_GEOMETRY_DEBUG_WITH_MAPPER +//#define BOOST_GEOMETRY_DEBUG_ASSEMBLE +//#define BOOST_GEOMETRY_DEBUG_IDENTIFIER + +#include + +#include +#include + +#include + +#include +#include +#include + +#include + +static std::string const simplex = "LINESTRING(0 0,4 5)"; +static std::string const one_bend = "LINESTRING(0 0,4 5,7 4)"; +static std::string const two_bends = "LINESTRING(0 0,4 5,7 4,10 6)"; +static std::string const overlapping = "LINESTRING(0 0,4 5,7 4,10 6, 10 2,2 2)"; + +template +void test_all() +{ + namespace bg = boost::geometry; + namespace buf = boost::geometry::strategy::buffer; + typedef bg::linestring

linestring; + typedef bg::polygon

polygon; + + double right = 1.5; + + test_one("simplex", simplex, 'r', 19.2093727122985, 1.5, right); + test_one("simplex", simplex, 'm', 19.2093727122985, 1.5, right); + + test_one("one_bend", one_bend, 'r', 28.4879539312069, 1.5, right); + test_one("one_bend", one_bend, 'm', 28.6962056928037, 1.5, right); + + test_one("two_bends", two_bends, 'r', 39.2220036534424, 1.5, right); + test_one("two_bends", two_bends, 'm', 39.5128595191957, 1.5, right); + + test_one("overlapping", overlapping, 'r', 65.646005724872, 1.5, right); + test_one("overlapping", overlapping, 'm', 68.1395194809293, 1.5, right); +} + +int test_main(int, char* []) +{ + namespace bg = boost::geometry; + test_all >(); + + + return 0; +} diff --git a/test/algorithms/buffer/linestring_buffer.vcproj b/test/algorithms/buffer/linestring_buffer.vcproj new file mode 100644 index 000000000..c43d7d9f6 --- /dev/null +++ b/test/algorithms/buffer/linestring_buffer.vcproj @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/algorithms/buffer/polygon_buffer.cpp b/test/algorithms/buffer/polygon_buffer.cpp new file mode 100644 index 000000000..51bea0178 --- /dev/null +++ b/test/algorithms/buffer/polygon_buffer.cpp @@ -0,0 +1,178 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) test file +// +// Copyright Barend Gehrels 2010, Geodan, 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) + + +#include + +#define BOOST_GEOMETRY_TEST_BUFFER_POLYGON +#include + + + +static std::string const simplex + = "POLYGON ((0 0,1 5,6 1,0 0))"; +static std::string const concave_simplex + = "POLYGON ((0 0,3 5,3 3,5 3,0 0))"; +static std::string const donut_simplex + = "POLYGON ((0 0,1 9,8 1,0 0),(1 1,4 1,1 4,1 1))"; +static std::string const letter_L + = "POLYGON ((0 0,0 4,1 4,1 1,3 1,3 0,0 0))"; +static std::string const indentation + = "POLYGON ((0 0,0 5,4 5,4 4,3 3,2 4,2 1,3 2,4 1,4 0,0 0))"; +static std::string const arrow + = "POLYGON ((1 0,1 5,0.5 4.5,2 10,3.5 4.5,3 5,3 0,1 0))"; +static std::string const tipped_aitch + = "POLYGON ((0 0,0 3,3 3,3 4,0 4,0 7,7 7,7 4,4 4,4 3,7 3,7 0,0 0))"; +static std::string const snake + = "POLYGON ((0 0,0 3,3 3,3 4,0 4,0 7,8 7,8 4,6 4,6 3,8 3,8 0,7 0,7 2,5 2" + ",5 5,7 5,7 6,1 6,1 5,4 5,4 2,1 2,1 1,6 1,6 0,0 0))"; +static std::string const church + = "POLYGON ((0 0,0 3,2.999 3,3 8,3 0,0 0))"; +static std::string const flower + = "POLYGON ((1 0,1 10,9 10,9 0,4.99 0,4.99 5.5,4.5 6,5 6.5,5.5 6,5.01 5.5,5.01 0.01,5.25 0.01,5.25 5,6 3,8 5,6 6,8 7,6 9,5 7,4 9,2 7,4 6,2 5,4 3,4.75 5,4.75 0,1 0))"; + +template +void test_all() +{ + namespace bg = boost::geometry; + namespace buf = boost::geometry::strategy::buffer; + + typedef bg::polygon

polygon_type; + + test_one("L", letter_L, 'm', 14, 0.5); + test_one("L", letter_L, 'r', 13.7254516100806, 0.5); + test_one("simplex", simplex, 'm', 52.8733092508931, 1.5); + test_one("simplex", simplex, 'r', 47.9004943967109, 1.5); + test_one("concave_simplex", concave_simplex, 'm', 16.3861105439862, 0.5); + test_one("concave_simplex", concave_simplex, 'r', 14.5563908986706, 0.5); + + test_one("indentation4", indentation, 'm', 25.7741125496954, 0.4); + test_one("indentation4", indentation, 'r', 25.5641980024698, 0.4); + + test_one("indentation8", indentation, 'm', 35.594305909533, 0.8); + test_one("indentation8", indentation, 'r', 35.0012686715019, 0.8); + test_one("indentation12", indentation, 'm', 46.3541038841777, 1.2); + test_one("indentation12", indentation, 'r', 45.0197700986076, 1.2); + test_one("indentation4_neg", indentation, 'm', 6.99098413022335, -0.4); + //test_one("indentation4_neg", indentation, 'r', 7.25523322189147, -0.4); + test_one("indentation8_neg", indentation, 'm', 1.36941992048731, -0.8); + //test_one("indentation8_neg", indentation, 'r', 1.37375487490664, -0.8); + test_one("indentation12_neg", indentation, 'm', 0, -1.2); + //test_one("indentation12_neg", indentation, 'r', 0, -1.2); + + test_one("donut_simplex6", donut_simplex, 'm', 53.6479838666524, 0.6); + test_one("donut_simplex6", donut_simplex, 'r', 52.8197383107592, 0.6); + test_one("donut_simplex8", donut_simplex, 'm', 61.1323012599270, 0.8); + test_one("donut_simplex8", donut_simplex, 'r', 59.6598647161168, 0.8); + test_one("donut_simplex10", donut_simplex, 'm', 68.6698998096905, 1.0); + test_one("donut_simplex10", donut_simplex, 'r', 66.3692177099870, 1.0); + test_one("donut_simplex12", donut_simplex, 'm', 76.6051864381534, 1.2); + test_one("donut_simplex12", donut_simplex, 'r', 73.2922042145803, 1.2); + test_one("donut_simplex14", donut_simplex, 'm', 84.9742419554578, 1.4); + test_one("donut_simplex14", donut_simplex, 'r', 80.4649050400389, 1.4); + test_one("donut_simplex16", donut_simplex, 'm', 93.7770663616038, 1.6); + test_one("donut_simplex16", donut_simplex, 'r', 87.8873201863629, 1.6); + + test_one("arrow4", arrow, 'm', 28.2654860719170, 0.4); + test_one("arrow4", arrow, 'r', 27.0385824776218, 0.4); + test_one("arrow5", arrow, 'm', 31.5003260106997, 0.5); + test_one("arrow5", arrow, 'r', 29.6211879021183, 0.5); + test_one("arrow6", arrow, 'm', 34.9025533178038, 0.6); + test_one("arrow6", arrow, 'r', 32.2572740033805, 0.6); + + test_one("tipped_aitch3", tipped_aitch, 'm', 55.36, 0.3); + test_one("tipped_aitch9", tipped_aitch, 'm', 77.44, 0.9); + test_one("tipped_aitch13", tipped_aitch, 'm', 92.16, 1.3); + + test_one("snake4", snake, 'm', 64.44, 0.4); + test_one("snake5", snake, 'm', 72, 0.5); + test_one("snake6", snake, 'm', 75.44, 0.6); + test_one("snake16", snake, 'm', 114.24, 1.6); + + test_one("flower1", flower, 'r', 67.48584413272776, 0.1); + test_one("flower1", flower, 'm', 67.613949189084963, 0.1); + test_one("flower4", flower, 'r', 87.665381352300471, 0.4); + test_one("flower4", flower, 'm', 87.8306529577, 0.4); + + return; + + /* + for (int i = 4; i < 30; i++) + { + { + std::ostringstream out; + out << "snake_" << i; + test_one(out.str(), snake, double(i) / 10.0); + } + { + std::ostringstream out; + out << "snake_" << i << "_neg"; + test_one(out.str(), snake, double(-i) / 10.0); + } + } + */ + + /* + for (int i = 4; i < 30; i++) + { + std::ostringstream out; + out << "church_" << i; + test_one(out.str(), church, 'm', double(i) / 10.0); + } + for (int i = 4; i < 30; i++) + { + std::ostringstream out; + out << "flower_" << i; + test_one(out.str(), flower, 'm', double(i) / 10.0); + } + static std::string const snl_8961 = + "POLYGON((161081 472784,161061 472769,161007 472740,160996 472746,160998 472777,160999 472782,161005 472888,161012 472889,161019 472891,161032 472895,161038 472883,161081 472784),(161026 472811,161022 472814,161019 472810,161023 472807,161026 472811))"; + test_one("snl_8961_10", snl_8961, 'm', 10.0); + test_one("snl_8961_100", snl_8961, 'm', 100.0); + test_one("snl_8961_500", snl_8961, 'm', 500.0); + + static std::string const snl_25120 = + "POLYGON((225343.489 585110.376,225319.123 585165.731,225323.497 585167.287,225323.134 585167.157,225313.975 585169.208,225321.828 585172,225332.677 585175.83,225367.032 585186.977,225401.64 585196.671,225422.799 585201.029,225429.784 585202.454,225418.859 585195.112,225423.803 585196.13,225425.389 585196.454,225397.027 585165.48,225363.802 585130.372,225354.086 585120.261,225343.489 585110.376))"; + test_one("snl_25120", snl_25120, 'm', 1.25); + return; + + + for (int i = 1; i < 10; i++) + { + std::ostringstream out; + out << "snl_7309_" << i; + static std::string const snl_7309 = + "POLYGON((116042.2 464335.07,116045.9 464325.15,116051.33 464311.53,116056.35 464294.59,116066.41 464264.16,116066.44 464264.09,116060.35 464280.93,116028.89 464268.43,116028.89 464268.44,116024.74 464280.7,116018.91 464296.71,116012.3 464319.59,116004.76 464345.13,115988.36 464389.71,115975.39 464426.35,115965.07 464455.99,115964.81 464458.9,115966.39 464461.02,115976.45 464466.84,115984.12 464470.41,115988.22 464471.33,115991.8 464470.8,115995.9 464467.76,115997.48 464462.73,115999.73 464455.72,116002.11 464448.98,116006.08 464438.53,116010.18 464429.79,116021.96 464392.75,116034 464357.7,116042.2 464335.07))"; + test_one(out.str(), snl_7309, 'm', i * 10.0); + } + + //return; + test_one("toolkit1", "POLYGON((173356.986490154 605912.122380707,173358.457939143 605902.891897507,173358.458257372 605902.889901239,173214.162964795 605901.13020255,173214.162746654 605901.132200038,173213.665 605905.69,173212.712441616 605913.799985923,173356.986490154 605912.122380707))", + 'm', 10.0); + for (int i = 1; i < 20; i++) + { + std::ostringstream out; + out << "toolkit2_" << i; + test_one(out.str(), + "POLYGON((120528.56 462115.62,120533.4 462072.1,120533.4 462072.01,120533.39 462071.93,120533.36 462071.86,120533.33 462071.78,120533.28 462071.72,120533.22 462071.66,120533.15 462071.61,120533.08 462071.58,120533 462071.55,120532.92 462071.54,120467.68 462068.66,120468.55 462059.04,120517.39 462062.87,120517.47 462062.87,120517.55 462062.86,120517.62 462062.83,120517.69 462062.79,120517.76 462062.74,120517.81 462062.68,120517.86 462062.62,120517.89 462062.55,120517.92 462062.47,120530.49 461998.63,120530.5 461998.55,120530.49 461998.47,120530.47 461998.39,120530.44 461998.31,120530.4 461998.24,120530.35 461998.18,120530.28 461998.13,120530.21 461998.09,120530.13 461998.06,120482.19 461984.63,120485 461963.14,120528.2 461950.66,120528.28 461950.63,120528.35 461950.59,120528.42 461950.53,120528.47 461950.47,120528.51 461950.4,120528.54 461950.32,120528.56 461950.24,120528.56 461950.15,120528.55 461950.07,120528.53 461949.99,120528.49 461949.92,120528.44 461949.85,120497.49 461915.03,120497.43 461914.98,120497.37 461914.93,120497.3 461914.9,120497.23 461914.88,120497.15 461914.86,120424.61 461910.03,120424.53 461910.03,120424.45 461910.05,120424.37 461910.07,120424.3 461910.11,120424.24 461910.16,120424.18 461910.22,120424.14 461910.29,120424.11 461910.37,120424.09 461910.45,120424.08 461910.53,120424.08 461967.59,120424.08 461967.67,120424.1 461967.75,120424.14 461967.82,120424.18 461967.89,120424.23 461967.95,120424.3 461968,120424.37 461968.04,120424.44 461968.07,120424.52 461968.09,120473.31 461973.83,120469.63 461993.16,120399.48 461986.43,120399.4 461986.43,120399.32 461986.44,120399.25 461986.47,120399.17 461986.5,120399.11 461986.55,120399.05 461986.61,120399.01 461986.67,120398.97 461986.74,120398.95 461986.82,120398.93 461986.9,120394.1 462057.5,120394.1 462057.58,120394.11 462057.66,120394.14 462057.74,120394.18 462057.81,120394.23 462057.87,120394.29 462057.93,120394.35 462057.97,120394.43 462058,120394.5 462058.03,120394.58 462058.03,120458.74 462059.95,120455.16 462072.48,120396.57 462067.68,120396.49 462067.68,120396.4 462067.69,120396.32 462067.72,120396.25 462067.76,120396.18 462067.82,120396.13 462067.88,120396.08 462067.96,120396.05 462068.04,120396.03 462068.12,120392.17 462103.9,120392.16 462103.99,120392.18 462104.07,120392.2 462104.15,120392.24 462104.22,120392.29 462104.29,120392.35 462104.35,120392.42 462104.4,120392.5 462104.43,120392.58 462104.45,120392.66 462104.46,120393.63 462104.46,120393.63 462103.46,120393.22 462103.46,120396.98 462068.71,120455.49 462073.51,120455.57 462073.51,120455.66 462073.49,120455.74 462073.46,120455.81 462073.42,120455.88 462073.37,120455.93 462073.3,120455.98 462073.23,120456.01 462073.15,120459.88 462059.61,120459.89 462059.52,120459.9 462059.44,120459.88 462059.36,120459.86 462059.28,120459.82 462059.21,120459.77 462059.14,120459.72 462059.08,120459.65 462059.04,120459.57 462059,120459.49 462058.98,120459.41 462058.97,120395.13 462057.05,120399.9 461987.48,120469.99 461994.2,120470.07 461994.2,120470.15 461994.19,120470.23 461994.16,120470.3 461994.13,120470.37 461994.08,120470.42 461994.02,120470.47 461993.95,120470.5 461993.88,120470.53 461993.8,120474.4 461973.48,120474.4 461973.4,120474.4 461973.32,120474.38 461973.24,120474.35 461973.16,120474.31 461973.09,120474.25 461973.03,120474.19 461972.98,120474.12 461972.94,120474.04 461972.91,120473.96 461972.9,120425.08 461967.14,120425.08 461911.06,120496.88 461915.85,120527.16 461949.92,120484.4 461962.27,120484.33 461962.3,120484.25 461962.35,120484.19 461962.4,120484.14 461962.46,120484.09 461962.53,120484.06 461962.61,120484.05 461962.69,120481.14 461984.93,120481.14 461985.01,120481.15 461985.09,120481.17 461985.17,120481.2 461985.24,120481.25 461985.31,120481.3 461985.36,120481.36 461985.41,120481.43 461985.45,120481.51 461985.48,120529.42 461998.9,120517.02 462061.84,120468.14 462058,120468.05 462058,120467.97 462058.02,120467.89 462058.05,120467.81 462058.09,120467.75 462058.15,120467.69 462058.22,120467.65 462058.29,120467.62 462058.37,120467.6 462058.46,120466.64 462069.1,120466.63 462069.18,120466.65 462069.26,120466.67 462069.33,120466.71 462069.4,120466.76 462069.47,120466.81 462069.53,120466.88 462069.57,120466.95 462069.61,120467.03 462069.63,120467.11 462069.64,120532.34 462072.52,120527.62 462115.03,120391.73 462106.36,120391.66 462107.36,120528.03 462116.06,120528.12 462116.06,120528.2 462116.04,120528.28 462116.02,120528.35 462115.97,120528.42 462115.92,120528.47 462115.85,120528.51 462115.78,120528.54 462115.7,120528.56 462115.62))", + 'm', double(i) + ); + } + */ + + + + +} + +int test_main(int, char* []) +{ + namespace bg = boost::geometry; + test_all >(); + + return 0; +} diff --git a/test/algorithms/buffer/polygon_buffer.vcproj b/test/algorithms/buffer/polygon_buffer.vcproj new file mode 100644 index 000000000..e8e625add --- /dev/null +++ b/test/algorithms/buffer/polygon_buffer.vcproj @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/algorithms/buffer/test_buffer.hpp b/test/algorithms/buffer/test_buffer.hpp new file mode 100644 index 000000000..5543d4ef9 --- /dev/null +++ b/test/algorithms/buffer/test_buffer.hpp @@ -0,0 +1,284 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) test file +// +// Copyright Barend Gehrels 2010, Geodan, 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 BOOST_GEOMETRY_TEST_BUFFER_HPP +#define BOOST_GEOMETRY_TEST_BUFFER_HPP + + +#define BOOST_GEOMETRY_DEBUG_WITH_MAPPER +//#define BOOST_GEOMETRY_DEBUG_SPLIT_RINGS + +//#define BOOST_GEOMETRY_CHECK_WITH_POSTGIS +//#define BOOST_GEOMETRY_DEBUG_ASSEMBLE +//#define BOOST_GEOMETRY_DEBUG_IDENTIFIER + +#undef BOOST_GEOMETRY_DEBUG_WITH_MAPPER +//#undef TEST_WITH_SVG + + +#if defined(BOOST_GEOMETRY_DEBUG_WITH_MAPPER) +#define TEST_WITH_SVG +#endif + +#include +#include + +#include +#include + + +#include +#include +#include +#include + + +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + + + +#if defined(TEST_WITH_SVG) +# include +#endif + + + +template +< + typename GeometryOut, + template + < + typename + , typename +#if defined(BOOST_GEOMETRY_DEBUG_WITH_MAPPER) + , typename +#endif + > class JoinStrategy, + typename Geometry +> +void test_buffer(std::string const& caseid, Geometry const& g1, + char join, + double expected_area, + double distance_left, double distance_right) +{ + namespace bg = boost::geometry; + + typedef typename bg::coordinate_type::type coordinate_type; + typedef typename bg::point_type::type point_type; + typedef bg::strategy::buffer::distance_assymetric distance; + + typedef typename bg::ring_type::type ring_type; + + typedef JoinStrategy + < + point_type, + typename bg::point_type::type +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , bg::svg_mapper +#endif + > join_strategy; + + std::vector buffered; + + typedef bg::detail::buffer::intersecting_inserter + < + std::vector + > inserter_type; + + +#if ! defined(TEST_WITH_SVG) + inserter_type inserter(buffered); + + #if defined(BOOST_GEOMETRY_TEST_BUFFER_POLYGON) + GeometryOut buffered_step1; + bg::detail::buffer::polygon_buffer + < + Geometry, Geometry, join_strategy + >::apply(g1, buffered_step1, distance_left, join_strategy()); + + //bg::dissolve_inserter(buffered_step1, std::back_inserter(buffered)); + buffered.push_back(buffered_step1); + #else + bg::detail::buffer::linestring_buffer + < + Geometry, GeometryOut, distance, join_strategy + >::apply(g1, inserter, + distance(distance_left, distance_right), + join_strategy()); + #endif + +#else + + { + std::ostringstream filename; + filename << "buffer_" + << (bg::geometry_id::value == 2 ? "line" : "poly") << "_" + << caseid << "_" + << string_from_type::name() + << "_" << join + << ".svg"; + + std::ofstream svg(filename.str().c_str()); + + bg::svg_mapper mapper(svg, 500, 500); + + inserter_type inserter(buffered); + + // Display including a margin + bg::box extent; + bg::envelope(g1, extent); + bg::buffer(extent, extent, 2); + mapper.add(extent); + + #if defined(BOOST_GEOMETRY_TEST_BUFFER_POLYGON) + Geometry buffered_step1; + bg::detail::buffer::polygon_buffer + < + Geometry, Geometry, join_strategy + >::apply(g1, buffered_step1, distance_left +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , join_strategy(mapper), mapper +#else + , join_strategy() +#endif + ); + + //bg::dissolve_inserter(buffered_step1, std::back_inserter(buffered)); + buffered.push_back(buffered_step1); + + #else + bg::detail::buffer::linestring_buffer + < + Geometry, GeometryOut, distance, join_strategy + >::apply(g1, inserter, + distance(distance_left, distance_right) +#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER + , join_strategy(mapper), mapper +#else + , join_strategy() +#endif + ); + #endif + + // Map input geometry in green + mapper.map(g1, "opacity:0.5;fill:rgb(0,255,0);stroke:rgb(0,255,0);stroke-width:1"); + + std::vector rings; + BOOST_FOREACH(GeometryOut const& polygon, buffered) + { +//std::cout << bg::wkt(polygon) << " ; POLYGON" << std::endl; + bg::split_rings(polygon, rings); + } + +/* + BOOST_FOREACH(ring_type const& ring, rings) + { + mapper.map(ring, + bg::area(ring) > 0 + ? "opacity:0.5;fill:none;stroke:rgb(255,0,0);stroke-width:8" + : "opacity:0.5;fill:none;stroke:rgb(0,0,255);stroke-width:8" + ); +std::cout << bg::wkt(ring) + << " ; " << bg::area(ring) + << " " << ring.size() + << std::endl; + } +*/ + + std::vector buffered_and_unioned; + bg::dissolver(rings, buffered_and_unioned); + + std::vector buffered_and_assembled; + bg::detail::overlay::assemble(buffered_and_unioned, + std::map(), + buffered_and_unioned[0], buffered_and_unioned[0], 1, true, true, + std::back_inserter(buffered_and_assembled)); + + + + // Map buffer in green + BOOST_FOREACH(GeometryOut const& p, buffered_and_assembled) + { + mapper.map(p, "opacity:0.8;fill:none;stroke:rgb(0,64,0);stroke-width:2"); + } + buffered.swap(buffered_and_assembled); +} +#endif + + double a = 0.0; + BOOST_FOREACH(GeometryOut const& polygon, buffered) + { + a += bg::area(polygon); + } + BOOST_CHECK_CLOSE(a, expected_area, join == 'r' ? 0.1 : 0.001); +} + +#ifdef BOOST_GEOMETRY_CHECK_WITH_POSTGIS +static int counter = 0; +#endif + +template +< + typename Geometry, + template + < + typename + , typename +#if defined(BOOST_GEOMETRY_DEBUG_WITH_MAPPER) + , typename +#endif + > class JoinStrategy, + typename GeometryOut +> +void test_one(std::string const& caseid, std::string const& wkt, + char join, double expected_area, + double distance_left, double distance_right = -999) +{ + namespace bg = boost::geometry; + Geometry g; + bg::read_wkt(wkt, g); + + typedef typename bg::point_type::type point_type; + + //std::cout << caseid << std::endl; + + +#ifdef BOOST_GEOMETRY_CHECK_WITH_POSTGIS + std::cout + << (counter > 0 ? "union " : "") + << "select " << counter++ + << ", '" << caseid << "' as caseid" + << ", ST_Area(ST_Buffer(ST_GeomFromText('" << wkt << "'), " + << distance_left + << ", 'endcap=flat join=" << (join == 'm' ? "miter" : "round") << "'))" + << ", " << expected_area + << std::endl; +#endif + + test_buffer + (caseid, g, join, expected_area, distance_left, distance_right); +} + + +#endif diff --git a/test/algorithms/difference.cpp b/test/algorithms/difference.cpp index aaceae587..4912abec1 100644 --- a/test/algorithms/difference.cpp +++ b/test/algorithms/difference.cpp @@ -5,6 +5,9 @@ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#define BOOST_GEOMETRY_CHECK_WITH_POSTGIS + + #include #include @@ -25,47 +28,61 @@ void test_all() test_one("two_bends", two_bends[0], two_bends[1], - 1, 7, 24.0, - 1, 7, 24.0); + 1, 7, 8.0, + 1, 7, 8.0); test_one("star_comb_15", star_15, comb_15, - 28, 150, 189.952883, - 28, 150, 189.952883); + 30, 150, 227.658275102812, + 30, 150, 480.485775259312); test_one("simplex_normal", simplex_normal[0], simplex_normal[1], - 1, 7, 5.47363293, - 1, 7, 5.47363293); + 3, 3, 2.52636706856656, + 3, 3, 3.52636706856656); + /* TODO: erroneous in assemble test_one("fitting", fitting[0], fitting[1], - 0, 0, 0, 0, 0, 0); + 1, 0, 21.0, + 1, 0, 4.0); + */ test_one("new_hole", new_hole[0], new_hole[1], - 2, 10, 2.0, - 2, 10, 2.0); + 1, 10, 7.0, + 1, 10, 14.0); + /* TODO: erroneous in assemble test_one("intersect_holes_disjoint", intersect_holes_disjoint[0], intersect_holes_disjoint[1], - 1, 15, 18.0, - 1, 15, 18.0); + 2, 15, 16.0, + 2, 15, 6.0); + */ test_one("intersect_holes_intersect", intersect_holes_intersect[0], intersect_holes_intersect[1], - 1, 14, 18.25, - 1, 14, 18.25); + 2, 14, 15.75, + 2, 14, 5.75); test_one( "case4", case_4[0], case_4[1], - 4, 22, 1.1901714, - 4, 27, 1.6701714); + 6, 22, 2.77878787878788, + 4, 27, 4.77878787878788); test_one( "case5", case_5[0], case_5[1], - 4, 22, 1.1901714, - 4, 27, 1.6701714); + 8, 22, 2.43452380952381, + 7, 27, 3.18452380952381); + + test_one( + "positive_negative", + "POLYGON((0 0,0 4,4 4,4 0,0 0))", + //"POLYGON((2 2,6 2,6 3,2 3,2 2))", + "POLYGON((2 2,2 3,6 3,6 2,2 2))", + 5, 22, 1.1901714, + 5, 27, 1.6701714); + } diff --git a/test/algorithms/overlay/dissolver.cpp b/test/algorithms/overlay/dissolver.cpp new file mode 100644 index 000000000..e3a7f9c54 --- /dev/null +++ b/test/algorithms/overlay/dissolver.cpp @@ -0,0 +1,219 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) test file +// +// Copyright Barend Gehrels 2010, Geodan, 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) + +#include +#include + + +#include + +#include + +#include +#include +#include +#include +#include + + +#include + + +//#define TEST_WITH_SVG +#if defined(TEST_WITH_SVG) +# include +#endif + +// Collection might be a multi-geometry, or std::vector +template +void test_dissolve_plusmin(std::string const& caseid, Collection const& input, + T const& expected_positive_area, + T const& expected_negative_area) +{ + namespace bg = boost::geometry; + typedef typename boost::range_value::type geometry_type; + typedef typename bg::point_type::type point_type; + + + GeometryOut output; + bg::dissolver(input, output); + + T zero = T(); + T positive_area = T(); + T negative_area = T(); + + BOOST_FOREACH(geometry_type const& geometry, output) + { + T a = bg::area(geometry); + if (a > zero) + { + positive_area += a; + } + else + { + negative_area += a; + } + } + + BOOST_CHECK_CLOSE(positive_area, expected_positive_area, 0.001); + BOOST_CHECK_CLOSE(negative_area, expected_negative_area, 0.001); + + +#if defined(TEST_WITH_SVG) + { + std::ostringstream filename; + filename << "dissolve_plusmin_" + << caseid << ".svg"; + + std::ofstream svg(filename.str().c_str()); + + bg::svg_mapper mapper(svg, 500, 500); + + typedef typename boost::range_value::type value_type; + BOOST_FOREACH(value_type const& geometry, input) + { + mapper.add(geometry); + } + + BOOST_FOREACH(value_type const& geometry, input) + { + mapper.map(geometry, + "opacity:0.6;fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:0.5"); + } + BOOST_FOREACH(geometry_type const& geometry, output) + { + mapper.map(geometry, + bg::area(geometry) > 0 + ? "opacity:0.5;fill:none;stroke:rgb(255,0,0);stroke-width:5" + : "opacity:0.5;fill:none;stroke:rgb(0,0,255);stroke-width:5" + ); + } + } +#endif + +} + +template +void test_geometry(std::string const& caseid, std::string const& wkt, + T const& expected_positive_area, + T const& expected_negative_area = T()) +{ + namespace bg = boost::geometry; + + MultiPolygon multi_polygon; + bg::read_wkt(wkt, multi_polygon); + + // Test std::vector (= multi_polygon) + test_dissolve_plusmin(caseid, multi_polygon, + expected_positive_area, + expected_negative_area); + + // Test std::vector + { + typedef typename boost::range_value::type polygon_type; + typedef typename bg::ring_type::type ring_type; + std::vector rings; + BOOST_FOREACH(polygon_type const& polygon, multi_polygon) + { + rings.push_back(bg::exterior_ring(polygon)); + } + + test_dissolve_plusmin(caseid + "_rings", rings, + expected_positive_area, + expected_negative_area); + } + + // Test different combinations +#define BOOST_GEOMETRY_TEST_PERMUTATIONS +#ifdef BOOST_GEOMETRY_TEST_PERMUTATIONS + + int n = multi_polygon.size(); + + // test them in all orders + std::vector indices; + for (int i = 0; i < n; i++) + { + indices.push_back(i); + } + int permutation = 0; + do + { + std::ostringstream out; + out << caseid; + MultiPolygon multi_polygon2; + for (int i = 0; i < n; i++) + { + int index = indices[i]; + out << "_" << index; + multi_polygon2.push_back(multi_polygon[index]); + } + test_dissolve_plusmin(out.str(), multi_polygon2, expected_positive_area, + expected_negative_area); + } while (std::next_permutation(indices.begin(), indices.end())); +#endif +} + +template +void test_all() +{ + namespace bg = boost::geometry; + typedef bg::polygon polygon; + typedef bg::multi_polygon multi_polygon; + + test_geometry("simplex_one", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)))", + 7.5); + + test_geometry("simplex_two", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)))", + 14.7); + test_geometry("simplex_three", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)))", + 16.7945); + test_geometry("simplex_four", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)),((5 5,7 7,8 4,5 5)))", + 20.7581); + + // disjoint + test_geometry("simplex_disjoint", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((1 6,2 10,5 7,1 6)),((3 4,5 6,6 2,3 4)),((6 5,8 7,9 4,6 5)))", + 24.0); + + // new hole of four + test_geometry("new_hole", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,3 6,6 3,2 2)),((3 4,5 6,6 2,3 4)),((3 1,5 4,8 4,3 1)))", + 19.5206); + + // intersection of positive/negative ring + test_geometry("plus_min_one", + "MULTIPOLYGON(((0 0,1 4,4 1,0 0)),((2 2,6 3,3 6,2 2)))", + 7.5, -7.2); + + // negative ring within a positive ring + test_geometry("plus_min_one_within", + "MULTIPOLYGON(((0 0,1 7,7 3,0 0)),((1 2,4 4,2 5,1 2)))", + 23.0, -3.5); + + // from buffer + test_geometry("from_buffer_1", + "MULTIPOLYGON(((2.4 3.03431,1.71716 3.71716,2.4 4,2.4 3.03431))" + ",((2.4 1.96569,2.4 1,1.71716 1.28284,2.4 1.96569))" + ",((2.93431 2.5,2.4 3.03431,2.4 1.96569,2.93431 2.5))" + ",((3.06569 2.5,3 2.43431,2.93431 2.5,3 2.56569,3.06569 2.5))" + ",((-0.4 5.4,4.4 5.4,4.4 3.83431,3.06569 2.5,4.4 1.16569,4.4 -0.4,-0.4 -0.4,-0.4 5.4)))" + , + 26.0596168239, -0.2854871761); + +} + +int test_main(int, char* []) +{ + test_all >(); + return 0; +} + + diff --git a/test/algorithms/overlay/dissolver.vcproj b/test/algorithms/overlay/dissolver.vcproj new file mode 100644 index 000000000..7261be872 --- /dev/null +++ b/test/algorithms/overlay/dissolver.vcproj @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/algorithms/overlay/overlay.sln b/test/algorithms/overlay/overlay.sln index 208183a02..33db5b889 100644 --- a/test/algorithms/overlay/overlay.sln +++ b/test/algorithms/overlay/overlay.sln @@ -14,6 +14,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "relative_order", "relative_ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "assemble", "assemble.vcproj", "{306E829F-ACEC-42D5-B1D4-2531B2F56EA3}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "split_rings", "split_rings.vcproj", "{271231F9-F7DA-4218-8538-0E9DCD688D09}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dissolver", "dissolver.vcproj", "{6CCB145C-C682-4B9F-8672-6D04DB5C76DD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -48,6 +52,14 @@ Global {306E829F-ACEC-42D5-B1D4-2531B2F56EA3}.Debug|Win32.Build.0 = Debug|Win32 {306E829F-ACEC-42D5-B1D4-2531B2F56EA3}.Release|Win32.ActiveCfg = Release|Win32 {306E829F-ACEC-42D5-B1D4-2531B2F56EA3}.Release|Win32.Build.0 = Release|Win32 + {271231F9-F7DA-4218-8538-0E9DCD688D09}.Debug|Win32.ActiveCfg = Debug|Win32 + {271231F9-F7DA-4218-8538-0E9DCD688D09}.Debug|Win32.Build.0 = Debug|Win32 + {271231F9-F7DA-4218-8538-0E9DCD688D09}.Release|Win32.ActiveCfg = Release|Win32 + {271231F9-F7DA-4218-8538-0E9DCD688D09}.Release|Win32.Build.0 = Release|Win32 + {6CCB145C-C682-4B9F-8672-6D04DB5C76DD}.Debug|Win32.ActiveCfg = Debug|Win32 + {6CCB145C-C682-4B9F-8672-6D04DB5C76DD}.Debug|Win32.Build.0 = Debug|Win32 + {6CCB145C-C682-4B9F-8672-6D04DB5C76DD}.Release|Win32.ActiveCfg = Release|Win32 + {6CCB145C-C682-4B9F-8672-6D04DB5C76DD}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/algorithms/overlay/split_rings.cpp b/test/algorithms/overlay/split_rings.cpp new file mode 100644 index 000000000..a7c02663a --- /dev/null +++ b/test/algorithms/overlay/split_rings.cpp @@ -0,0 +1,121 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) test file +// +// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands +// Copyright Bruno Lalande 2008, 2009 +// 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) + +#include +#include +#include + +#include + +#include +#include + +#include + +#include +#include + + +#if defined(TEST_WITH_SVG) +# include +#endif + + +struct test_split_rings +{ + template + static void apply(std::string const& id, + Geometry const& geometry, + int expected_ring_count, + double precision) + { + namespace bg = boost::geometry; + + typedef typename bg::ring_type::type ring_type; + std::vector rings; + bg::split_rings(geometry, rings); + + BOOST_CHECK_EQUAL(rings.size(), expected_ring_count); + + +#if defined(TEST_WITH_SVG) + { + std::ostringstream filename; + filename << "split_rings_" << id << ".svg"; + + std::ofstream svg(filename.str().c_str()); + + bg::svg_mapper::type> mapper(svg, 500, 500); + mapper.add(geometry); + + mapper.map(geometry, "fill:rgb(255,255,128);stroke:rgb(0,0,0);stroke-width:1"); + + BOOST_FOREACH(ring_type const& ring, rings) + { + std::string style = "opacity:0.6;fill:rgb"; + std::string color = bg::area(ring) > 0 ? "(255,0,0)" : "(0,0,255)"; + mapper.map(ring, style + color + ";stroke:rgb(128,128,128);stroke-width:3"); + } + } +#endif + } +}; + + +template +void test_geometry(std::string const& caseid, + std::string const& wkt, + int expected_ring_count, double precision = 0.001) +{ + if (wkt.empty()) + { + return; + } + + Geometry geometry; + boost::geometry::read_wkt(wkt, geometry); + + test_split_rings::apply(caseid, geometry, expected_ring_count, precision); +} + + +#if ! defined(GEOMETRY_TEST_MULTI) + +template +void test_self_all() +{ + typedef boost::geometry::polygon

polygon; + + // Simplex + + test_geometry("1", "POLYGON((0 0,0 10,10 10,5 2,5 8,10 0,0 0))", 2); + + // From "mill" (flower) + test_geometry("2", + "POLYGON((5 6.10557,3.64223 8.82111,4.28284 8.71716,2.28284 6.71716,2.17889 7.35777,4.89443 6,2.17889 4.64223,2.28284 5.28284,4.28284 3.28284,3.62547 3.14045,5 6.10557))", + 5); + + test_geometry("3", + "POLYGON((0.6 10.4,9.4 10.4,9.4 -0.4,7.59 -0.4,4.59 5.33667,4.25383 5.6797,2.67526 4.89042,4.28284 3.28284,3.62547 3.14045,5.15 7.20587,5.15 -0.4,0.6 -0.4,0.6 10.4))", + 4); + + test_geometry("4", + "POLYGON((0.6 10.4,9.4 10.4,9.4 -0.4,4.59 -0.4,4.59 5.5,4.70431 5.22003,3.93716 6.00284,5 7.06569,6.06284 6.00284,5.29569 5.22003,5.41 5.5,5.41 0.01,5.01 0.41,5.25 0.41,4.85 0.01,4.85 7.20587,6.37453 3.14045,5.71716 3.28284,7.71716 5.28284,7.82111 4.64223,5.10557 6,7.82111 7.35777,7.71716 6.71716,5.71716 8.71716,6.35777 8.82111,5 6.10557,3.64223 8.82111,4.28284 8.71716,2.28284 6.71716,2.17889 7.35777,4.89443 6,2.17889 4.64223,2.28284 5.28284,4.28284 3.28284,3.62547 3.14045,5.15 7.20587,5.15 -0.4,0.6 -0.4,0.6 10.4))", + 21); +} +#endif + + + +#if ! defined(GEOMETRY_TEST_MULTI) +int test_main(int, char* []) +{ + test_self_all >(); + return 0; +} +#endif diff --git a/test/algorithms/overlay/split_rings.vcproj b/test/algorithms/overlay/split_rings.vcproj new file mode 100644 index 000000000..d31189e22 --- /dev/null +++ b/test/algorithms/overlay/split_rings.vcproj @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/algorithms/sectionalize.cpp b/test/algorithms/sectionalize.cpp index 328158575..75492e4cd 100644 --- a/test/algorithms/sectionalize.cpp +++ b/test/algorithms/sectionalize.cpp @@ -21,17 +21,53 @@ #include + +namespace bg = boost::geometry; + + +template +void test_sectionalize_part() +{ + typedef typename bg::point_type::type point_type; + typedef bg::box box_type; + + typedef bg::sections sections_type; + typedef typename boost::range_value::type section_type; + + typedef bg::detail::sectionalize::sectionalize_part + < + Geometry, point_type, sections_type, 1, 10 + > sectionalize_part; + + sections_type sections; + section_type section; + + + Geometry geometry; + geometry.push_back(bg::make(1, 1)); + + int index = 0; + int ndi = 0; + sectionalize_part::apply(sections, section, index, ndi, geometry); + // There should not yet be anything generated, because it is only ONE point + + geometry.push_back(bg::make(2, 2)); + sectionalize_part::apply(sections, section, index, ndi, geometry); + +} + + template void test_sectionalize(G const& g, std::size_t section_count, std::string const& index_check, std::string const& dir_check, bool sort = false) { - typedef typename boost::geometry::point_type::type point; - typedef boost::geometry::box box; - typedef boost::geometry::sections sections; + typedef typename bg::point_type::type point; + typedef bg::box box; + typedef bg::sections sections; sections s; - boost::geometry::sectionalize(g, s); + bg::sectionalize(g, s); BOOST_CHECK_EQUAL(s.size(), section_count); @@ -65,8 +101,8 @@ void test_sectionalize(G const& g, std::size_t section_count, } out_sections << s[i].begin_index << ".." << s[i].end_index; - out_boxes << boost::geometry::get<0,0>(b) << " " << boost::geometry::get<0,1>(b) - << ".." << boost::geometry::get<1,0>(b) << " " << boost::geometry::get<1,1>(b); + out_boxes << bg::get<0,0>(b) << " " << bg::get<0,1>(b) + << ".." << bg::get<1,0>(b) << " " << bg::get<1,1>(b); for (int d = 0; d < DimensionCount; d++) { out_dirs << (d == 0 ? "" : " "); @@ -92,7 +128,7 @@ void test_sectionalize(G const& g, std::size_t section_count, { if (out_sections.str().length() < 80) { - std::cout << std::endl << boost::geometry::wkt(g) << std::endl; + std::cout << std::endl << bg::wkt(g) << std::endl; std::cout << out_sections.str() << std::endl; //std::cout << out_boxes.str() << std::endl; } @@ -107,7 +143,7 @@ void test_sectionalize(std::string const& wkt, bool sort = false) { G g; - boost::geometry::read_wkt(wkt, g); + bg::read_wkt(wkt, g); test_sectionalize<2>(g, count2, s2, d2, sort); test_sectionalize<1>(g, count1, s1, d1, sort); } @@ -115,57 +151,59 @@ void test_sectionalize(std::string const& wkt, template void test_all() { - test_sectionalize >( + test_sectionalize_part<1, bg::linestring

>(); + + test_sectionalize >( "LINESTRING(1 1,2 2,3 0,5 0,5 8)", 4, "0..1|1..2|2..3|3..4", "+ +|+ -|+ .|. +", 2, "0..3|3..4", "+|."); - test_sectionalize >( + test_sectionalize >( "POLYGON((0 0,0 7,4 2,2 0,0 0))", 4, "0..1|1..2|2..3|3..4", ". +|+ -|- -|- .", // . + - - -> 3 sections 3, "0..1|1..2|2..4", ".|+|-"); - test_sectionalize > + test_sectionalize > ("polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6,3.4 2.0, 4.1 3.0, 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7,2.0 1.3))", 8, "0..2|2..3|3..4|4..5|5..6|6..8|8..10|10..11", "+ +|+ -|+ +|- +|+ +|+ -|- -|- +", 4, "0..4|4..5|5..8|8..11", "+|-|+|-"); - test_sectionalize >( + test_sectionalize >( "POLYGON((3 1,2 2,1 3,2 4,3 5,4 4,5 3,4 2,3 1))", 4, "0..2|2..4|4..6|6..8", "- +|+ +|+ -|- -", // - - - + + + + - - -> 3 sections 3, "0..2|2..6|6..8", "-|+|-"); // With holes - test_sectionalize >( + test_sectionalize >( "POLYGON((3 1,2 2,1 3,2 4,3 5,4 4,5 3,4 2,3 1), (3 2,2 2,3 4,3 2))", 7, "0..2|2..4|4..6|6..8|0..1|1..2|2..3", "- +|+ +|+ -|- -|- .|+ +|. -", // - - - + + + + - - - + . -> 6 sections 6, "0..2|2..6|6..8|0..1|1..2|2..3", "-|+|-|-|+|."); // With duplicates - test_sectionalize >( + test_sectionalize >( "LINESTRING(1 1,2 2,3 0,3 0,5 0,5 8)", 5, "0..1|1..2|2..3|3..4|4..5", "+ +|+ -|DUP DUP|+ .|. +", 4, "0..2|2..3|3..4|4..5", "+|DUP|+|."); // With two subsequent duplicate segments - test_sectionalize >( + test_sectionalize >( "LINESTRING(1 1,2 2,3 0,3 0,3 0,5 0,5 0,5 0,5 0,5 8)", 6, "0..1|1..2|2..4|4..5|5..8|8..9", "+ +|+ -|DUP DUP|+ .|DUP DUP|. +", 5, "0..2|2..4|4..5|5..8|8..9", "+|DUP|+|DUP|."); - typedef boost::geometry::box

B; - test_sectionalize<2, B>(boost::geometry::make(0,0,4,4), + typedef bg::box

B; + test_sectionalize<2, B>(bg::make(0,0,4,4), 4, "0..1|1..2|2..3|3..4", ". +|+ .|. -|- ."); - test_sectionalize<1, B>(boost::geometry::make(0,0,4,4), + test_sectionalize<1, B>(bg::make(0,0,4,4), 4, "0..1|1..2|2..3|3..4", ".|+|.|-"); return; // Buffer-case - test_sectionalize >( + test_sectionalize >( "POLYGON((-1.1713 0.937043,2.8287 5.93704,2.90334 6.02339,2.98433 6.10382,2.98433 6.10382,3.07121 6.17786,3.16346 6.24507,3.16346 6.24507,3.16346 6.24507,3.26056 6.30508,3.36193 6.35752,3.36193 6.35752,3.46701 6.40211,3.57517 6.43858,3.57517 6.43858,3.57517 6.43858,3.57517 6.43858,3.68579 6.46672,3.79822 6.48637,3.79822 6.48637,3.91183 6.49741,4.02595 6.49978,4.02595 6.49978,4.02595 6.49978,4.13991 6.49346,4.25307 6.4785,4.25307 6.4785,4.36476 6.45497,4.47434 6.42302,4.47434 6.42302,4.47434 6.42302,4.47434 6.42302,7.47434 5.42302,6.84189 3.52566,4.39043 4.68765,0.390434 -0.312348,-1.1713 0.937043))", 8, "0..2|2..3|3..4|4..5|5..6|6..8|8..10|10..11", "+ +|+ -|+ +|- +|+ +|+ -|- -|- +", 4, "0..4|4..5|5..8|8..11", "+|-|+|-"); @@ -173,7 +211,7 @@ void test_all() int test_main(int, char* []) { - //test_all >(); + //test_all >(); test_all >(); return 0; diff --git a/test/algorithms/test_difference.hpp b/test/algorithms/test_difference.hpp index 20b2d7ba1..75ff971bb 100644 --- a/test/algorithms/test_difference.hpp +++ b/test/algorithms/test_difference.hpp @@ -75,7 +75,7 @@ void test_difference(std::string const& caseid, G1 const& g1, G2 const& g2, #if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST) - if (expected_point_count > 0) + /*if (expected_point_count > 0) { BOOST_CHECK_MESSAGE(n == expected_point_count, "difference: " << caseid @@ -83,7 +83,7 @@ void test_difference(std::string const& caseid, G1 const& g1, G2 const& g2, << " detected: " << n << " type: " << string_from_type::name() ); - } + }*/ if (expected_count > 0) { @@ -129,15 +129,23 @@ void test_difference(std::string const& caseid, G1 const& g1, G2 const& g2, #endif } + +#ifdef BOOST_GEOMETRY_CHECK_WITH_POSTGIS +static int counter = 0; +#endif + + template void test_one(std::string const& caseid, std::string const& wkt1, std::string const& wkt2, std::size_t expected_count1, std::size_t expected_point_count1, double expected_area1, + std::size_t expected_count2, std::size_t expected_point_count2, double expected_area2, + double percentage = 0.0001) { G1 g1; @@ -157,6 +165,39 @@ void test_one(std::string const& caseid, expected_point_count1 + expected_point_count2, expected_area1 + expected_area2, percentage, true); + +#ifdef BOOST_GEOMETRY_CHECK_WITH_POSTGIS + std::cout + << (counter > 0 ? "union " : "") + << "select " << counter++ + << ", '" << caseid << "' as caseid" + << ", ST_NumPoints(ST_Difference(ST_GeomFromText('" << wkt1 << "'), " + << " ST_GeomFromText('" << wkt2 << "'))) " + << ", ST_NumGeometries(ST_Difference(ST_GeomFromText('" << wkt1 << "'), " + << " ST_GeomFromText('" << wkt2 << "'))) " + << ", ST_Area(ST_Difference(ST_GeomFromText('" << wkt1 << "'), " + << " ST_GeomFromText('" << wkt2 << "'))) " + //<< ", " << expected_area1 << " as expected_area_a" + //<< ", " << expected_count1 << " as expected_count_a" + << ", ST_NumPoints(ST_Difference(ST_GeomFromText('" << wkt2 << "'), " + << " ST_GeomFromText('" << wkt1 << "'))) " + << ", ST_NumGeometries(ST_Difference(ST_GeomFromText('" << wkt2 << "'), " + << " ST_GeomFromText('" << wkt1 << "'))) " + << ", ST_Area(ST_Difference(ST_GeomFromText('" << wkt2 << "'), " + << " ST_GeomFromText('" << wkt1 << "'))) " + //<< ", " << expected_area2 << " as expected_area_b" + //<< ", " << expected_count2 << " as expected_count_b" + << ", ST_NumPoints(ST_SymDifference(ST_GeomFromText('" << wkt1 << "'), " + << " ST_GeomFromText('" << wkt2 << "'))) " + << ", ST_NumGeometries(ST_SymDifference(ST_GeomFromText('" << wkt1 << "'), " + << " ST_GeomFromText('" << wkt2 << "'))) " + << ", ST_Area(ST_SymDifference(ST_GeomFromText('" << wkt1 << "'), " + << " ST_GeomFromText('" << wkt2 << "'))) " + //<< ", " << expected_area1 + expected_area2 << " as expected_area_s" + //<< ", " << expected_count1 + expected_count2 << " as expected_count_s" + << std::endl; +#endif + } diff --git a/test/extensions/algorithms/extension_algorithms.sln b/test/extensions/algorithms/extension_algorithms.sln index 61ff1d4ec..b8d185c92 100644 --- a/test/extensions/algorithms/extension_algorithms.sln +++ b/test/extensions/algorithms/extension_algorithms.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "midpoints", "midpoints.vcpr EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "selected", "selected.vcproj", "{22DD12E5-4AAD-4066-9C4F-4C360F7759AA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "remove_spikes", "remove_spikes.vcproj", "{3EA21C81-DE4A-410D-AABE-CDC5091DAB6E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -25,6 +27,10 @@ Global {22DD12E5-4AAD-4066-9C4F-4C360F7759AA}.Debug|Win32.Build.0 = Debug|Win32 {22DD12E5-4AAD-4066-9C4F-4C360F7759AA}.Release|Win32.ActiveCfg = Release|Win32 {22DD12E5-4AAD-4066-9C4F-4C360F7759AA}.Release|Win32.Build.0 = Release|Win32 + {3EA21C81-DE4A-410D-AABE-CDC5091DAB6E}.Debug|Win32.ActiveCfg = Debug|Win32 + {3EA21C81-DE4A-410D-AABE-CDC5091DAB6E}.Debug|Win32.Build.0 = Debug|Win32 + {3EA21C81-DE4A-410D-AABE-CDC5091DAB6E}.Release|Win32.ActiveCfg = Release|Win32 + {3EA21C81-DE4A-410D-AABE-CDC5091DAB6E}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/extensions/algorithms/remove_spikes.cpp b/test/extensions/algorithms/remove_spikes.cpp new file mode 100644 index 000000000..88317b250 --- /dev/null +++ b/test/extensions/algorithms/remove_spikes.cpp @@ -0,0 +1,103 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) test file +// +// Copyright Barend Gehrels 2010, Geodan, 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) + +#include +#include +#include + + +#include + +#include + +#include +#include +#include + +#include +#include + + + +#if defined(TEST_WITH_SVG) +# include +#endif + +template +inline void test_remove_spikes(std::string const& id, + Geometry const& geometry, + int expected_count) +{ + namespace bg = boost::geometry; + + typedef typename bg::point_type::type point_type; + + Geometry processed = geometry; + //bg::remove_spikes(processed, bg::remove_elongated_spikes()); + bg::remove_spikes(processed, bg::remove_by_normalized()); + bg::unique(processed); + + + int detected = bg::num_points(processed); + + BOOST_CHECK_MESSAGE(detected == expected_count, + "remove_spikes: " << bg::wkt(geometry) + << " -> Expected: " << expected_count + << " detected: " << detected); + + +#if defined(TEST_WITH_SVG) + { + std::ostringstream filename; + filename << "remove_spikes_" << id << ".svg"; + std::ofstream svg(filename.str().c_str()); + + bg::svg_mapper::type> mapper(svg, 500, 500); + mapper.add(geometry); + mapper.map(geometry, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,255);stroke-width:1"); + mapper.map(processed, "opacity:0.6;fill:rgb(0,255,0);stroke:rgb(0,255,0);stroke-width:1"); + } +#endif +} + +template +void test_geometry(std::string const& id, std::string const& wkt, int expected_count) +{ + Geometry geometry; + boost::geometry::read_wkt(wkt, geometry); + test_remove_spikes(id, geometry, expected_count); +} + + +#if ! defined(GGL_TEST_MULTI) + +template +void test_all() +{ + typedef boost::geometry::linear_ring

ring; + typedef boost::geometry::polygon

polygon; + + test_geometry("box", + "POLYGON((0 0,0 4,4 4,4 0,0 0))", 5); + test_geometry("spike_right", + "POLYGON((0 0,0 4,4 4,4 2,6 2,4 2,4 0,0 0))", 6); + test_geometry("spike_at_first", + "POLYGON((0 0,-1 3,0 0,0 4,4 4,4 0,0 0))", 5); + test_geometry("spike_at_closing", + "POLYGON((-1 0,0 0,0 4,4 4,4 0,0 0,-1 0))", 5); + test_geometry("double_spike", + "POLYGON((0 0,0 4,4 4,4 2,6 2,5 2,4 2,4 0,0 0))", 6); + test_geometry("three_double_spike", + "POLYGON((0 0,0 4,4 4,4 2,6 2,5 2,4.5 2,4 2,4 0,0 0))", 6); +} + +int test_main(int, char* []) +{ + test_all >(); + return 0; +} +#endif diff --git a/test/extensions/algorithms/remove_spikes.vcproj b/test/extensions/algorithms/remove_spikes.vcproj new file mode 100644 index 000000000..1f003664c --- /dev/null +++ b/test/extensions/algorithms/remove_spikes.vcproj @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/multi/algorithms/overlay/multi_svg_mapper.hpp b/test/multi/algorithms/overlay/multi_svg_mapper.hpp index e95800dcf..206f4ea43 100644 --- a/test/multi/algorithms/overlay/multi_svg_mapper.hpp +++ b/test/multi/algorithms/overlay/multi_svg_mapper.hpp @@ -15,6 +15,9 @@ #include +namespace boost { namespace geometry +{ + #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { @@ -40,5 +43,7 @@ struct svg_map #endif +}} // namespace boost::geometry + #endif // GEOMETRY_TEST_MULTI_UTIL_SVG_MAPPER_HPP