Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69918 - trunk/libs/geometry/test/algorithms/detail
From: barend.gehrels_at_[hidden]
Date: 2011-03-13 08:07:00


Author: barendgehrels
Date: 2011-03-13 08:06:58 EDT (Sun, 13 Mar 2011)
New Revision: 69918
URL: http://svn.boost.org/trac/boost/changeset/69918

Log:
Added unit-test for detail/partition
Added:
   trunk/libs/geometry/test/algorithms/detail/detail.sln (contents, props changed)
   trunk/libs/geometry/test/algorithms/detail/partition.cpp (contents, props changed)
   trunk/libs/geometry/test/algorithms/detail/partition.vcproj (contents, props changed)
Text files modified:
   trunk/libs/geometry/test/algorithms/detail/Jamfile.v2 | 5 ++---
   1 files changed, 2 insertions(+), 3 deletions(-)

Modified: trunk/libs/geometry/test/algorithms/detail/Jamfile.v2
==============================================================================
--- trunk/libs/geometry/test/algorithms/detail/Jamfile.v2 (original)
+++ trunk/libs/geometry/test/algorithms/detail/Jamfile.v2 2011-03-13 08:06:58 EDT (Sun, 13 Mar 2011)
@@ -1,6 +1,4 @@
-# test/algorithms/Jamfile.v2
-#
-# Copyright (c) 2010 Barend Gehrels
+# Copyright (c) 2011 Barend Gehrels
 #
 # Use, modification and distribution is subject to the Boost Software License,
 # Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -8,6 +6,7 @@
 
 test-suite boost-geometry-algorithms-detail
     :
+ [ run partition.cpp ]
     ;
 
 build-project sections ;

Added: trunk/libs/geometry/test/algorithms/detail/detail.sln
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/test/algorithms/detail/detail.sln 2011-03-13 08:06:58 EDT (Sun, 13 Mar 2011)
@@ -0,0 +1,19 @@
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual C++ Express 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "partition", "partition.vcproj", "{5EF21715-DB87-41AB-9D0A-59ED04F316A1}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5EF21715-DB87-41AB-9D0A-59ED04F316A1}.Debug|Win32.ActiveCfg = Debug|Win32
+ {5EF21715-DB87-41AB-9D0A-59ED04F316A1}.Debug|Win32.Build.0 = Debug|Win32
+ {5EF21715-DB87-41AB-9D0A-59ED04F316A1}.Release|Win32.ActiveCfg = Release|Win32
+ {5EF21715-DB87-41AB-9D0A-59ED04F316A1}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal

Added: trunk/libs/geometry/test/algorithms/detail/partition.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/test/algorithms/detail/partition.cpp 2011-03-13 08:06:58 EDT (Sun, 13 Mar 2011)
@@ -0,0 +1,142 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels, Geodan B.V. 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 <geometry_test_common.hpp>
+
+#include <algorithms/test_overlay.hpp>
+
+#include <boost/range/algorithm/copy.hpp>
+
+#include <boost/geometry/geometry.hpp>
+#include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
+#include <boost/geometry/algorithms/detail/overlay/assign_parents.hpp>
+#include <boost/geometry/algorithms/detail/partition.hpp>
+
+#include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
+
+
+template <typename Box>
+struct sample_item
+{
+ int id;
+ Box box;
+ sample_item(int i = 0, std::string const& wkt = "")
+ : id(i)
+ {
+ if (! wkt.empty())
+ {
+ bg::read_wkt(wkt, box);
+ }
+ }
+};
+
+
+struct get_box
+{
+ template <typename Box, typename InputItem>
+ static inline void apply(Box& total, InputItem const& item)
+ {
+ bg::expand(total, item.box);
+ }
+};
+
+struct ovelaps_box
+{
+ template <typename Box, typename InputItem>
+ static inline bool apply(Box const& box, InputItem const& item)
+ {
+ return ! bg::detail::disjoint::disjoint_box_box(box, item.box);
+ }
+};
+
+
+template <typename Box>
+struct sample_visitor
+{
+ int count;
+ typename bg::area_result<Box>::type area;
+
+ sample_visitor()
+ : count(0)
+ , area(0)
+ {}
+
+ template <typename Item>
+ inline void apply(Item const& item1, Item const& item2)
+ {
+ if (bg::intersects(item1.box, item2.box))
+ {
+ Box b;
+ bg::intersection(item1.box, item2.box, b);
+ area += bg::area(b);
+ count++;
+ }
+ }
+};
+
+
+
+template <typename Box>
+void test_geometry(std::string const& wkt_box_list, double expected_area, int expected_count)
+{
+ std::vector<std::string> wkt_boxes;
+
+ boost::split(wkt_boxes, wkt_box_list, boost::is_any_of(";"), boost::token_compress_on);
+
+ typedef sample_item<Box> sample;
+ std::vector<sample> boxes;
+
+ int index = 1;
+ BOOST_FOREACH(std::string const& wkt, wkt_boxes)
+ {
+ boxes.push_back(sample(index++, wkt));
+ }
+
+ sample_visitor<Box> visitor;
+ bg::partition
+ <
+ Box, get_box, ovelaps_box
+ >::apply(boxes, visitor);
+
+ BOOST_CHECK_CLOSE(visitor.area, expected_area, 0.001);
+ BOOST_CHECK_EQUAL(visitor.count, expected_count);
+}
+
+
+
+
+template <typename P>
+void test_all()
+{
+ typedef bg::model::box<P> box;
+
+ test_geometry<box>(
+ // 1 2 3 4 5 6 7
+ "box(0 0,1 1); box(0 0,2 2); box(9 9,10 10); box(8 8,9 9); box(4 4,6 6); box(2 4,6 8); box(7 1,8 2)",
+ 5, // Area(Intersection(1,2)) + A(I(5,6))
+ 3);
+
+ test_geometry<box>(
+ "box(0 0,10 10); box(4 4,6 6); box(3 3,7 7)",
+ 4 + 16 + 4, // A(I(1,2)) + A(I(1,3)) + A(I(2,3))
+ 3);
+
+ test_geometry<box>(
+ "box(0 2,10 3); box(3 1,4 5); box(7 1,8 5)",
+ 1 + 1, // A(I(1,2)) + A(I(1,3))
+ 2);
+}
+
+
+
+
+int test_main( int , char* [] )
+{
+ test_all<bg::model::d2::point_xy<double> >();
+
+ return 0;
+}

Added: trunk/libs/geometry/test/algorithms/detail/partition.vcproj
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/test/algorithms/detail/partition.vcproj 2011-03-13 08:06:58 EDT (Sun, 13 Mar 2011)
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="partition"
+ ProjectGUID="{5EF21715-DB87-41AB-9D0A-59ED04F316A1}"
+ RootNamespace="partition"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\partition"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".;../../../../..;../..;../../../../../boost/geometry/extensions/contrib/ttmath"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;TEST_WITH_SVG"
+ ExceptionHandling="2"
+ RuntimeLibrary="1"
+ UsePrecompiledHeader="0"
+ DebugInformationFormat="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\partition"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=".;../../../../..;../..;../../../../../boost/geometry/extensions/contrib/ttmath"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ ExceptionHandling="2"
+ UsePrecompiledHeader="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\partition.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk