OmniSciDB  8a228a1076
geo_compression_runtime.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 OmniSci, 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 
25 #ifndef SHARED_GEO_COMPRESSION_H
26 #define SHARED_GEO_COMPRESSION_H
27 
28 #include "funcannotations.h"
29 
30 #define COMPRESSION_NONE 0
31 #define COMPRESSION_GEOINT32 1
32 #define COMPRESSION_GEOBBINT32 2
33 #define COMPRESSION_GEOBBINT16 3
34 #define COMPRESSION_GEOBBINT8 4
35 
36 #define TOLERANCE_DEFAULT 0.000000001
37 #define TOLERANCE_GEOINT32 0.0000001
38 
39 namespace Geo_namespace {
40 
41 DEVICE inline double decompress_longitude_coord_geoint32(const int32_t compressed) {
42  // decompress longitude: -2,147,483,647..2,147,483,647 ---> -180..180
43  return static_cast<double>(compressed) *
44  8.3819031754424345e-08; // (180.0 / 2147483647.0)
45 }
46 
47 DEVICE inline double decompress_lattitude_coord_geoint32(const int32_t compressed) {
48  // decompress latitude: -2,147,483,647..2,147,483,647 ---> -90..90
49  return static_cast<double>(compressed) *
50  4.1909515877212172e-08; // // (90.0 / 2147483647.0)
51 }
52 
53 DEVICE inline bool is_null_point_longitude_geoint32(const int32_t compressed) {
54  // check compressed null point longitude: -2,147,483,648 ---> NULL
55  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
56 }
57 
58 DEVICE inline bool is_null_point_lattitude_geoint32(const int32_t compressed) {
59  // check compressed null point latitude: -2,147,483,648 ---> NULL
60  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
61 }
62 
63 DEVICE inline uint64_t compress_longitude_coord_geoint32(const double coord) {
64  // compress longitude: -180..180 ---> -2,147,483,647..2,147,483,647
65  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 180.0));
66  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
67 }
68 
69 DEVICE inline uint64_t compress_lattitude_coord_geoint32(const double coord) {
70  // compress latitude: -90..90 ---> -2,147,483,647..2,147,483,647
71  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 90.0));
72  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
73 }
74 
76  // compress null point longitude: NULL ---> -2,147,483,648
77  return 0x0000000080000000ULL;
78 }
79 
81  // compress null point latitude: NULL ---> -2,147,483,648
82  return 0x0000000080000000ULL;
83 }
84 
85 }; // namespace Geo_namespace
86 
87 #endif // SHARED_GEO_COMPRESSION_H
DEVICE constexpr uint64_t compress_null_point_lattitude_geoint32()
DEVICE bool is_null_point_longitude_geoint32(const int32_t compressed)
#define DEVICE
DEVICE uint64_t compress_longitude_coord_geoint32(const double coord)
DEVICE constexpr uint64_t compress_null_point_longitude_geoint32()
DEVICE uint64_t compress_lattitude_coord_geoint32(const double coord)
DEVICE double decompress_lattitude_coord_geoint32(const int32_t compressed)
DEVICE bool is_null_point_lattitude_geoint32(const int32_t compressed)
DEVICE double decompress_longitude_coord_geoint32(const int32_t compressed)