2015-01-20 10:24:49 -05:00
|
|
|
/*
|
|
|
|
|
2015-02-19 03:19:51 -05:00
|
|
|
Copyright (c) 2015, Project OSRM contributors
|
2015-01-20 10:24:49 -05:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-01-16 11:23:29 -05:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/coordinate_calculation.hpp"
|
2015-01-20 10:24:49 -05:00
|
|
|
|
2015-01-15 18:49:43 -05:00
|
|
|
#include <osrm/coordinate.hpp>
|
|
|
|
|
2015-01-16 11:23:29 -05:00
|
|
|
#include <cmath>
|
2015-01-15 18:49:43 -05:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2015-12-26 14:12:10 -05:00
|
|
|
double d1 = coordinate_calculation::perpendicular_distance(u, v, q);
|
2015-01-15 18:49:43 -05:00
|
|
|
|
2015-12-26 14:12:10 -05:00
|
|
|
double ratio;
|
2015-01-15 18:49:43 -05:00
|
|
|
FixedPointCoordinate nearest_location;
|
2015-12-26 14:12:10 -05:00
|
|
|
double d2 = coordinate_calculation::perpendicular_distance(u, v, q, nearest_location, ratio);
|
2015-01-15 18:49:43 -05:00
|
|
|
|
2015-12-26 14:12:10 -05:00
|
|
|
BOOST_CHECK_LE(std::abs(d1 - d2), 0.01);
|
2015-01-15 18:49:43 -05:00
|
|
|
}
|