| 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 faceijk.h |
| 17 | * @brief FaceIJK functions including conversion to/from lat/lon. |
| 18 | * |
| 19 | * References the Vec2d cartesian coordinate systems hex2d: local face-centered |
| 20 | * coordinate system scaled a specific H3 grid resolution unit length and |
| 21 | * with x-axes aligned with the local i-axes |
| 22 | */ |
| 23 | |
| 24 | #ifndef FACEIJK_H |
| 25 | #define FACEIJK_H |
| 26 | |
| 27 | #include "coordijk.h" |
| 28 | #include "geoCoord.h" |
| 29 | #include "vec2d.h" |
| 30 | |
| 31 | /** @struct FaceIJK |
| 32 | * @brief Face number and ijk coordinates on that face-centered coordinate |
| 33 | * system |
| 34 | */ |
| 35 | typedef struct { |
| 36 | int face; ///< face number |
| 37 | CoordIJK coord; ///< ijk coordinates on that face |
| 38 | } FaceIJK; |
| 39 | |
| 40 | /** @struct FaceOrientIJK |
| 41 | * @brief Information to transform into an adjacent face IJK system |
| 42 | */ |
| 43 | typedef struct { |
| 44 | int face; ///< face number |
| 45 | CoordIJK translate; ///< res 0 translation relative to primary face |
| 46 | int ccwRot60; ///< number of 60 degree ccw rotations relative to primary |
| 47 | /// face |
| 48 | } FaceOrientIJK; |
| 49 | |
| 50 | extern const GeoCoord faceCenterGeo[NUM_ICOSA_FACES]; |
| 51 | |
| 52 | // indexes for faceNeighbors table |
| 53 | /** Invalid faceNeighbors table direction */ |
| 54 | #define INVALID -1 |
| 55 | /** Center faceNeighbors table direction */ |
| 56 | #define CENTER 0 |
| 57 | /** IJ quadrant faceNeighbors table direction */ |
| 58 | #define IJ 1 |
| 59 | /** KI quadrant faceNeighbors table direction */ |
| 60 | #define KI 2 |
| 61 | /** JK quadrant faceNeighbors table direction */ |
| 62 | #define JK 3 |
| 63 | |
| 64 | // Internal functions |
| 65 | |
| 66 | void _geoToFaceIjk(const GeoCoord* g, int res, FaceIJK* h); |
| 67 | void _geoToHex2d(const GeoCoord* g, int res, int* face, Vec2d* v); |
| 68 | void _faceIjkToGeo(const FaceIJK* h, int res, GeoCoord* g); |
| 69 | void _faceIjkToGeoBoundary(const FaceIJK* h, int res, int isPentagon, |
| 70 | GeoBoundary* g); |
| 71 | void _faceIjkPentToGeoBoundary(const FaceIJK* h, int res, GeoBoundary* g); |
| 72 | void _hex2dToGeo(const Vec2d* v, int face, int res, int substrate, GeoCoord* g); |
| 73 | int _adjustOverageClassII(FaceIJK* fijk, int res, int pentLeading4, |
| 74 | int substrate); |
| 75 | |
| 76 | #endif |
| 77 | |