2017-07-14 23:56:23 +00:00
|
|
|
#ifndef GEOMETRY_HPP
|
|
|
|
#define GEOMETRY_HPP
|
|
|
|
|
|
|
|
#include <vector>
|
2018-05-07 20:17:00 +00:00
|
|
|
#include <atomic>
|
2017-07-14 23:56:23 +00:00
|
|
|
#include <sqlite3.h>
|
|
|
|
|
2016-04-27 22:09:06 +00:00
|
|
|
#define VT_POINT 1
|
|
|
|
#define VT_LINE 2
|
|
|
|
#define VT_POLYGON 3
|
|
|
|
|
|
|
|
#define VT_END 0
|
|
|
|
#define VT_MOVETO 1
|
|
|
|
#define VT_LINETO 2
|
|
|
|
#define VT_CLOSEPATH 7
|
|
|
|
|
2016-05-13 22:45:33 +00:00
|
|
|
// The bitfield is to make sizeof(draw) be 16 instead of 24
|
|
|
|
// at the cost, apparently, of a 0.7% increase in running time
|
|
|
|
// for packing and unpacking.
|
2014-10-24 22:12:02 +00:00
|
|
|
struct draw {
|
2016-05-13 22:45:33 +00:00
|
|
|
long long x : 40;
|
2016-05-11 21:23:39 +00:00
|
|
|
signed char op;
|
2016-05-13 22:45:33 +00:00
|
|
|
long long y : 40;
|
2016-05-11 21:23:39 +00:00
|
|
|
signed char necessary;
|
2014-10-24 22:12:02 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
draw(int nop, long long nx, long long ny)
|
|
|
|
: x(nx),
|
|
|
|
op(nop),
|
|
|
|
y(ny),
|
|
|
|
necessary(0) {
|
2014-10-24 22:12:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
draw()
|
|
|
|
: x(0),
|
|
|
|
op(0),
|
|
|
|
y(0),
|
|
|
|
necessary(0) {
|
2015-06-03 18:21:40 +00:00
|
|
|
}
|
2016-09-23 20:06:37 +00:00
|
|
|
|
|
|
|
bool operator<(draw const &s) const {
|
|
|
|
if (y < s.y || (y == s.y && x < s.x)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(draw const &s) const {
|
|
|
|
return y == s.y && x == s.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(draw const &s) const {
|
|
|
|
return y != s.y || x != s.x;
|
|
|
|
}
|
2014-10-24 22:12:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<draw> drawvec;
|
|
|
|
|
2018-05-07 20:17:00 +00:00
|
|
|
drawvec decode_geometry(FILE *meta, std::atomic<long long> *geompos, int z, unsigned tx, unsigned ty, long long *bbox, unsigned initial_x, unsigned initial_y);
|
2014-10-24 22:12:02 +00:00
|
|
|
void to_tile_scale(drawvec &geom, int z, int detail);
|
2015-07-01 19:16:50 +00:00
|
|
|
drawvec remove_noop(drawvec geom, int type, int shift);
|
2016-12-09 18:47:03 +00:00
|
|
|
drawvec clip_point(drawvec &geom, int z, long long buffer);
|
2017-11-07 18:48:19 +00:00
|
|
|
drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip);
|
2016-12-09 18:47:03 +00:00
|
|
|
drawvec simple_clip_poly(drawvec &geom, int z, int buffer);
|
2015-10-28 21:34:57 +00:00
|
|
|
drawvec close_poly(drawvec &geom);
|
2014-10-24 22:12:02 +00:00
|
|
|
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area);
|
2016-12-09 18:47:03 +00:00
|
|
|
drawvec clip_lines(drawvec &geom, int z, long long buffer);
|
2016-11-28 22:55:22 +00:00
|
|
|
drawvec stairstep(drawvec &geom, int z, int detail);
|
2017-11-07 18:48:19 +00:00
|
|
|
bool point_within_tile(long long x, long long y, int z);
|
2016-12-09 18:47:03 +00:00
|
|
|
int quick_check(long long *bbox, int z, long long buffer);
|
2016-11-14 19:22:21 +00:00
|
|
|
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain);
|
2014-10-24 22:12:02 +00:00
|
|
|
drawvec reorder_lines(drawvec &geom);
|
2015-10-07 23:52:52 +00:00
|
|
|
drawvec fix_polygon(drawvec &geom);
|
2016-02-11 20:14:32 +00:00
|
|
|
std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms);
|
2017-11-07 18:48:19 +00:00
|
|
|
void check_polygon(drawvec &geom);
|
2016-05-05 20:39:21 +00:00
|
|
|
double get_area(drawvec &geom, size_t i, size_t j);
|
2017-02-06 22:14:34 +00:00
|
|
|
double get_mp_area(drawvec &geom);
|
2017-07-14 23:56:23 +00:00
|
|
|
|
2018-10-22 23:49:33 +00:00
|
|
|
drawvec simple_clip_poly(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
|
|
|
|
drawvec clip_lines(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
|
|
|
|
drawvec clip_point(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
|
|
|
|
|
2017-07-14 23:56:23 +00:00
|
|
|
#endif
|