[geometry] Fixed results for distance of integer point types point-segment

or point-linestring
This commit is contained in:
Barend Gehrels 2014-02-13 22:18:39 +01:00
parent cec1994358
commit 8af588045e
3 changed files with 25 additions and 2 deletions

View File

@ -85,7 +85,9 @@ public :
< <
Point1, Point1,
Point2, Point2,
CalculationType CalculationType,
double,
double
> >
{}; {};

View File

@ -133,8 +133,27 @@ void test_all()
test_distance_linestring<P>(); test_distance_linestring<P>();
} }
template <typename T>
void test_double_result_from_integer()
{
typedef bg::model::point<T, 2, bg::cs::cartesian> point_type;
point_type point;
bg::model::linestring<point_type> ls;
bg::read_wkt("POINT(2 2)", point);
bg::read_wkt("LINESTRING(4 1,1 4)", ls);
double dd = bg::distance(point, ls);
double dc = bg::comparable_distance(point, ls);
BOOST_CHECK_CLOSE(dd, std::sqrt(0.5), 0.001);
BOOST_CHECK_CLOSE(dc, 0.5, 0.001);
}
int test_main(int, char* []) int test_main(int, char* [])
{ {
test_double_result_from_integer<int>();
test_double_result_from_integer<boost::long_long_type>();
//test_all<bg::model::d2::point_xy<int> >(); //test_all<bg::model::d2::point_xy<int> >();
test_all<bg::model::d2::point_xy<float> >(); test_all<bg::model::d2::point_xy<float> >();
test_all<bg::model::d2::point_xy<double> >(); test_all<bg::model::d2::point_xy<double> >();

View File

@ -253,7 +253,9 @@ void test_integer(bool check_types)
if (check_types) if (check_types)
{ {
BOOST_CHECK((boost::is_same<distance_type, double>::type::value)); BOOST_CHECK((boost::is_same<distance_type, double>::type::value));
BOOST_CHECK((boost::is_same<cdistance_type, boost::long_long_type>::type::value)); // comparable_distance results in now double too, obviously because
// comp.distance point-segment can be fraction, even for integer input
BOOST_CHECK((boost::is_same<cdistance_type, double>::type::value));
} }
} }