mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-11 21:44:04 +00:00
[test][similarity] Tests for frechet distance algorithms
This commit is contained in:
parent
3722dd5402
commit
29866d5f1f
@ -11,4 +11,5 @@
|
||||
test-suite boost-geometry-algorithms-length
|
||||
:
|
||||
[ run hausdorff_distance.cpp : : : : algorithms_hausdorff_distance ]
|
||||
[ run frechet_distance.cpp : : : : algorithms_frechet_distance ]
|
||||
;
|
||||
|
58
test/algorithms/similarity/frechet_distance.cpp
Normal file
58
test/algorithms/similarity/frechet_distance.cpp
Normal file
@ -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 <vector>
|
||||
#define BOOST_GEOMETRY_TEST_DEBUG
|
||||
|
||||
#include "./test_frechet_distance.hpp"
|
||||
|
||||
#include <boost/geometry/geometry.hpp>
|
||||
#include <boost/geometry/geometries/linestring.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
using namespace boost::geometry;
|
||||
|
||||
template <typename P>
|
||||
void test_all()
|
||||
{
|
||||
typedef model::linestring<P> linestring_2d;
|
||||
|
||||
#ifdef BOOST_GEOMETRY_TEST_DEBUG
|
||||
typedef typename coordinate_system<P>::type CordType;
|
||||
std::cout << typeid(CordType).name() << std::endl;
|
||||
#endif
|
||||
|
||||
test_geometry<linestring_2d,linestring_2d >("LINESTRING(3 0,2 1,3 2)","LINESTRING(0 0,3 4,4 3)", 3);
|
||||
test_geometry<linestring_2d,linestring_2d >("LINESTRING(3 0,2 1,3 2)","LINESTRING(0 0,3 4,4 3)",strategy::distance::pythagoras<>(), 3);
|
||||
test_geometry<linestring_2d,linestring_2d >("LINESTRING(0 0,3 4,4 3)","LINESTRING(0 0,3 4,4 3)", 0);
|
||||
test_geometry<linestring_2d,linestring_2d >("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<model::d2::point_xy<int,cs::cartesian> >();
|
||||
test_all<model::d2::point_xy<float,cs::cartesian> >();
|
||||
test_all<model::d2::point_xy<double,cs::cartesian> >();
|
||||
|
||||
//Geographic Coordinate System
|
||||
test_all<model::d2::point_xy<int,cs::geographic<degree> > >();
|
||||
test_all<model::d2::point_xy<float,cs::geographic<degree> > >();
|
||||
test_all<model::d2::point_xy<double,cs::geographic<degree> > >();
|
||||
|
||||
//Spherical_Equatorial Coordinate System
|
||||
test_all<model::d2::point_xy<int,cs::spherical_equatorial<degree> > >();
|
||||
test_all<model::d2::point_xy<float,cs::spherical_equatorial<degree> > >();
|
||||
test_all<model::d2::point_xy<double,cs::spherical_equatorial<degree> > >();
|
||||
|
||||
return 0;
|
||||
}
|
153
test/algorithms/similarity/test_frechet_distance.hpp
Normal file
153
test/algorithms/similarity/test_frechet_distance.hpp
Normal file
@ -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 <boost/test/unit_test.hpp>
|
||||
|
||||
#ifndef BOOST_GEOMETRY_TEST_frechet_DISTANCE_HPP
|
||||
#define BOOST_GEOMETRY_TEST_frechet_DISTANCE_HPP
|
||||
|
||||
#define BOOST_GEOMETRY_TEST_DEBUG
|
||||
|
||||
//#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
|
||||
#include "../../../include/boost/geometry/algorithms/frechet_distance.hpp"
|
||||
#include <boost/geometry/io/wkt/wkt.hpp>
|
||||
#include <boost/geometry/strategies/strategies.hpp>
|
||||
#include <boost/variant/variant.hpp>
|
||||
|
||||
namespace bg = boost::geometry;
|
||||
|
||||
|
||||
template <typename Geometry1,typename Geometry2>
|
||||
void test_frechet_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,
|
||||
typename bg::distance_result
|
||||
<
|
||||
typename bg::point_type<Geometry1>::type,
|
||||
typename bg::point_type<Geometry2>::type
|
||||
>::type expected_frechet_distance )
|
||||
{
|
||||
using namespace bg;
|
||||
typedef typename distance_result
|
||||
<
|
||||
typename point_type<Geometry1>::type,
|
||||
typename point_type<Geometry2>::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<Geometry1>::type).name()
|
||||
<< std::endl
|
||||
<< typeid(typename bg::coordinate_type<Geometry2>::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 <typename Geometry1,typename Geometry2>
|
||||
void test_geometry(std::string const& wkt1,std::string const& wkt2,
|
||||
typename bg::distance_result
|
||||
<
|
||||
typename bg::point_type<Geometry1>::type,
|
||||
typename bg::point_type<Geometry2>::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>(geometry1,geometry2), expected_frechet_distance);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename Geometry1,typename Geometry2 ,typename Strategy>
|
||||
void test_frechet_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,Strategy strategy,
|
||||
typename bg::distance_result
|
||||
<
|
||||
typename bg::point_type<Geometry1>::type,
|
||||
typename bg::point_type<Geometry2>::type,
|
||||
Strategy
|
||||
>::type expected_frechet_distance )
|
||||
{
|
||||
using namespace bg;
|
||||
typedef typename distance_result
|
||||
<
|
||||
typename point_type<Geometry1>::type,
|
||||
typename point_type<Geometry2>::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<Geometry1>::type).name()
|
||||
<< std::endl
|
||||
<< typeid(typename bg::coordinate_type<Geometry2>::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 <typename Geometry1,typename Geometry2,typename Strategy>
|
||||
void test_geometry(std::string const& wkt1,std::string const& wkt2,Strategy strategy,
|
||||
typename bg::distance_result
|
||||
<
|
||||
typename bg::point_type<Geometry1>::type,
|
||||
typename bg::point_type<Geometry2>::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>(geometry1,geometry2,strategy), expected_frechet_distance);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template <typename Geometry1,typename Geometry2>
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user