Merge pull request #226 from mapbox/c++-math

use std::fabs instead of clib fabs
This commit is contained in:
Dane Springmeyer
2016-04-26 17:03:00 -07:00
2 changed files with 11 additions and 11 deletions
+6 -6
View File
@@ -4,15 +4,15 @@
#include <stack> #include <stack>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <stdio.h> #include <cstdio>
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <cmath>
#include <sqlite3.h>
#include <limits.h> #include <limits.h>
#include "geometry.hh" #include "geometry.hh"
#include "clipper/clipper.hpp" #include "clipper/clipper.hpp"
extern "C" { extern "C" {
#include <sqlite3.h>
#include "tile.h" #include "tile.h"
#include "clip.h" #include "clip.h"
#include "projection.h" #include "projection.h"
@@ -246,7 +246,7 @@ struct ring {
} }
bool operator<(const ring &o) const { bool operator<(const ring &o) const {
if (fabs(this->area) < fabs(o.area)) { if (std::fabs(this->area) < std::fabs(o.area)) {
return true; return true;
} else { } else {
return false; return false;
@@ -811,7 +811,7 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
// inner rings must just have their area de-accumulated rather // inner rings must just have their area de-accumulated rather
// than being drawn since we don't really know where they are. // than being drawn since we don't really know where they are.
if (fabs(area) <= pixel * pixel || (area < 0 && !included_last_outer)) { if (std::fabs(area) <= pixel * pixel || (area < 0 && !included_last_outer)) {
// printf("area is only %f vs %lld so using square\n", area, pixel * pixel); // printf("area is only %f vs %lld so using square\n", area, pixel * pixel);
*accum_area += area; *accum_area += area;
@@ -1012,7 +1012,7 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e) {
for (i = first + 1; i < second; i++) { for (i = first + 1; i < second; i++) {
double temp_dist = square_distance_from_line(geom[start + i].x, geom[start + i].y, geom[start + first].x, geom[start + first].y, geom[start + second].x, geom[start + second].y); double temp_dist = square_distance_from_line(geom[start + i].x, geom[start + i].y, geom[start + first].x, geom[start + first].y, geom[start + second].x, geom[start + second].y);
double distance = fabs(temp_dist); double distance = std::fabs(temp_dist);
if (distance > e && distance > max_distance) { if (distance > e && distance > max_distance) {
farthest_element_index = i; farthest_element_index = i;
+5 -5
View File
@@ -15,7 +15,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <math.h> #include <cmath>
#include <sqlite3.h> #include <sqlite3.h>
#include <pthread.h> #include <pthread.h>
#include <errno.h> #include <errno.h>
@@ -502,7 +502,7 @@ int manage_gap(unsigned long long index, unsigned long long *previndex, double s
return 1; // Exact duplicate: can't fulfil the gap requirement return 1; // Exact duplicate: can't fulfil the gap requirement
} }
if (exp(log((index - *previndex) / scale) * gamma) >= *gap) { if (std::exp(std::log((index - *previndex) / scale) * gamma) >= *gap) {
// Dot is further from the previous than the nth root of the gap, // Dot is further from the previous than the nth root of the gap,
// so produce it, and choose a new gap at the next point. // so produce it, and choose a new gap at the next point.
*gap = 0; *gap = 0;
@@ -534,7 +534,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
long long og = *geompos_in; long long og = *geompos_in;
// XXX is there a way to do this without floating point? // XXX is there a way to do this without floating point?
int max_zoom_increment = log(child_shards) / log(4); int max_zoom_increment = std::log(child_shards) / std::log(4);
if (child_shards < 4 || max_zoom_increment < 1) { if (child_shards < 4 || max_zoom_increment < 1) {
fprintf(stderr, "Internal error: %d shards, max zoom increment %d\n", child_shards, max_zoom_increment); fprintf(stderr, "Internal error: %d shards, max zoom increment %d\n", child_shards, max_zoom_increment);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@@ -564,7 +564,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
double interval = 0; double interval = 0;
double seq = 0; double seq = 0;
if (z < basezoom) { if (z < basezoom) {
interval = exp(log(droprate) * (basezoom - z)); interval = std::exp(std::log(droprate) * (basezoom - z));
} }
double fraction_accum = 0; double fraction_accum = 0;
@@ -1181,7 +1181,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
threads = useful_threads; threads = useful_threads;
} }
// Round down to a power of 2 // Round down to a power of 2
threads = 1 << (int) (log(threads) / log(2)); threads = 1 << (int) (std::log(threads) / std::log(2));
// Assign temporary files to threads // Assign temporary files to threads