Merge pull request #1841 from mortada/use_double_not_float

use double precision calculations instead of mixing double and float
This commit is contained in:
Patrick Niklaus
2016-01-04 11:58:07 +01:00
9 changed files with 94 additions and 94 deletions
+13 -13
View File
@@ -30,7 +30,7 @@ template <typename RTreeT> class GeospatialQuery
// Does not filter by small/big component!
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate,
const float max_distance,
const double max_distance,
const int bearing = 0,
const int bearing_range = 180)
{
@@ -40,7 +40,7 @@ template <typename RTreeT> class GeospatialQuery
{
return checkSegmentBearing(data, bearing, bearing_range);
},
[max_distance](const std::size_t, const float min_dist)
[max_distance](const std::size_t, const double min_dist)
{
return min_dist > max_distance;
});
@@ -61,7 +61,7 @@ template <typename RTreeT> class GeospatialQuery
{
return checkSegmentBearing(data, bearing, bearing_range);
},
[max_results](const std::size_t num_results, const float)
[max_results](const std::size_t num_results, const double)
{
return num_results >= max_results;
});
@@ -99,7 +99,7 @@ template <typename RTreeT> class GeospatialQuery
return use_directions;
},
[&has_big_component](const std::size_t num_results, const float)
[&has_big_component](const std::size_t num_results, const double)
{
return num_results > 0 && has_big_component;
});
@@ -132,7 +132,7 @@ template <typename RTreeT> class GeospatialQuery
const EdgeData &data) const
{
FixedPointCoordinate point_on_segment;
float ratio;
double ratio;
const auto current_perpendicular_distance = coordinate_calculation::perpendicular_distance(
coordinates->at(data.u), coordinates->at(data.v), input_coordinate, point_on_segment,
ratio);
@@ -140,7 +140,7 @@ template <typename RTreeT> class GeospatialQuery
auto transformed =
PhantomNodeWithDistance { PhantomNode{data, point_on_segment}, current_perpendicular_distance };
ratio = std::min(1.f, std::max(0.f, ratio));
ratio = std::min(1.0, std::max(0.0, ratio));
if (SPECIAL_NODEID != transformed.phantom_node.forward_node_id)
{
@@ -148,27 +148,27 @@ template <typename RTreeT> class GeospatialQuery
}
if (SPECIAL_NODEID != transformed.phantom_node.reverse_node_id)
{
transformed.phantom_node.reverse_weight *= 1.f - ratio;
transformed.phantom_node.reverse_weight *= 1.0 - ratio;
}
return transformed;
}
std::pair<bool, bool> checkSegmentBearing(const EdgeData &segment,
const float filter_bearing,
const float filter_bearing_range)
const int filter_bearing,
const int filter_bearing_range)
{
const float forward_edge_bearing =
const double forward_edge_bearing =
coordinate_calculation::bearing(coordinates->at(segment.u), coordinates->at(segment.v));
const float backward_edge_bearing = (forward_edge_bearing + 180) > 360
const double backward_edge_bearing = (forward_edge_bearing + 180) > 360
? (forward_edge_bearing - 180)
: (forward_edge_bearing + 180);
const bool forward_bearing_valid =
bearing::CheckInBounds(forward_edge_bearing, filter_bearing, filter_bearing_range) &&
bearing::CheckInBounds(std::round(forward_edge_bearing), filter_bearing, filter_bearing_range) &&
segment.forward_edge_based_node_id != SPECIAL_NODEID;
const bool backward_bearing_valid =
bearing::CheckInBounds(backward_edge_bearing, filter_bearing, filter_bearing_range) &&
bearing::CheckInBounds(std::round(backward_edge_bearing), filter_bearing, filter_bearing_range) &&
segment.reverse_edge_based_node_id != SPECIAL_NODEID;
return std::make_pair(forward_bearing_valid, backward_bearing_valid);
}
@@ -359,7 +359,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
continue;
}
matching.length = 0.0f;
matching.length = 0.0;
matching.nodes.resize(reconstructed_indices.size());
matching.indices.resize(reconstructed_indices.size());
for (const auto i : osrm::irange<std::size_t>(0u, reconstructed_indices.size()))
+2 -2
View File
@@ -34,7 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace
{
constexpr static const float COORDINATE_PRECISION = 1000000.f;
constexpr static const double COORDINATE_PRECISION = 1000000.0;
}
struct FixedPointCoordinate
@@ -58,7 +58,7 @@ struct FixedPointCoordinate
bool is_valid() const;
bool operator==(const FixedPointCoordinate &other) const;
float bearing(const FixedPointCoordinate &other) const;
double bearing(const FixedPointCoordinate &other) const;
void output(std::ostream &out) const;
};
+11 -11
View File
@@ -41,41 +41,41 @@ namespace coordinate_calculation
double haversine_distance(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate);
float great_circle_distance(const FixedPointCoordinate &first_coordinate,
double great_circle_distance(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate);
float great_circle_distance(const int lat1, const int lon1, const int lat2, const int lon2);
double great_circle_distance(const int lat1, const int lon1, const int lat2, const int lon2);
void lat_or_lon_to_string(const int value, std::string &output);
float perpendicular_distance(const FixedPointCoordinate &segment_source,
double perpendicular_distance(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location);
float perpendicular_distance(const FixedPointCoordinate &segment_source,
double perpendicular_distance(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
FixedPointCoordinate &nearest_location,
float &ratio);
double &ratio);
float perpendicular_distance_from_projected_coordinate(
double perpendicular_distance_from_projected_coordinate(
const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
const std::pair<double, double> &projected_coordinate);
float perpendicular_distance_from_projected_coordinate(
double perpendicular_distance_from_projected_coordinate(
const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
const std::pair<double, double> &projected_coordinate,
FixedPointCoordinate &nearest_location,
float &ratio);
double &ratio);
float deg_to_rad(const float degree);
float rad_to_deg(const float radian);
double deg_to_rad(const double degree);
double rad_to_deg(const double radian);
float bearing(const FixedPointCoordinate &first_coordinate,
double bearing(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate);
}
+5 -5
View File
@@ -84,7 +84,7 @@ struct RectangleInt2D
Contains(lower_left));
}
float GetMinDist(const FixedPointCoordinate &location) const
double GetMinDist(const FixedPointCoordinate &location) const
{
const bool is_contained = Contains(location);
if (is_contained)
@@ -117,7 +117,7 @@ struct RectangleInt2D
BOOST_ASSERT(d != INVALID);
float min_dist = std::numeric_limits<float>::max();
double min_dist = std::numeric_limits<double>::max();
switch (d)
{
case NORTH:
@@ -156,14 +156,14 @@ struct RectangleInt2D
break;
}
BOOST_ASSERT(min_dist < std::numeric_limits<float>::max());
BOOST_ASSERT(min_dist < std::numeric_limits<double>::max());
return min_dist;
}
float GetMinMaxDist(const FixedPointCoordinate &location) const
double GetMinMaxDist(const FixedPointCoordinate &location) const
{
float min_max_dist = std::numeric_limits<float>::max();
double min_max_dist = std::numeric_limits<double>::max();
// Get minmax distance to each of the four sides
const FixedPointCoordinate upper_left(max_lat, min_lon);
const FixedPointCoordinate upper_right(max_lat, max_lon);