diff --git a/test/algorithms/similarity/Jamfile.v2 b/test/algorithms/similarity/Jamfile.v2 index cd4dc2933..13e21d456 100644 --- a/test/algorithms/similarity/Jamfile.v2 +++ b/test/algorithms/similarity/Jamfile.v2 @@ -11,4 +11,5 @@ test-suite boost-geometry-algorithms-length : [ run hausdorff_distance.cpp : : : : algorithms_hausdorff_distance ] + [ run frechet_distance.cpp : : : : algorithms_frechet_distance ] ; diff --git a/test/algorithms/similarity/frechet_distance.cpp b/test/algorithms/similarity/frechet_distance.cpp new file mode 100644 index 000000000..90ccd7101 --- /dev/null +++ b/test/algorithms/similarity/frechet_distance.cpp @@ -0,0 +1,58 @@ +// Boost.Geometry + +// Copyright (c) 2018 Yaghyavardhan Singh Khangarot, Hyderabad, India. + +// Contributed and/or modified by Yaghyavardhan Singh Khangarot, as part of Google Summer of Code 2018 program. + +// 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_DEBUG + +#include "./test_frechet_distance.hpp" + +#include +#include +#include +#include + +using namespace boost::geometry; + +template +void test_all() +{ + typedef model::linestring

linestring_2d; + + #ifdef BOOST_GEOMETRY_TEST_DEBUG + typedef typename coordinate_system

::type CordType; + std::cout << typeid(CordType).name() << std::endl; + #endif + + test_geometry("LINESTRING(3 0,2 1,3 2)","LINESTRING(0 0,3 4,4 3)", 3); + test_geometry("LINESTRING(3 0,2 1,3 2)","LINESTRING(0 0,3 4,4 3)",strategy::distance::pythagoras<>(), 3); + test_geometry("LINESTRING(0 0,3 4,4 3)","LINESTRING(0 0,3 4,4 3)", 0); + test_geometry("LINESTRING(0 0,3 4,4 3)","LINESTRING(0 0,3 4,4 3)",strategy::distance::pythagoras<>(), 0); + +} + +int main() +{ + //Cartesian Coordinate System + test_all >(); + test_all >(); + test_all >(); + + //Geographic Coordinate System + test_all > >(); + test_all > >(); + test_all > >(); + + //Spherical_Equatorial Coordinate System + test_all > >(); + test_all > >(); + test_all > >(); + + return 0; +} diff --git a/test/algorithms/similarity/test_frechet_distance.hpp b/test/algorithms/similarity/test_frechet_distance.hpp new file mode 100644 index 000000000..ce9c4cd48 --- /dev/null +++ b/test/algorithms/similarity/test_frechet_distance.hpp @@ -0,0 +1,153 @@ +// Boost.Geometry + +// Copyright (c) 2018 Yaghyavardhan Singh Khangarot, Hyderabad, India. + +// Contributed and/or modified by Yaghyavardhan Singh Khangarot, as part of Google Summer of Code 2018 program. + +// 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_TEST_MAIN +#include + +#ifndef BOOST_GEOMETRY_TEST_frechet_DISTANCE_HPP +#define BOOST_GEOMETRY_TEST_frechet_DISTANCE_HPP + +#define BOOST_GEOMETRY_TEST_DEBUG + +//#include +#include + +#include "../../../include/boost/geometry/algorithms/frechet_distance.hpp" +#include +#include +#include + +namespace bg = boost::geometry; + + +template +void test_frechet_distance(Geometry1 const& geometry1,Geometry2 const& geometry2, + typename bg::distance_result + < + typename bg::point_type::type, + typename bg::point_type::type + >::type expected_frechet_distance ) +{ + using namespace bg; + typedef typename distance_result + < + typename point_type::type, + typename point_type::type + >::type result_type; + long double h_distance = bg::frechet_distance(geometry1,geometry2); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << std::endl + << typeid(typename bg::coordinate_type::type).name() + << std::endl + << typeid(h_distance).name() + << std::endl + << "frechet_distance : " << bg::frechet_distance(geometry1,geometry2) + << std::endl; + std::cout << out.str(); +#endif + + // BOOST_CHECK_CLOSE(h_distance, expected_frechet_distance, 0.0001); +} + + + +template +void test_geometry(std::string const& wkt1,std::string const& wkt2, + typename bg::distance_result + < + typename bg::point_type::type, + typename bg::point_type::type + >::type expected_frechet_distance) +{ + Geometry1 geometry1; + bg::read_wkt(wkt1, geometry1); + Geometry2 geometry2; + bg::read_wkt(wkt2, geometry2); + test_frechet_distance(geometry1,geometry2,expected_frechet_distance); +#if !defined(BOOST_GEOMETRY_TEST_DEBUG) + test_frechet_distance(boost::variant(geometry1,geometry2), expected_frechet_distance); +#endif +} + +template +void test_frechet_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,Strategy strategy, + typename bg::distance_result + < + typename bg::point_type::type, + typename bg::point_type::type, + Strategy + >::type expected_frechet_distance ) +{ + using namespace bg; + typedef typename distance_result + < + typename point_type::type, + typename point_type::type, + Strategy + >::type result_type; + long double h_distance = bg::frechet_distance(geometry1,geometry2,strategy); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << std::endl + << typeid(typename bg::coordinate_type::type).name() + << std::endl + << typeid(h_distance).name() + << std::endl + << "frechet_distance : " << bg::frechet_distance(geometry1,geometry2,strategy) + << std::endl; + std::cout << out.str(); +#endif + + //BOOST_CHECK_CLOSE(h_distance, expected_frechet_distance, 0.0001); +} + + + +template +void test_geometry(std::string const& wkt1,std::string const& wkt2,Strategy strategy, + typename bg::distance_result + < + typename bg::point_type::type, + typename bg::point_type::type, + Strategy + >::type expected_frechet_distance) +{ + Geometry1 geometry1; + bg::read_wkt(wkt1, geometry1); + Geometry2 geometry2; + bg::read_wkt(wkt2, geometry2); + test_frechet_distance(geometry1,geometry2,strategy,expected_frechet_distance); +#if !defined(BOOST_GEOMETRY_TEST_DEBUG) + test_frechet_distance(boost::variant(geometry1,geometry2,strategy), expected_frechet_distance); +#endif +} + + +template +void test_empty_input(Geometry1 const& geometry1,Geometry2 const& geometry2) +{ + try + { + bg::frechet_distance(geometry1,geometry2); + } + catch(bg::empty_input_exception const& ) + { + return; + } + //BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" ); +} + + +#endif