osrm-backend/unit_tests/util/coordinate.cpp

27 lines
820 B
C++
Raw Normal View History

#include <boost/test/unit_test.hpp>
2016-01-02 11:13:44 -05:00
#include "util/coordinate_calculation.hpp"
#include <osrm/coordinate.hpp>
#include <cmath>
2016-01-05 10:51:13 -05:00
using namespace osrm;
using namespace osrm::util;
// Regression test for bug captured in #1347
BOOST_AUTO_TEST_CASE(regression_test_1347)
{
FixedPointCoordinate u(10 * COORDINATE_PRECISION, -100 * COORDINATE_PRECISION);
FixedPointCoordinate v(10.001 * COORDINATE_PRECISION, -100.002 * COORDINATE_PRECISION);
FixedPointCoordinate q(10.002 * COORDINATE_PRECISION, -100.001 * COORDINATE_PRECISION);
2016-01-04 07:30:03 -05:00
double d1 = coordinate_calculation::perpendicularDistance(u, v, q);
double ratio;
FixedPointCoordinate nearest_location;
2016-01-04 07:30:03 -05:00
double d2 = coordinate_calculation::perpendicularDistance(u, v, q, nearest_location, ratio);
BOOST_CHECK_LE(std::abs(d1 - d2), 0.01);
}