|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76882 - in trunk/libs/geometry/test: algorithms strategies util
From: barend.gehrels_at_[hidden]
Date: 2012-02-04 10:18:08
Author: barendgehrels
Date: 2012-02-04 10:18:06 EST (Sat, 04 Feb 2012)
New Revision: 76882
URL: http://svn.boost.org/trac/boost/changeset/76882
Log:
Added/updated unit test for distance fix, and new calculation_type meta function
Added:
trunk/libs/geometry/test/util/calculation_type.cpp (contents, props changed)
trunk/libs/geometry/test/util/calculation_type.vcproj (contents, props changed)
Text files modified:
trunk/libs/geometry/test/algorithms/distance.cpp | 45 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/geometry/test/strategies/pythagoras.cpp | 44 ++++++++++++++++++++++++++++++++++++++
trunk/libs/geometry/test/util/Jamfile.v2 | 1
trunk/libs/geometry/test/util/util_tests.sln | 6 +++++
4 files changed, 95 insertions(+), 1 deletions(-)
Modified: trunk/libs/geometry/test/algorithms/distance.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/distance.cpp (original)
+++ trunk/libs/geometry/test/algorithms/distance.cpp 2012-02-04 10:18:06 EST (Sat, 04 Feb 2012)
@@ -244,6 +244,49 @@
test_empty_input(p, ring_empty);
}
+void test_large_integers()
+{
+ typedef bg::model::point<int, 2, bg::cs::cartesian> int_point_type;
+ typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type;
+
+ // point-point
+ {
+ std::string const a = "POINT(2544000 528000)";
+ std::string const b = "POINT(2768040 528000)";
+ int_point_type ia, ib;
+ double_point_type da, db;
+ bg::read_wkt(a, ia);
+ bg::read_wkt(b, ib);
+ bg::read_wkt(a, da);
+ bg::read_wkt(b, db);
+
+ BOOST_AUTO(idist, bg::distance(ia, ib));
+ BOOST_AUTO(ddist, bg::distance(da, db));
+
+ BOOST_CHECK_MESSAGE(std::abs(idist - ddist) < 0.1,
+ "within<a double> different from within<an int>");
+ }
+ // Point-segment
+ {
+ std::string const a = "POINT(2600000 529000)";
+ std::string const b = "LINESTRING(2544000 528000, 2768040 528000)";
+ int_point_type ia;
+ double_point_type da;
+ bg::model::segment<int_point_type> ib;
+ bg::model::segment<double_point_type> db;
+ bg::read_wkt(a, ia);
+ bg::read_wkt(b, ib);
+ bg::read_wkt(a, da);
+ bg::read_wkt(b, db);
+
+ BOOST_AUTO(idist, bg::distance(ia, ib));
+ BOOST_AUTO(ddist, bg::distance(da, db));
+
+ BOOST_CHECK_MESSAGE(std::abs(idist - ddist) < 0.1,
+ "within<a double> different from within<an int>");
+ }
+}
+
int test_main(int, char* [])
{
#ifdef TEST_ARRAY
@@ -253,6 +296,8 @@
//test_all<test::test_point>(); // located here because of 3D
#endif
+ test_large_integers();
+
test_all<bg::model::d2::point_xy<int> >();
test_all<boost::tuple<float, float> >();
test_all<bg::model::d2::point_xy<float> >();
Modified: trunk/libs/geometry/test/strategies/pythagoras.cpp
==============================================================================
--- trunk/libs/geometry/test/strategies/pythagoras.cpp (original)
+++ trunk/libs/geometry/test/strategies/pythagoras.cpp 2012-02-04 10:18:06 EST (Sat, 04 Feb 2012)
@@ -233,6 +233,43 @@
"987654.32100001", "876543.21900001");
}
+template <typename CoordinateType>
+void test_integer(bool check_types)
+{
+ typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
+
+ point_type p1, p2;
+ bg::assign_values(p1, 12345678, 23456789);
+ bg::assign_values(p2, 98765432, 87654321);
+
+ typedef bg::strategy::distance::pythagoras
+ <
+ point_type
+ > pythagoras_type;
+ pythagoras_type pythagoras;
+ BOOST_AUTO(distance, pythagoras.apply(p1, p2));
+ BOOST_CHECK_CLOSE(distance, 107655455.02347542, 0.001);
+
+ typedef typename bg::strategy::distance::services::comparable_type
+ <
+ pythagoras_type
+ >::type comparable_type;
+ comparable_type comparable;
+ BOOST_AUTO(cdistance, comparable.apply(p1, p2));
+ BOOST_CHECK_EQUAL(cdistance, 11589696996311540);
+
+ typedef BOOST_TYPEOF(cdistance) cdistance_type;
+ typedef BOOST_TYPEOF(distance) distance_type;
+
+ distance_type distance2 = sqrt(distance_type(cdistance));
+ BOOST_CHECK_CLOSE(distance, distance2, 0.001);
+
+ if (check_types)
+ {
+ BOOST_CHECK((boost::is_same<distance_type, double>::type::value));
+ BOOST_CHECK((boost::is_same<cdistance_type, boost::long_long_type>::type::value));
+ }
+}
template <typename P1, typename P2>
@@ -284,6 +321,10 @@
int test_main(int, char* [])
{
+ test_integer<int>(true);
+ test_integer<boost::long_long_type>(true);
+ test_integer<double>(false);
+
test_all_3d<int[3]>();
test_all_3d<float[3]>();
test_all_3d<double[3]>();
@@ -303,7 +344,8 @@
test_services<double[3], test::test_point, float>();
- time_compare<bg::model::point<double, 2, bg::cs::cartesian> >(10000);
+ // TODO move this to another non-unit test
+ // time_compare<bg::model::point<double, 2, bg::cs::cartesian> >(10000);
#if defined(HAVE_TTMATH)
Modified: trunk/libs/geometry/test/util/Jamfile.v2
==============================================================================
--- trunk/libs/geometry/test/util/Jamfile.v2 (original)
+++ trunk/libs/geometry/test/util/Jamfile.v2 2012-02-04 10:18:06 EST (Sat, 04 Feb 2012)
@@ -10,6 +10,7 @@
test-suite boost-geometry-util
:
+ [ run calculation_type.cpp ]
[ run for_each_coordinate.cpp ]
[ run rational.cpp ]
[ run select_most_precise.cpp ]
Added: trunk/libs/geometry/test/util/calculation_type.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/test/util/calculation_type.cpp 2012-02-04 10:18:06 EST (Sat, 04 Feb 2012)
@@ -0,0 +1,206 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+// Unit Test
+
+// Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands.
+// Copyright (c) 2012 Bruno Lalande, Paris, France.
+// Copyright (c) 2012 Mateusz Loskot, London, UK.
+
+// 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 <boost/geometry/geometries/geometries.hpp>
+#include <boost/geometry/util/calculation_type.hpp>
+
+template <typename G1, typename G2>
+inline std::string helper()
+{
+ std::string result;
+ result += typeid(typename bg::coordinate_type<G1>::type).name();
+ result += "/";
+ result += typeid(typename bg::coordinate_type<G2>::type).name();
+ return result;
+}
+
+template <typename G1, typename G2, typename G3>
+inline std::string helper3()
+{
+ std::string result;
+ result += typeid(typename bg::coordinate_type<G1>::type).name();
+ result += "/";
+ result += typeid(typename bg::coordinate_type<G2>::type).name();
+ result += "/";
+ result += typeid(typename bg::coordinate_type<G3>::type).name();
+ return result;
+}
+
+template
+<
+ typename G1,
+ typename G2,
+ typename DefaultFP,
+ typename DefaultInt,
+ typename ExpectedType
+>
+void test()
+{
+ typedef typename bg::util::calculation_type::geometric::binary
+ <
+ G1,
+ G2,
+ void,
+ DefaultFP,
+ DefaultInt
+ >::type type;
+
+ std::string const caption = helper<G1, G2>();
+
+ BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value),
+ "Failure, types do not agree;"
+ << " input: " << caption
+ << " defaults: " << typeid(DefaultFP).name()
+ << "/" << typeid(DefaultInt).name()
+ << " expected: " << typeid(ExpectedType).name()
+ << " detected: " << typeid(type).name()
+ );
+}
+
+template
+<
+ typename G1,
+ typename G2,
+ typename CalculationType,
+ typename ExpectedType
+>
+void test_with_calculation_type()
+{
+ typedef typename bg::util::calculation_type::geometric::binary
+ <
+ G1,
+ G2,
+ CalculationType,
+ double,
+ int
+ >::type type;
+
+ std::string const caption = helper<G1, G2>();
+
+ BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value),
+ "Failure, types do not agree;"
+ << " input: " << caption
+ << " calculation type: " << typeid(CalculationType).name()
+ << " expected: " << typeid(ExpectedType).name()
+ << " detected: " << typeid(type).name()
+ );
+}
+
+template
+<
+ typename Geometry,
+ typename DefaultFP,
+ typename DefaultInt,
+ typename ExpectedType
+>
+void test_unary()
+{
+ typedef typename bg::util::calculation_type::geometric::unary
+ <
+ Geometry,
+ void,
+ DefaultFP,
+ DefaultInt
+ >::type type;
+
+ BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value),
+ "Failure, types do not agree;"
+ << " input: " << typeid(typename bg::coordinate_type<Geometry>::type).name()
+ << " defaults: " << typeid(DefaultFP).name()
+ << "/" << typeid(DefaultInt).name()
+ << " expected: " << typeid(ExpectedType).name()
+ << " detected: " << typeid(type).name()
+ );
+}
+
+
+template
+<
+ typename G1,
+ typename G2,
+ typename G3,
+ typename DefaultFP,
+ typename DefaultInt,
+ typename ExpectedType
+>
+void test_ternary()
+{
+ typedef typename bg::util::calculation_type::geometric::ternary
+ <
+ G1,
+ G2,
+ G3,
+ void,
+ DefaultFP,
+ DefaultInt
+ >::type type;
+
+ std::string const caption = helper3<G1, G2, G3>();
+
+ BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value),
+ "Failure, types do not agree;"
+ << " input: " << caption
+ << " defaults: " << typeid(DefaultFP).name()
+ << "/" << typeid(DefaultInt).name()
+ << " expected: " << typeid(ExpectedType).name()
+ << " detected: " << typeid(type).name()
+ );
+}
+
+
+struct user_defined {};
+
+int test_main(int, char* [])
+{
+ using namespace boost::geometry;
+ typedef model::point<double, 2, cs::cartesian> d;
+ typedef model::point<float, 2, cs::cartesian> f;
+ typedef model::point<int, 2, cs::cartesian> i;
+ typedef model::point<char, 2, cs::cartesian> c;
+ typedef model::point<short int, 2, cs::cartesian> s;
+ typedef model::point<boost::long_long_type, 2, cs::cartesian> ll;
+ typedef model::point<user_defined, 2, cs::cartesian> u;
+
+ // Calculation type "void" so
+ test<f, f, double, int, double>();
+ test<d, d, double, int, double>();
+ test<f, d, double, int, double>();
+
+ // FP/int mixed
+ test<i, f, double, int, double>();
+
+ // integers
+ test<i, i, double, int, int>();
+ test<c, i, double, int, int>();
+ test<c, c, double, char, char>();
+ test<c, c, double, int, int>();
+ test<i, i, double, boost::long_long_type, boost::long_long_type>();
+
+ // Even if we specify "int" as default-calculation-type, it should never go downwards.
+ // So it will select "long long"
+ test<ll, ll, double, int, boost::long_long_type>();
+
+ // user defined
+ test<u, i, double, char, user_defined>();
+ test<u, d, double, double, user_defined>();
+
+ test_with_calculation_type<i, i, double, double>();
+ test_with_calculation_type<u, u, double, double>();
+
+ test_unary<i, double, int, int>();
+ test_unary<u, double, double, user_defined>();
+ test_ternary<u, u, u, double, double, user_defined>();
+
+ return 0;
+}
Added: trunk/libs/geometry/test/util/calculation_type.vcproj
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/test/util/calculation_type.vcproj 2012-02-04 10:18:06 EST (Sat, 04 Feb 2012)
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="calculation_type"
+ ProjectGUID="{CF8FE803-A26B-4553-B605-9C28225B5595}"
+ RootNamespace="calculation_type"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\calculation_type"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\boost.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="../../../..;.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ 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)\calculation_type"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\boost.vsprops"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="../../../..;.."
+ 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=".\calculation_type.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Modified: trunk/libs/geometry/test/util/util_tests.sln
==============================================================================
--- trunk/libs/geometry/test/util/util_tests.sln (original)
+++ trunk/libs/geometry/test/util/util_tests.sln 2012-02-04 10:18:06 EST (Sat, 04 Feb 2012)
@@ -10,6 +10,8 @@
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rational", "rational.vcproj", "{6ABF6324-C1DC-4687-9895-B4CE2B27446F}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "calculation_type", "calculation_type.vcproj", "{CF8FE803-A26B-4553-B605-9C28225B5595}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -36,6 +38,10 @@
{6ABF6324-C1DC-4687-9895-B4CE2B27446F}.Debug|Win32.Build.0 = Debug|Win32
{6ABF6324-C1DC-4687-9895-B4CE2B27446F}.Release|Win32.ActiveCfg = Release|Win32
{6ABF6324-C1DC-4687-9895-B4CE2B27446F}.Release|Win32.Build.0 = Release|Win32
+ {CF8FE803-A26B-4553-B605-9C28225B5595}.Debug|Win32.ActiveCfg = Debug|Win32
+ {CF8FE803-A26B-4553-B605-9C28225B5595}.Debug|Win32.Build.0 = Debug|Win32
+ {CF8FE803-A26B-4553-B605-9C28225B5595}.Release|Win32.ActiveCfg = Release|Win32
+ {CF8FE803-A26B-4553-B605-9C28225B5595}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
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