├── .gitignore
├── CMakeLists.txt
├── COPYING
├── LICENSE.txt
├── README.md
├── apps
├── OGR.cpp
├── OGR.hpp
├── ProgramArgs.hpp
├── Utils.cpp
├── Utils.hpp
├── curse.cpp
└── pdal_util_export.hpp
├── cmake
├── hexer_utils.cmake
└── modules
│ ├── FindCairo.cmake
│ ├── GetGitRevisionDescription.cmake
│ └── GetGitRevisionDescription.cmake.in
├── h3
├── include
│ ├── algos.h
│ ├── alloc.h
│ ├── baseCells.h
│ ├── bbox.h
│ ├── constants.h
│ ├── coordijk.h
│ ├── directedEdge.h
│ ├── faceijk.h
│ ├── h3Assert.h
│ ├── h3Index.h
│ ├── h3api.h
│ ├── iterators.h
│ ├── latLng.h
│ ├── linkedGeo.h
│ ├── localij.h
│ ├── mathExtensions.h
│ ├── polyfill.h
│ ├── polygon.h
│ ├── polygonAlgos.h
│ ├── vec2d.h
│ ├── vec3d.h
│ ├── vertex.h
│ └── vertexGraph.h
└── lib
│ ├── algos.c
│ ├── baseCells.c
│ ├── bbox.c
│ ├── coordijk.c
│ ├── directedEdge.c
│ ├── faceijk.c
│ ├── h3Assert.c
│ ├── h3Index.c
│ ├── iterators.c
│ ├── latLng.c
│ ├── linkedGeo.c
│ ├── localij.c
│ ├── mathExtensions.c
│ ├── polyfill.c
│ ├── polygon.c
│ ├── vec2d.c
│ ├── vec3d.c
│ ├── vertex.c
│ └── vertexGraph.c
├── hexer
├── BaseGrid.cpp
├── BaseGrid.hpp
├── H3grid.cpp
├── H3grid.hpp
├── HexGrid.cpp
├── HexGrid.hpp
├── HexId.hpp
├── Mathpair.hpp
├── Path.cpp
├── Path.hpp
├── Processor.cpp
├── Processor.hpp
├── Segment.hpp
├── Utils.hpp
├── exception.hpp
├── export.hpp
└── hexer.hpp
├── hexer_defines.h.in
├── hobu-config.sh
├── images
├── h3bounds.png
└── serpent.png
├── lazperf
├── Extractor.hpp
├── Inserter.hpp
├── charbuf.cpp
├── charbuf.hpp
├── coderbase.hpp
├── compressor.hpp
├── decoder.hpp
├── decompressor.hpp
├── detail
│ ├── field_byte10.cpp
│ ├── field_byte10.hpp
│ ├── field_byte14.cpp
│ ├── field_byte14.hpp
│ ├── field_gpstime.hpp
│ ├── field_gpstime10.cpp
│ ├── field_gpstime10.hpp
│ ├── field_nir14.cpp
│ ├── field_nir14.hpp
│ ├── field_point10.cpp
│ ├── field_point10.hpp
│ ├── field_point14.cpp
│ ├── field_point14.hpp
│ ├── field_rgb10.cpp
│ ├── field_rgb10.hpp
│ ├── field_rgb14.cpp
│ ├── field_rgb14.hpp
│ └── field_xyz.hpp
├── encoder.hpp
├── excepts.hpp
├── filestream.cpp
├── filestream.hpp
├── header.cpp
├── header.hpp
├── las.hpp
├── lazperf.cpp
├── lazperf.hpp
├── lazperf_base.hpp
├── lazperf_user_base.hpp
├── model.hpp
├── portable_endian.hpp
├── readers.cpp
├── readers.hpp
├── streams.hpp
├── utils.hpp
├── vlr.cpp
├── vlr.hpp
├── writers.cpp
└── writers.hpp
├── make_shapes.py
└── test
├── CMakeLists.txt
├── data
├── autzen_trim.las
└── autzen_trim.laz
├── gridtest.cpp
├── gtest
└── gtest-10-06-21
│ ├── CMakeLists.txt
│ ├── CONTRIBUTING.md
│ ├── CONTRIBUTORS
│ ├── LICENSE
│ ├── README.md
│ └── googletest
│ ├── CMakeLists.txt
│ ├── README.md
│ ├── cmake
│ ├── Config.cmake.in
│ ├── gtest.pc.in
│ ├── gtest_main.pc.in
│ ├── internal_utils.cmake
│ └── libgtest.la.in
│ ├── docs
│ └── README.md
│ ├── include
│ └── gtest
│ │ ├── gtest-death-test.h
│ │ ├── gtest-matchers.h
│ │ ├── gtest-message.h
│ │ ├── gtest-param-test.h
│ │ ├── gtest-printers.h
│ │ ├── gtest-spi.h
│ │ ├── gtest-test-part.h
│ │ ├── gtest-typed-test.h
│ │ ├── gtest.h
│ │ ├── gtest_pred_impl.h
│ │ ├── gtest_prod.h
│ │ └── internal
│ │ ├── custom
│ │ ├── README.md
│ │ ├── gtest-port.h
│ │ ├── gtest-printers.h
│ │ └── gtest.h
│ │ ├── gtest-death-test-internal.h
│ │ ├── gtest-filepath.h
│ │ ├── gtest-internal.h
│ │ ├── gtest-param-util.h
│ │ ├── gtest-port-arch.h
│ │ ├── gtest-port.h
│ │ ├── gtest-string.h
│ │ └── gtest-type-util.h
│ ├── samples
│ ├── prime_tables.h
│ ├── sample1.cc
│ ├── sample1.h
│ ├── sample10_unittest.cc
│ ├── sample1_unittest.cc
│ ├── sample2.cc
│ ├── sample2.h
│ ├── sample2_unittest.cc
│ ├── sample3-inl.h
│ ├── sample3_unittest.cc
│ ├── sample4.cc
│ ├── sample4.h
│ ├── sample4_unittest.cc
│ ├── sample5_unittest.cc
│ ├── sample6_unittest.cc
│ ├── sample7_unittest.cc
│ ├── sample8_unittest.cc
│ └── sample9_unittest.cc
│ ├── scripts
│ ├── README.md
│ ├── common.py
│ ├── fuse_gtest_files.py
│ ├── gen_gtest_pred_impl.py
│ ├── gtest-config.in
│ ├── release_docs.py
│ ├── run_with_path.py
│ ├── upload.py
│ └── upload_gtest.py
│ ├── src
│ ├── gtest-all.cc
│ ├── gtest-death-test.cc
│ ├── gtest-filepath.cc
│ ├── gtest-internal-inl.h
│ ├── gtest-matchers.cc
│ ├── gtest-port.cc
│ ├── gtest-printers.cc
│ ├── gtest-test-part.cc
│ ├── gtest-typed-test.cc
│ ├── gtest.cc
│ └── gtest_main.cc
│ └── test
│ ├── BUILD.bazel
│ ├── googletest-break-on-failure-unittest.py
│ ├── googletest-break-on-failure-unittest_.cc
│ ├── googletest-catch-exceptions-test.py
│ ├── googletest-catch-exceptions-test_.cc
│ ├── googletest-color-test.py
│ ├── googletest-color-test_.cc
│ ├── googletest-death-test-test.cc
│ ├── googletest-death-test_ex_test.cc
│ ├── googletest-env-var-test.py
│ ├── googletest-env-var-test_.cc
│ ├── googletest-failfast-unittest.py
│ ├── googletest-failfast-unittest_.cc
│ ├── googletest-filepath-test.cc
│ ├── googletest-filter-unittest.py
│ ├── googletest-filter-unittest_.cc
│ ├── googletest-global-environment-unittest.py
│ ├── googletest-global-environment-unittest_.cc
│ ├── googletest-json-outfiles-test.py
│ ├── googletest-json-output-unittest.py
│ ├── googletest-list-tests-unittest.py
│ ├── googletest-list-tests-unittest_.cc
│ ├── googletest-listener-test.cc
│ ├── googletest-message-test.cc
│ ├── googletest-options-test.cc
│ ├── googletest-output-test-golden-lin.txt
│ ├── googletest-output-test.py
│ ├── googletest-output-test_.cc
│ ├── googletest-param-test-invalid-name1-test.py
│ ├── googletest-param-test-invalid-name1-test_.cc
│ ├── googletest-param-test-invalid-name2-test.py
│ ├── googletest-param-test-invalid-name2-test_.cc
│ ├── googletest-param-test-test.cc
│ ├── googletest-param-test-test.h
│ ├── googletest-param-test2-test.cc
│ ├── googletest-port-test.cc
│ ├── googletest-printers-test.cc
│ ├── googletest-setuptestsuite-test.py
│ ├── googletest-setuptestsuite-test_.cc
│ ├── googletest-shuffle-test.py
│ ├── googletest-shuffle-test_.cc
│ ├── googletest-test-part-test.cc
│ ├── googletest-throw-on-failure-test.py
│ ├── googletest-throw-on-failure-test_.cc
│ ├── googletest-uninitialized-test.py
│ ├── googletest-uninitialized-test_.cc
│ ├── gtest-typed-test2_test.cc
│ ├── gtest-typed-test_test.cc
│ ├── gtest-typed-test_test.h
│ ├── gtest-unittest-api_test.cc
│ ├── gtest_all_test.cc
│ ├── gtest_assert_by_exception_test.cc
│ ├── gtest_environment_test.cc
│ ├── gtest_help_test.py
│ ├── gtest_help_test_.cc
│ ├── gtest_json_test_utils.py
│ ├── gtest_list_output_unittest.py
│ ├── gtest_list_output_unittest_.cc
│ ├── gtest_main_unittest.cc
│ ├── gtest_no_test_unittest.cc
│ ├── gtest_pred_impl_unittest.cc
│ ├── gtest_premature_exit_test.cc
│ ├── gtest_prod_test.cc
│ ├── gtest_repeat_test.cc
│ ├── gtest_skip_check_output_test.py
│ ├── gtest_skip_environment_check_output_test.py
│ ├── gtest_skip_in_environment_setup_test.cc
│ ├── gtest_skip_test.cc
│ ├── gtest_sole_header_test.cc
│ ├── gtest_stress_test.cc
│ ├── gtest_test_macro_stack_footprint_test.cc
│ ├── gtest_test_utils.py
│ ├── gtest_testbridge_test.py
│ ├── gtest_testbridge_test_.cc
│ ├── gtest_throw_on_failure_ex_test.cc
│ ├── gtest_unittest.cc
│ ├── gtest_xml_outfile1_test_.cc
│ ├── gtest_xml_outfile2_test_.cc
│ ├── gtest_xml_outfiles_test.py
│ ├── gtest_xml_output_unittest.py
│ ├── gtest_xml_output_unittest_.cc
│ ├── gtest_xml_test_utils.py
│ ├── production.cc
│ └── production.h
├── pathstest.cpp
└── test_main.hpp.in
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 |
3 | syntax: glob
4 |
5 | CMakeFiles/
6 | CMakeCache.txt
7 | .DS_Store
8 | CTestTestfile.cmake
9 | Makefile
10 | cmake_install.cmake
11 | *.exe
12 | *.dll
13 | *.lib
14 | *.lo
15 | *.o
16 | bin/
17 | include/hexer/hexer_defines.h
18 | install_manifest.txt
19 | curse
20 |
21 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Unless otherwise indicated, all files in the PDAL distribution are
2 |
3 | Copyright (c) 2017, Hobu, Inc. (howard@hobu.co)
4 |
5 | and are released under the terms of the BSD open source license.
6 |
7 | This file contains the license terms of all files within PDAL.
8 |
9 |
10 | Overall PDAL license (BSD)
11 | ===========================
12 |
13 | Copyright (c) 2017, Hobu, Inc. (howard@hobu.co)
14 |
15 | All rights reserved.
16 |
17 | Redistribution and use in source and binary forms, with or without
18 | modification, are permitted provided that the following
19 | conditions are met:
20 |
21 | * Redistributions of source code must retain the above copyright
22 | notice, this list of conditions and the following disclaimer.
23 | * Redistributions in binary form must reproduce the above copyright
24 | notice, this list of conditions and the following disclaimer in
25 | the documentation and/or other materials provided
26 | with the distribution.
27 | * Neither the name of Hobu, Inc. or Flaxen Consulting LLC nor the
28 | names of its contributors may be used to endorse or promote
29 | products derived from this software without specific prior
30 | written permission.
31 |
32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
36 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
39 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
40 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
42 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
43 | OF SUCH DAMAGE.
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Hexer - Hexbin density and boundary generation
2 |
3 | Hexer is a [LGPL] C++ library that provides some classes for generating
4 | hexbin density surfaces and [multipolygon] boundaries for large point sets. I use
5 | the code for generating boundary polygons of large [LiDAR] collections, but it is
6 | useful in other contexts.
7 |
8 | Hexer also offers support for creating boundaries and density surfaces using Uber's [H3]
9 | geospatial indexing library. By specifying --grid h3, points can be summarized
10 | inside of H3's existing global hexagon grid. H3 [resolution] can be specified with -r,
11 | or Hexer can calculate an appropriate cell size based on the input. H3 processing
12 | currently only supports .LAS and .LAZ files with WGS84 (EPSG:4326) CRS.
13 |
14 | Hexer supports two operations at this time, density and boundary. You
15 | use hexer through the curse command:
16 |
17 | ```
18 | [howardbutler@ardere hexer (master)]$ ./bin/curse --help
19 | --------------------------------------------------------------------
20 | curse (hexer 1.4.0 at revision e2d559 with GDAL 3.9.1)
21 | --------------------------------------------------------------------
22 | command [boundary]
23 | Command to run on points ('boundary' or 'density')
24 |
25 | input
26 | Input point set to curse
27 |
28 | output, o []
29 | Specify an OGR-compatible output filename to write boundary. stdout used if none specified.
30 |
31 | edge [0]
32 | Edge distance of hexagon (hexgrid only)
33 |
34 | count [0]
35 | Number of points that must be in polygon for it to be positive space
36 |
37 | resolution, r [-1]
38 | H3 grid resolution: 0 (coarsest) - 15 (finest)
39 |
40 | grid [hexgrid]
41 | Grid type ('hexgrid' or 'h3'): proprietary HexGrid hexagons, or H3 indexed grid
42 |
43 | For more information, see the full documentation for hexer at:
44 | http://github.com/hobu/hexer
45 |
46 | ```
47 | ### H3 Processing
48 | ```
49 | $ curse density mylasfile.las --output myhexagons.shp --grid h3
50 | $ curse boundary mylasfile.las --output myboundary.shp --grid h3 -r 12
51 | ```
52 |
53 |
54 |
55 | ### Default Processing
56 | ```
57 | $ curse boundary mypointfile.shp --output myboundary.shp
58 | $ curse density mylasfile.las --output myhexagons.shp --edge 100
59 | ```
60 |
61 |
62 |
63 | [LGPL]: http://www.gnu.org/licenses/lgpl-2.1.html
64 | [LiDAR]: https://en.wikipedia.org/wiki/LIDAR
65 | [multipolygon]: http://en.wikipedia.org/wiki/Well-known_text
66 | [H3]: https://h3geo.org/
67 | [resolution]: https://h3geo.org/docs/core-library/restable
68 |
69 | [map]: http://a.tiles.mapbox.com/v3/hobu.serpent-mound.html#16.00/39.0346/-83.4353
70 |
71 |
--------------------------------------------------------------------------------
/apps/pdal_util_export.hpp:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Copyright (c) 2010, Howard Butler
3 | *
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following
8 | * conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in
14 | * the documentation and/or other materials provided
15 | * with the distribution.
16 | * * Neither the name of the Martin Isenburg or Iowa Department
17 | * of Natural Resources nor the names of its contributors may be
18 | * used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | * OF SUCH DAMAGE.
33 | ****************************************************************************/
34 |
35 | // This eliminates the need to include pdal base includes in code for the Util
36 | // library.
37 |
38 | #pragma once
39 |
40 | #ifndef PDAL_DLL
41 | #if defined(_WIN32)
42 | # define PDAL_DLL __declspec(dllexport)
43 | #else
44 | # if defined(USE_GCC_VISIBILITY_FLAG)
45 | # define PDAL_DLL __attribute__ ((visibility("default")))
46 | # else
47 | # define PDAL_DLL
48 | # endif
49 | #endif
50 | #endif
51 |
52 |
--------------------------------------------------------------------------------
/cmake/modules/GetGitRevisionDescription.cmake.in:
--------------------------------------------------------------------------------
1 | #
2 | # Internal file for GetGitRevisionDescription.cmake
3 | #
4 | # Requires CMake 2.6 or newer (uses the 'function' command)
5 | #
6 | # Original Author:
7 | # 2009-2010 Ryan Pavlik
8 | # http://academic.cleardefinition.com
9 | # Iowa State University HCI Graduate Program/VRAC
10 | #
11 | # Copyright Iowa State University 2009-2010.
12 | # Distributed under the Boost Software License, Version 1.0.
13 | # (See accompanying file LICENSE_1_0.txt or copy at
14 | # http://www.boost.org/LICENSE_1_0.txt)
15 |
16 | set(HEAD_HASH)
17 |
18 | file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
19 |
20 | string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
21 | if(HEAD_CONTENTS MATCHES "ref")
22 | # named branch
23 | string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
24 | if(EXISTS "@GIT_DIR@/${HEAD_REF}")
25 | configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
26 | elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
27 | configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
28 | set(HEAD_HASH "${HEAD_REF}")
29 | endif()
30 | else()
31 | # detached HEAD
32 | configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
33 | endif()
34 |
35 | if(NOT HEAD_HASH)
36 | file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
37 | string(STRIP "${HEAD_HASH}" HEAD_HASH)
38 | endif()
39 |
--------------------------------------------------------------------------------
/h3/include/algos.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2018, 2020 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file algos.h
17 | * @brief Hexagon grid algorithms
18 | */
19 |
20 | #ifndef ALGOS_H
21 | #define ALGOS_H
22 |
23 | #include "bbox.h"
24 | #include "coordijk.h"
25 | #include "h3api.h"
26 | #include "linkedGeo.h"
27 | #include "vertexGraph.h"
28 |
29 | // neighbor along the ijk coordinate system of the current face, rotated
30 | H3Error h3NeighborRotations(H3Index origin, Direction dir, int *rotations,
31 | H3Index *out);
32 |
33 | // IJK direction of neighbor
34 | Direction directionForNeighbor(H3Index origin, H3Index destination);
35 |
36 | // k-ring implementation
37 | void _kRingInternal(H3Index origin, int k, H3Index *out, int *distances,
38 | int maxIdx, int curK);
39 |
40 | // Create a vertex graph from a set of hexagons
41 | H3Error h3SetToVertexGraph(const H3Index *h3Set, const int numHexes,
42 | VertexGraph *out);
43 |
44 | // Create a LinkedGeoPolygon from a vertex graph
45 | void _vertexGraphToLinkedGeo(VertexGraph *graph, LinkedGeoPolygon *out);
46 |
47 | // Internal function for polygonToCells that traces a geoloop with hexagons of
48 | // a specific size
49 | H3Error _getEdgeHexagons(const GeoLoop *geoloop, int64_t numHexagons, int res,
50 | int64_t *numSearchHexes, H3Index *search,
51 | H3Index *found);
52 |
53 | // The safe gridDiskDistances algorithm.
54 | H3Error _gridDiskDistancesInternal(H3Index origin, int k, H3Index *out,
55 | int *distances, int64_t maxIdx, int curK);
56 | #endif
57 |
--------------------------------------------------------------------------------
/h3/include/alloc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file alloc.h
17 | * @brief Memory management functions
18 | *
19 | * This file contains macros and the necessary declarations to be able
20 | * to point H3 at different memory management functions than the standard
21 | * malloc/free/etc functions.
22 | */
23 |
24 | #ifndef ALLOC_H
25 | #define ALLOC_H
26 |
27 | #include "h3api.h" // for TJOIN
28 |
29 | #ifdef H3_ALLOC_PREFIX
30 | #define H3_MEMORY(name) TJOIN(H3_ALLOC_PREFIX, name)
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | void *H3_MEMORY(malloc)(size_t size);
37 | void *H3_MEMORY(calloc)(size_t num, size_t size);
38 | void *H3_MEMORY(realloc)(void *ptr, size_t size);
39 | void H3_MEMORY(free)(void *ptr);
40 |
41 | #ifdef __cplusplus
42 | }
43 | #endif
44 |
45 | #else
46 | #define H3_MEMORY(name) name
47 | #endif
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/h3/include/baseCells.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2018 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file baseCells.h
17 | * @brief Base cell related lookup tables and access functions.
18 | */
19 |
20 | #ifndef BASECELLS_H
21 | #define BASECELLS_H
22 |
23 | #include "constants.h"
24 | #include "coordijk.h"
25 | #include "faceijk.h"
26 |
27 | /** @struct BaseCellData
28 | * @brief information on a single base cell
29 | */
30 | typedef struct {
31 | FaceIJK
32 | homeFijk; ///< "home" face and normalized ijk coordinates on that face
33 | int isPentagon; ///< is this base cell a pentagon?
34 | int cwOffsetPent[2]; ///< if a pentagon, what are its two clockwise offset
35 | /// faces?
36 | } BaseCellData;
37 |
38 | #define INVALID_BASE_CELL 127
39 | extern const int baseCellNeighbors[NUM_BASE_CELLS][7];
40 | extern const int baseCellNeighbor60CCWRots[NUM_BASE_CELLS][7];
41 |
42 | // resolution 0 base cell data lookup-table (global)
43 | extern const BaseCellData baseCellData[NUM_BASE_CELLS];
44 |
45 | /** Maximum input for any component to face-to-base-cell lookup functions */
46 | #define MAX_FACE_COORD 2
47 |
48 | /** Invalid number of rotations */
49 | #define INVALID_ROTATIONS -1
50 |
51 | // Internal functions
52 | int _isBaseCellPentagon(int baseCell);
53 | bool _isBaseCellPolarPentagon(int baseCell);
54 | int _faceIjkToBaseCell(const FaceIJK *h);
55 | int _faceIjkToBaseCellCCWrot60(const FaceIJK *h);
56 | int _baseCellToCCWrot60(int baseCell, int face);
57 | void _baseCellToFaceIjk(int baseCell, FaceIJK *h);
58 | bool _baseCellIsCwOffset(int baseCell, int testFace);
59 | int _getBaseCellNeighbor(int baseCell, Direction dir);
60 | Direction _getBaseCellDirection(int originBaseCell, int destinationBaseCell);
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/h3/include/bbox.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2017, 2020-2021 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file bbox.h
17 | * @brief Geographic bounding box functions
18 | */
19 |
20 | #ifndef BBOX_H
21 | #define BBOX_H
22 |
23 | #include
24 |
25 | #include "h3api.h"
26 | #include "latLng.h"
27 |
28 | /** @struct BBox
29 | * @brief Geographic bounding box with coordinates defined in radians
30 | */
31 | typedef struct {
32 | double north; ///< north latitude
33 | double south; ///< south latitude
34 | double east; ///< east longitude
35 | double west; ///< west longitude
36 | } BBox;
37 |
38 | double bboxWidthRads(const BBox *bbox);
39 | double bboxHeightRads(const BBox *bbox);
40 | bool bboxIsTransmeridian(const BBox *bbox);
41 | void bboxCenter(const BBox *bbox, LatLng *center);
42 | bool bboxContains(const BBox *bbox, const LatLng *point);
43 | bool bboxContainsBBox(const BBox *a, const BBox *b);
44 | bool bboxOverlapsBBox(const BBox *a, const BBox *b);
45 | bool bboxEquals(const BBox *b1, const BBox *b2);
46 | CellBoundary bboxToCellBoundary(const BBox *bbox);
47 | H3Error bboxHexEstimate(const BBox *bbox, int res, int64_t *out);
48 | H3Error lineHexEstimate(const LatLng *origin, const LatLng *destination,
49 | int res, int64_t *out);
50 | void scaleBBox(BBox *bbox, double scale);
51 | void bboxNormalization(const BBox *a, const BBox *b,
52 | LongitudeNormalization *aNormalization,
53 | LongitudeNormalization *bNormalization);
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/h3/include/constants.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2017, 2020 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file constants.h
17 | * @brief Constants used by more than one source code file.
18 | */
19 |
20 | #ifndef CONSTANTS_H
21 | #define CONSTANTS_H
22 |
23 | #ifndef M_PI
24 | /** pi */
25 | #define M_PI 3.14159265358979323846
26 | #endif
27 |
28 | #ifndef M_PI_2
29 | /** pi / 2.0 */
30 | #define M_PI_2 1.5707963267948966
31 | #endif
32 |
33 | /** 2.0 * PI */
34 | #define M_2PI 6.28318530717958647692528676655900576839433
35 |
36 | /** pi / 180 */
37 | #define M_PI_180 0.0174532925199432957692369076848861271111
38 | /** 180 / pi */
39 | #define M_180_PI 57.29577951308232087679815481410517033240547
40 |
41 | /** threshold epsilon */
42 | #define EPSILON 0.0000000000000001
43 | /** sqrt(3) / 2.0 */
44 | #define M_SQRT3_2 0.8660254037844386467637231707529361834714
45 | /** sin(60') */
46 | #define M_SIN60 M_SQRT3_2
47 | /** 1/sin(60') **/
48 | #define M_RSIN60 1.1547005383792515290182975610039149112953
49 |
50 | /** one third **/
51 | #define M_ONETHIRD 0.333333333333333333333333333333333333333
52 |
53 | /** rotation angle between Class II and Class III resolution axes
54 | * (asin(sqrt(3.0 / 28.0))) */
55 | #define M_AP7_ROT_RADS 0.333473172251832115336090755351601070065900389
56 |
57 | /** sin(M_AP7_ROT_RADS) */
58 | #define M_SIN_AP7_ROT 0.3273268353539885718950318
59 |
60 | /** cos(M_AP7_ROT_RADS) */
61 | #define M_COS_AP7_ROT 0.9449111825230680680167902
62 |
63 | /** earth radius in kilometers using WGS84 authalic radius */
64 | #define EARTH_RADIUS_KM 6371.007180918475
65 |
66 | /** scaling factor from hex2d resolution 0 unit length
67 | * (or distance between adjacent cell center points
68 | * on the plane) to gnomonic unit length. */
69 | #define RES0_U_GNOMONIC 0.38196601125010500003
70 | #define INV_RES0_U_GNOMONIC 2.61803398874989588842
71 |
72 | /** max H3 resolution; H3 version 1 has 16 resolutions, numbered 0 through 15 */
73 | #define MAX_H3_RES 15
74 |
75 | /** The number of faces on an icosahedron */
76 | #define NUM_ICOSA_FACES 20
77 | /** The number of H3 base cells */
78 | #define NUM_BASE_CELLS 122
79 | /** The number of vertices in a hexagon */
80 | #define NUM_HEX_VERTS 6
81 | /** The number of vertices in a pentagon */
82 | #define NUM_PENT_VERTS 5
83 | /** The number of pentagons per resolution **/
84 | #define NUM_PENTAGONS 12
85 |
86 | /** H3 index modes */
87 | #define H3_CELL_MODE 1
88 | #define H3_DIRECTEDEDGE_MODE 2
89 | #define H3_EDGE_MODE 3
90 | #define H3_VERTEX_MODE 4
91 |
92 | #endif
93 |
--------------------------------------------------------------------------------
/h3/include/directedEdge.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017, 2020 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file directedEdge.h
17 | * @brief DirectedEdge functions for manipulating directed edge indexes.
18 | */
19 |
20 | #ifndef DIRECTEDEDGE_H
21 | #define DIRECTEDEDGE_H
22 |
23 | #include "algos.h"
24 | #include "h3Index.h"
25 |
26 | // nothing non-public in this file
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/h3/include/iterators.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /** @file iterators.h
18 | * @brief Iterator structs and functions for the children of a cell,
19 | * or cells at a given resolution.
20 | */
21 |
22 | #ifndef ITERATORS_H
23 | #define ITERATORS_H
24 |
25 | #include
26 |
27 | #include "h3api.h"
28 |
29 | /**
30 | * IterCellsChildren: struct for iterating through the descendants of
31 | * a given cell.
32 | *
33 | * Constructors:
34 | *
35 | * Initialize with either `iterInitParent` or `iterInitBaseCellNum`.
36 | * `iterInitParent` sets up an iterator for all the children of a given
37 | * parent cell at a given resolution.
38 | *
39 | * `iterInitBaseCellNum` sets up an iterator for children cells, given
40 | * a base cell number (0--121).
41 | *
42 | * Iteration:
43 | *
44 | * Step iterator with `iterStepChild`.
45 | * During the lifetime of the `IterCellsChildren`, the current iterate
46 | * is accessed via the `IterCellsChildren.h` member.
47 | * When the iterator is exhausted or if there was an error in initialization,
48 | * `IterCellsChildren.h` will be `H3_NULL` even after calling `iterStepChild`.
49 | */
50 | typedef struct {
51 | H3Index h;
52 | int _parentRes; // parent resolution
53 | int _skipDigit; // this digit skips `1` for pentagons
54 | } IterCellsChildren;
55 |
56 | DECLSPEC IterCellsChildren iterInitParent(H3Index h, int childRes);
57 | void _iterInitParent(H3Index h, int childRes, IterCellsChildren *iter);
58 | DECLSPEC IterCellsChildren iterInitBaseCellNum(int baseCellNum, int childRes);
59 | DECLSPEC void iterStepChild(IterCellsChildren *iter);
60 |
61 | /**
62 | * IterCellsResolution: struct for iterating through all cells at a given
63 | * resolution
64 | *
65 | * Constructor:
66 | *
67 | * Initialize with `IterCellsResolution`.
68 | *
69 | * Iteration:
70 | *
71 | * Step iterator with `iterStepRes`.
72 | * During the lifetime of the iterator the current iterate
73 | * is accessed via the `IterCellsResolution.h` member.
74 | * When the iterator is exhausted or if there was an error in initialization,
75 | * `IterCellsResolution.h` will be `H3_NULL` even after calling `iterStepRes`.
76 | */
77 | typedef struct {
78 | H3Index h;
79 | int _baseCellNum;
80 | int _res;
81 | IterCellsChildren _itC;
82 | } IterCellsResolution;
83 |
84 | DECLSPEC IterCellsResolution iterInitRes(int res);
85 | DECLSPEC void iterStepRes(IterCellsResolution *iter);
86 |
87 | #endif
88 |
--------------------------------------------------------------------------------
/h3/include/latLng.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2021 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file latLng.h
17 | * @brief Geodetic (lat/lng) functions.
18 | */
19 |
20 | #ifndef GEOPOINT_H
21 | #define GEOPOINT_H
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | #include "constants.h"
28 | #include "h3api.h"
29 |
30 | /** epsilon of ~0.1mm in degrees */
31 | #define EPSILON_DEG .000000001
32 | /** epsilon of ~0.1mm in radians */
33 | #define EPSILON_RAD (EPSILON_DEG * M_PI_180)
34 |
35 | typedef enum {
36 | NORMALIZE_NONE = 0, // Do not normalize
37 | NORMALIZE_EAST = 1, // Normalize negative numbers to the east
38 | NORMALIZE_WEST = 2 // Normalize positive numbers to the west
39 | } LongitudeNormalization;
40 |
41 | void setGeoDegs(LatLng *p, double latDegs, double lngDegs);
42 | double constrainLat(double lat);
43 | double constrainLng(double lng);
44 | double normalizeLng(const double lng,
45 | const LongitudeNormalization normalization);
46 |
47 | bool geoAlmostEqual(const LatLng *p1, const LatLng *p2);
48 | bool geoAlmostEqualThreshold(const LatLng *p1, const LatLng *p2,
49 | double threshold);
50 |
51 | // Internal functions
52 |
53 | double _posAngleRads(double rads);
54 | void _setGeoRads(LatLng *p, double latRads, double lngRads);
55 | double _geoAzimuthRads(const LatLng *p1, const LatLng *p2);
56 | void _geoAzDistanceRads(const LatLng *p1, double az, double distance,
57 | LatLng *p2);
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/h3/include/localij.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file localij.h
17 | * @brief Local IJ coordinate space functions.
18 | */
19 |
20 | #ifndef LOCALIJ_H
21 | #define LOCALIJ_H
22 |
23 | #include "coordijk.h"
24 | #include "h3api.h"
25 |
26 | H3Error cellToLocalIjk(H3Index origin, H3Index h3, CoordIJK *out);
27 | H3Error localIjkToCell(H3Index origin, const CoordIJK *ijk, H3Index *out);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/h3/include/mathExtensions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2018, 2022 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file mathExtensions.h
17 | * @brief Math functions that should've been in math.h but aren't
18 | */
19 |
20 | #ifndef MATHEXTENSIONS_H
21 | #define MATHEXTENSIONS_H
22 |
23 | #include
24 | #include
25 |
26 | /**
27 | * MAX returns the maximum of two values.
28 | */
29 | #define MAX(a, b) (((a) > (b)) ? (a) : (b))
30 |
31 | /** Evaluates to true if a + b would overflow for int32 */
32 | static inline bool ADD_INT32S_OVERFLOWS(int32_t a, int32_t b) {
33 | if (a > 0) {
34 | return INT32_MAX - a < b;
35 | } else {
36 | return INT32_MIN - a > b;
37 | }
38 | }
39 |
40 | /** Evaluates to true if a - b would overflow for int32 */
41 | static inline bool SUB_INT32S_OVERFLOWS(int32_t a, int32_t b) {
42 | if (a >= 0) {
43 | return INT32_MIN + a >= b;
44 | } else {
45 | return INT32_MAX + a + 1 < b;
46 | }
47 | }
48 |
49 | // Internal functions
50 | int64_t _ipow(int64_t base, int64_t exp);
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/h3/include/vec2d.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2017 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file vec2d.h
17 | * @brief 2D floating point vector functions.
18 | */
19 |
20 | #ifndef VEC2D_H
21 | #define VEC2D_H
22 |
23 | #include
24 |
25 | /** @struct Vec2d
26 | * @brief 2D floating-point vector
27 | */
28 | typedef struct {
29 | double x; ///< x component
30 | double y; ///< y component
31 | } Vec2d;
32 |
33 | // Internal functions
34 |
35 | double _v2dMag(const Vec2d *v);
36 | void _v2dIntersect(const Vec2d *p0, const Vec2d *p1, const Vec2d *p2,
37 | const Vec2d *p3, Vec2d *inter);
38 | bool _v2dAlmostEquals(const Vec2d *p0, const Vec2d *p1);
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/h3/include/vec3d.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, 2020-2021 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file vec3d.h
17 | * @brief 3D floating point vector functions.
18 | */
19 |
20 | #ifndef VEC3D_H
21 | #define VEC3D_H
22 |
23 | #include "latLng.h"
24 |
25 | /** @struct Vec3D
26 | * @brief 3D floating point structure
27 | */
28 | typedef struct {
29 | double x; ///< x component
30 | double y; ///< y component
31 | double z; ///< z component
32 | } Vec3d;
33 |
34 | void _geoToVec3d(const LatLng *geo, Vec3d *point);
35 | double _pointSquareDist(const Vec3d *p1, const Vec3d *p2);
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/h3/include/vertex.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020-2021 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file vertex.h
17 | * @brief Functions for working with cell vertexes.
18 | */
19 |
20 | #ifndef H3VERTEX_H
21 | #define H3VERTEX_H
22 |
23 | #include "faceijk.h"
24 | #include "h3Index.h"
25 |
26 | /** @struct PentagonDirectionFaces
27 | * @brief The faces in each axial direction of a given pentagon base cell
28 | */
29 | typedef struct {
30 | int baseCell; ///< base cell number
31 | int faces[NUM_PENT_VERTS]; ///< face numbers for each axial direction,
32 | /// in order, starting with J
33 | } PentagonDirectionFaces;
34 |
35 | /** Invalid vertex number */
36 | #define INVALID_VERTEX_NUM -1
37 |
38 | /** Max number of faces a base cell's descendants may appear on */
39 | #define MAX_BASE_CELL_FACES 5
40 |
41 | int vertexNumForDirection(const H3Index origin, const Direction direction);
42 | Direction directionForVertexNum(const H3Index origin, const int vertexNum);
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/h3/include/vertexGraph.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017, 2020-2021 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file vertexGraph.h
17 | * @brief Data structure for storing a graph of vertices
18 | */
19 |
20 | #ifndef VERTEX_GRAPH_H
21 | #define VERTEX_GRAPH_H
22 |
23 | #include
24 | #include
25 |
26 | #include "latLng.h"
27 |
28 | /** @struct VertexNode
29 | * @brief A single node in a vertex graph, part of a linked list
30 | */
31 | typedef struct VertexNode VertexNode;
32 | struct VertexNode {
33 | LatLng from;
34 | LatLng to;
35 | VertexNode *next;
36 | };
37 |
38 | /** @struct VertexGraph
39 | * @brief A data structure to store a graph of vertices
40 | */
41 | typedef struct {
42 | VertexNode **buckets;
43 | int numBuckets;
44 | int size;
45 | int res;
46 | } VertexGraph;
47 |
48 | void initVertexGraph(VertexGraph *graph, int numBuckets, int res);
49 |
50 | void destroyVertexGraph(VertexGraph *graph);
51 |
52 | VertexNode *addVertexNode(VertexGraph *graph, const LatLng *fromVtx,
53 | const LatLng *toVtx);
54 |
55 | int removeVertexNode(VertexGraph *graph, VertexNode *node);
56 |
57 | VertexNode *findNodeForEdge(const VertexGraph *graph, const LatLng *fromVtx,
58 | const LatLng *toVtx);
59 |
60 | VertexNode *findNodeForVertex(const VertexGraph *graph, const LatLng *fromVtx);
61 |
62 | VertexNode *firstVertexNode(const VertexGraph *graph);
63 |
64 | // Internal functions
65 | uint32_t _hashVertex(const LatLng *vertex, int res, int numBuckets);
66 | void _initVertexNode(VertexNode *node, const LatLng *fromVtx,
67 | const LatLng *toVtx);
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/h3/lib/h3Assert.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file h3Assert.c
17 | * @brief Support code for unit testing
18 | */
19 |
20 | #include "h3Assert.h"
21 |
22 | #if defined(H3_COVERAGE_TEST) || defined(H3_DEBUG)
23 | /*
24 | ** Counter used for coverage testing. Does not come into play for
25 | ** release builds.
26 | **
27 | ** Access to this global variable is not mutex protected. This might
28 | ** result in TSAN warnings. But as the variable does not exist in
29 | ** release builds, that should not be a concern.
30 | */
31 | unsigned int h3CoverageCounter;
32 | #endif
33 |
--------------------------------------------------------------------------------
/h3/lib/mathExtensions.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file mathExtensions.c
17 | * @brief Math functions that should've been in math.h but aren't
18 | */
19 |
20 | #include "mathExtensions.h"
21 |
22 | /**
23 | * _ipow does integer exponentiation efficiently. Taken from StackOverflow.
24 | *
25 | * @param base the integer base (can be positive or negative)
26 | * @param exp the integer exponent (should be nonnegative)
27 | *
28 | * @return the exponentiated value
29 | */
30 | int64_t _ipow(int64_t base, int64_t exp) {
31 | int64_t result = 1;
32 | while (exp) {
33 | if (exp & 1) result *= base;
34 | exp >>= 1;
35 | base *= base;
36 | }
37 |
38 | return result;
39 | }
40 |
--------------------------------------------------------------------------------
/h3/lib/vec2d.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2017 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file vec2d.c
17 | * @brief 2D floating point vector functions.
18 | */
19 |
20 | #include "vec2d.h"
21 |
22 | #include
23 | #include
24 | #include
25 |
26 | /**
27 | * Calculates the magnitude of a 2D cartesian vector.
28 | * @param v The 2D cartesian vector.
29 | * @return The magnitude of the vector.
30 | */
31 | double _v2dMag(const Vec2d *v) { return sqrt(v->x * v->x + v->y * v->y); }
32 |
33 | /**
34 | * Finds the intersection between two lines. Assumes that the lines intersect
35 | * and that the intersection is not at an endpoint of either line.
36 | * @param p0 The first endpoint of the first line.
37 | * @param p1 The second endpoint of the first line.
38 | * @param p2 The first endpoint of the second line.
39 | * @param p3 The second endpoint of the second line.
40 | * @param inter The intersection point.
41 | */
42 | void _v2dIntersect(const Vec2d *p0, const Vec2d *p1, const Vec2d *p2,
43 | const Vec2d *p3, Vec2d *inter) {
44 | Vec2d s1, s2;
45 | s1.x = p1->x - p0->x;
46 | s1.y = p1->y - p0->y;
47 | s2.x = p3->x - p2->x;
48 | s2.y = p3->y - p2->y;
49 |
50 | double t;
51 | t = (s2.x * (p0->y - p2->y) - s2.y * (p0->x - p2->x)) /
52 | (-s2.x * s1.y + s1.x * s2.y);
53 |
54 | inter->x = p0->x + (t * s1.x);
55 | inter->y = p0->y + (t * s1.y);
56 | }
57 |
58 | /**
59 | * Whether two 2D vectors are almost equal, within some threshold
60 | * @param v1 First vector to compare
61 | * @param v2 Second vector to compare
62 | * @return Whether the vectors are almost equal
63 | */
64 | bool _v2dAlmostEquals(const Vec2d *v1, const Vec2d *v2) {
65 | return fabs(v1->x - v2->x) < FLT_EPSILON &&
66 | fabs(v1->y - v2->y) < FLT_EPSILON;
67 | }
68 |
--------------------------------------------------------------------------------
/h3/lib/vec3d.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, 2020-2021 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /** @file vec3d.c
17 | * @brief 3D floating point vector functions.
18 | */
19 |
20 | #include "vec3d.h"
21 |
22 | #include
23 |
24 | /**
25 | * Square of a number
26 | *
27 | * @param x The input number.
28 | * @return The square of the input number.
29 | */
30 | double _square(double x) { return x * x; }
31 |
32 | /**
33 | * Calculate the square of the distance between two 3D coordinates.
34 | *
35 | * @param v1 The first 3D coordinate.
36 | * @param v2 The second 3D coordinate.
37 | * @return The square of the distance between the given points.
38 | */
39 | double _pointSquareDist(const Vec3d *v1, const Vec3d *v2) {
40 | return _square(v1->x - v2->x) + _square(v1->y - v2->y) +
41 | _square(v1->z - v2->z);
42 | }
43 |
44 | /**
45 | * Calculate the 3D coordinate on unit sphere from the latitude and longitude.
46 | *
47 | * @param geo The latitude and longitude of the point.
48 | * @param v The 3D coordinate of the point.
49 | */
50 | void _geoToVec3d(const LatLng *geo, Vec3d *v) {
51 | double r = cos(geo->lat);
52 |
53 | v->z = sin(geo->lat);
54 | v->x = cos(geo->lng) * r;
55 | v->y = sin(geo->lng) * r;
56 | }
57 |
--------------------------------------------------------------------------------
/hexer/BaseGrid.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "Mathpair.hpp"
9 | #include "Path.hpp"
10 | #include "HexId.hpp"
11 |
12 | #include
13 |
14 | namespace hexer
15 | {
16 |
17 | class HexGrid;
18 | class H3Grid;
19 |
20 | class BaseGrid
21 | {
22 | public:
23 | void addPoint(Point& p);
24 | void findShapes();
25 | void findParentPaths();
26 | bool isDense(HexId hex);
27 | void toWKT(std::ostream& output) const;
28 |
29 | // test function: adds pre-defined hexagon coordinates to the grid
30 | void setHexes(const std::vector& hexes);
31 |
32 | void setSampleSize(int num)
33 | {m_maxSample = num; }
34 | std::vector const& rootPaths() const
35 | { return m_roots; }
36 | // returns all hexagons in the grid and their counts
37 | std::unordered_map const& getHexes()
38 | { return m_counts; }
39 |
40 | virtual void addXY(double& x, double& y) = 0;
41 | virtual Point findPoint(Segment& s) = 0;
42 | virtual bool isH3() = 0;
43 |
44 | virtual H3Index ij2h3(HexId ij)
45 | { return 0; }
46 | virtual HexId h32ij(H3Index h3)
47 | { return {0,0}; }
48 |
49 | protected:
50 | BaseGrid(int dense_limit) : m_denseLimit{dense_limit}
51 | {}
52 | int increment(HexId hex);
53 |
54 | int m_maxSample;
55 | /// map of cells bordering paths at side 0 or 3
56 | std::unordered_map m_hexPaths;
57 | /// map of all hexagons containing points, and the number of points within.
58 | std::unordered_map m_counts;
59 |
60 | private:
61 | virtual bool sampling() const = 0;
62 | virtual HexId findHexagon(Point p) = 0;
63 | virtual HexId edgeHex(HexId hex, int edge) const = 0;
64 | virtual void processHeight(double height) = 0;
65 | virtual bool inGrid(HexId& h) = 0;
66 | virtual HexId moveCoord(HexId& h) = 0;
67 |
68 | void handleSamplePoint(Point& p);
69 | void addRoot(HexId hex);
70 | void removeRoot(HexId hex);
71 | void findShape(HexId root);
72 | double distance(const Point& p1, const Point& p2);
73 | double computeHexSize();
74 | void parentOrChild(Path& p);
75 | std::pair nextSegments(const Segment& s) const;
76 |
77 | /// Vector of points to use to determine hex height
78 | std::vector m_sample;
79 | /// Set of hexagons with non-dense neighbors at side 0
80 | std::unordered_set m_possibleRoots;
81 | /// List of all paths
82 | std::list m_paths;
83 | /// List of pointers to paths in m_paths to be written as roots
84 | std::vector m_roots;
85 | /// Minimum number of points for a cell to be dense
86 | int m_denseLimit;
87 | };
88 |
89 | } // namespace hexer
90 |
--------------------------------------------------------------------------------
/hexer/H3grid.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include