Skip to content

Commit

Permalink
Switch other calls to Wagyu over. But now coalesce is slow.
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Nov 15, 2023
1 parent 33052aa commit ef271ad
Show file tree
Hide file tree
Showing 15 changed files with 422 additions and 412 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ tippecanoe-enumerate: enumerate.o
tippecanoe-decode: decode.o projection.o mvt.o write_json.o text.o jsonpull/jsonpull.o dirtiles.o pmtiles_file.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3

tile-join: tile-join.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o
tile-join: tile-join.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o polygon.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread

tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o
Expand All @@ -76,7 +76,7 @@ tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o
unit: unit.o text.o sort.o mvt.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread

tippecanoe-overzoom: overzoom.o mvt.o clip.o
tippecanoe-overzoom: overzoom.o mvt.o clip.o polygon.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread

-include $(wildcard *.d)
Expand Down
31 changes: 29 additions & 2 deletions clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "errors.hpp"
#include "compression.hpp"
#include "mvt.hpp"
#include "polygon.hpp"

static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<double, double>> &geom,
long long minx, long long miny, long long maxx, long long maxy,
Expand Down Expand Up @@ -852,13 +853,17 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int

// Scale to output tile extent

to_tile_scale(geom, nz, det);
if (t == VT_POLYGON) {
geom = scale_polygon(geom, nz, det);
} else {
to_tile_scale(geom, nz, det);
}

// Clean geometries

geom = remove_noop(geom, t, 0);
if (t == VT_POLYGON) {
geom = clean_or_clip_poly(geom, 0, 0, false, false);
geom = clean_polygon(geom, 1LL << det);
geom = close_poly(geom);
}

Expand Down Expand Up @@ -929,3 +934,25 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int
return "";
}
}

/* pnpoly:
Copyright (c) 1970-2003, Wm. Randolph Franklin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution.
The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy) {
size_t i, j;
bool c = false;
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
if (((vert[i + start].y > testy) != (vert[j + start].y > testy)) &&
(testx < (vert[j + start].x - vert[i + start].x) * (testy - vert[i + start].y) / (double) (vert[j + start].y - vert[i + start].y) + vert[i + start].x))
c = !c;
}
return c;
}
22 changes: 0 additions & 22 deletions geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,6 @@ drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, long long
return out;
}

/* pnpoly:
Copyright (c) 1970-2003, Wm. Randolph Franklin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution.
The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy) {
size_t i, j;
bool c = false;
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
if (((vert[i + start].y > testy) != (vert[j + start].y > testy)) &&
(testx < (vert[j + start].x - vert[i + start].x) * (testy - vert[i + start].y) / (double) (vert[j + start].y - vert[i + start].y) + vert[i + start].x))
c = !c;
}
return c;
}

void check_polygon(drawvec &geom) {
geom = remove_noop(geom, VT_POLYGON, 0);

Expand Down
17 changes: 12 additions & 5 deletions plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "geometry.hpp"
#include "serial.hpp"
#include "errors.hpp"
#include "polygon.hpp"

extern "C" {
#include "jsonpull/jsonpull.h"
Expand Down Expand Up @@ -194,16 +195,22 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
dv = fix_polygon(dv);
}

// Scale and offset geometry from global to tile
// Offset geometry from global to tile
for (size_t i = 0; i < dv.size(); i++) {
long long scale = 1LL << (32 - z);
dv[i].x = std::round((dv[i].x - scale * x) * extent / (double) scale);
dv[i].y = std::round((dv[i].y - scale * y) * extent / (double) scale);
dv[i].x = dv[i].x - scale * x;
dv[i].y = dv[i].y - scale * y;
}
// Scale to tile extent
int detail = std::round(log(extent) / log(2));
if (t == VT_POLYGON) {
dv = scale_polygon(dv, z, detail);
} else {
to_tile_scale(dv, z, detail);
}

if (mb_geometry[t] == VT_POLYGON) {
// we can try scaling up because these are tile coordinates
dv = clean_or_clip_poly(dv, 0, 0, false, true);
dv = clean_polygon(dv, extent); // tile coordinates
if (dv.size() < 3) {
dv.clear();
}
Expand Down
22 changes: 11 additions & 11 deletions polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ void snap_round(std::vector<segment> &segs, long long extent) {
}
}

// https://www.cuemath.com/geometry/area-of-triangle-in-coordinate-geometry/
double triangle_area(drawvec const &geom, size_t base, size_t increment, size_t len) {
double area = ((double) geom[base + (increment + 0) % len].x * (geom[base + (increment + 1) % len].y - geom[base + (increment + 2) % len].y) +
(double) geom[base + (increment + 1) % len].x * (geom[base + (increment + 2) % len].y - geom[base + (increment + 0) % len].y) +
(double) geom[base + (increment + 2) % len].x * (geom[base + (increment + 0) % len].y - geom[base + (increment + 1) % len].y)) /
2;

return area;
}

struct ring_area {
drawvec geom;
double area;
Expand All @@ -446,7 +456,7 @@ struct ring_area {
long long x = (geom[i].x + geom[i + 1].x + geom[i + 2].x) / 3;
long long y = (geom[i].y + geom[i + 1].y + geom[i + 2].y) / 3;

if (get_area(geom, i, i + 3) != 0 && pnpoly(geom, 0, geom.size(), x, y)) {
if (triangle_area(geom, 0, i, geom.size() - 1) != 0 && pnpoly(geom, 0, geom.size(), x, y)) {
ear_x = x;
ear_y = y;
return;
Expand Down Expand Up @@ -689,16 +699,6 @@ drawvec remove_collinear(drawvec const &geom) {
return out;
}

// https://www.cuemath.com/geometry/area-of-triangle-in-coordinate-geometry/
double triangle_area(drawvec const &geom, size_t base, size_t increment, size_t len) {
double area = ((double) geom[base + (increment + 0) % len].x * (geom[base + (increment + 1) % len].y - geom[base + (increment + 2) % len].y) +
(double) geom[base + (increment + 1) % len].x * (geom[base + (increment + 2) % len].y - geom[base + (increment + 0) % len].y) +
(double) geom[base + (increment + 2) % len].x * (geom[base + (increment + 0) % len].y - geom[base + (increment + 1) % len].y)) /
2;

return area;
}

drawvec scale_polygon(drawvec const &geom, int z, int detail) {
double scale = 1LL << (32 - detail - z);
drawvec out;
Expand Down
10 changes: 5 additions & 5 deletions tests/coalesce-id/out/-z1_--coalesce_--reorder.json

Large diffs are not rendered by default.

Loading

0 comments on commit ef271ad

Please sign in to comment.