/src/geos/src/shape/fractal/HilbertEncoder.cpp
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca> |
7 | | * |
8 | | * This is free software; you can redistribute and/or modify it under |
9 | | * the terms of the GNU Lesser General Public Licence as published |
10 | | * by the Free Software Foundation. |
11 | | * See the COPYING file for more information. |
12 | | * |
13 | | **********************************************************************/ |
14 | | |
15 | | #include <geos/shape/fractal/HilbertEncoder.h> |
16 | | #include <geos/shape/fractal/HilbertCode.h> |
17 | | #include <geos/geom/Coordinate.h> |
18 | | #include <geos/geom/Envelope.h> |
19 | | #include <geos/geom/Geometry.h> |
20 | | |
21 | | #include <cstdint> |
22 | | #include <vector> |
23 | | |
24 | | namespace geos { |
25 | | namespace shape { // geos.shape |
26 | | namespace fractal { // geos.shape.fractal |
27 | | |
28 | | |
29 | | HilbertEncoder::HilbertEncoder(uint32_t p_level, geom::Envelope& extent) |
30 | 0 | : level(p_level) |
31 | 0 | { |
32 | 0 | int hside = (int)std::pow(2, level) - 1; |
33 | |
|
34 | 0 | minx = extent.getMinX(); |
35 | 0 | strideX = extent.getWidth() / hside; |
36 | |
|
37 | 0 | miny = extent.getMinY(); |
38 | 0 | strideY = extent.getHeight() / hside; |
39 | 0 | } |
40 | | |
41 | | uint32_t |
42 | | HilbertEncoder::encode(const geom::Envelope* env) |
43 | 0 | { |
44 | 0 | double midx = env->getWidth()/2 + env->getMinX(); |
45 | 0 | uint32_t x = 0; |
46 | 0 | if (midx > minx && strideX != 0) |
47 | 0 | x = (uint32_t) ((midx - minx) / strideX); |
48 | |
|
49 | 0 | double midy = env->getHeight()/2 + env->getMinY(); |
50 | 0 | uint32_t y = 0; |
51 | 0 | if (midy > miny && strideY != 0) |
52 | 0 | y = (uint32_t) ((midy - miny) / strideY); |
53 | |
|
54 | 0 | return HilbertCode::encode(level, x, y); |
55 | 0 | } |
56 | | |
57 | | |
58 | | /* public static */ |
59 | | void |
60 | | HilbertEncoder::sort(std::vector<geom::Geometry*>& geoms) |
61 | 0 | { |
62 | 0 | sort(geoms.begin(), geoms.end()); |
63 | 0 | } |
64 | | |
65 | | |
66 | | } // namespace geos.shape.fractal |
67 | | } // namespace geos.shape |
68 | | } // namespace geos |