Does floating point help?

This commit is contained in:
Erica Fischer
2023-10-27 14:47:39 -07:00
parent 1fbc926d03
commit 0c4b5d089b
4 changed files with 7 additions and 53 deletions
+5 -44
View File
@@ -5,45 +5,6 @@ using Coord = long long;
using N = size_t;
using Point = std::array<Coord, 2>;
// Return false if the requested adjustment would give
// any of the polygons that contain vertex N a negative area
bool can_adjust(drawvec const &dv, std::vector<N> const &indices, size_t n, double *dx, double *dy) {
printf("looking for %zu\n", n);
bool again = true;
while (again) {
again = false;
for (size_t i = 0; i + 2 < indices.size(); i += 3) {
for (size_t j = 0; j < 3; j++) {
if (indices[i + j] == indices[n]) {
drawvec tri;
for (size_t k = 0; k < 3; k++) {
printf("found %zu %lld,%lld\n", i + j, dv[indices[i + k]].x, dv[indices[i + k]].y);
tri.push_back(dv[indices[i + k]]);
tri[k].op = VT_LINETO;
if (indices[i + k] == indices[n]) {
tri[k].x += *dx;
tri[k].y += *dy;
}
}
tri.push_back(tri[0]);
tri[0].op = VT_MOVETO;
printf("area %f\n", get_area(tri, 0, tri.size()));
if (get_area(tri, 0, tri.size()) < 0) {
*dx /= 2;
*dy /= 2;
again = true;
}
}
}
}
}
return true;
}
drawvec fix_by_triangulation(drawvec const &dv, int z, int detail) {
std::vector<std::vector<Point>> polygon;
drawvec out;
@@ -83,18 +44,18 @@ drawvec fix_by_triangulation(drawvec const &dv, int z, int detail) {
size_t v2 = i + ((j + 1) % 3);
size_t v3 = i + ((j + 2) % 3);
long long px, py;
double px, py;
if (distance_from_line(out[indices[v1]].x, out[indices[v1]].y, // the point
out[indices[v2]].x, out[indices[v2]].y, // start of opposite side
out[indices[v3]].x, out[indices[v3]].y, // end of opposite side
&px, &py) < scale) {
&px, &py) < 2 * scale) {
double ang = atan2(out[indices[v1]].y - py, out[indices[v1]].x - px);
// make a new triangle that is not so flat
out2.push_back(draw(VT_MOVETO, out[indices[v2]].x, out[indices[v2]].y));
out2.push_back(draw(VT_LINETO, out[indices[v3]].x, out[indices[v3]].y));
double ang = atan2(out[indices[v1]].y - py, out[indices[v1]].x - px);
out2.push_back(draw(VT_LINETO, out[indices[v1]].x + scale * cos(ang), out[indices[v1]].y + scale * sin(ang)));
out2.push_back(draw(VT_LINETO, px + 2 * scale * cos(ang), py + 2 * scale * sin(ang)));
out2.push_back(draw(VT_LINETO, out[indices[v2]].x, out[indices[v2]].y));
}
}
+1 -1
View File
@@ -334,7 +334,7 @@ bool point_within_tile(long long x, long long y, int z) {
return x >= 0 && y >= 0 && x < area && y < area;
}
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y, long long *px, long long *py) {
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y, double *px, double *py) {
long long p2x = segB_x - segA_x;
long long p2y = segB_y - segA_y;
double something = p2x * p2x + p2y * p2y;
+1 -1
View File
@@ -96,7 +96,7 @@ drawvec clip_lines(drawvec &geom, long long x1, long long y1, long long x2, long
drawvec clip_point(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
void visvalingam(drawvec &ls, size_t start, size_t end, double threshold, size_t retain);
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy);
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y, long long *px, long long *py);
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y, double *px, double *py);
std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress);
-7
View File
@@ -613,12 +613,6 @@ void *partial_feature_worker(void *v) {
drawvec geom = (*partials)[i].geoms[0];
if (t == VT_POLYGON) {
geom = clean_or_clip_poly(geom, 0, 0, false, false);
geom = fix_by_triangulation(geom, z, out_detail);
}
#if 0
if (t == VT_POLYGON) {
drawvec cleaned = clean_or_clip_poly(geom, 0, 0, false, false);
drawvec fixed = fix_by_triangulation(geom, z, out_detail);
@@ -626,7 +620,6 @@ void *partial_feature_worker(void *v) {
geom = fixed;
}
}
#endif
to_tile_scale(geom, z, out_detail);