OmniSciDB  17c254d2f8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 namespace Geo_namespace {
31 
32 DEVICE inline double decompress_longitude_coord_geoint32(const int32_t compressed) {
33  // decompress longitude: -2,147,483,647..2,147,483,647 ---> -180..180
34  return static_cast<double>(compressed) *
35  8.3819031754424345e-08; // (180.0 / 2147483647.0)
36 }
37 
38 DEVICE inline double decompress_lattitude_coord_geoint32(const int32_t compressed) {
39  // decompress latitude: -2,147,483,647..2,147,483,647 ---> -90..90
40  return static_cast<double>(compressed) *
41  4.1909515877212172e-08; // // (90.0 / 2147483647.0)
42 }
43 
44 DEVICE inline bool is_null_point_longitude_geoint32(const int32_t compressed) {
45  // check compressed null point longitude: -2,147,483,648 ---> NULL
46  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
47 }
48 
49 DEVICE inline bool is_null_point_lattitude_geoint32(const int32_t compressed) {
50  // check compressed null point latitude: -2,147,483,648 ---> NULL
51  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
52 }
53 
54 DEVICE inline uint64_t compress_longitude_coord_geoint32(const double coord) {
55  // compress longitude: -180..180 ---> -2,147,483,647..2,147,483,647
56  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 180.0));
57  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
58 }
59 
60 DEVICE inline uint64_t compress_lattitude_coord_geoint32(const double coord) {
61  // compress latitude: -90..90 ---> -2,147,483,647..2,147,483,647
62  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 90.0));
63  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
64 }
65 
67  // compress null point longitude: NULL ---> -2,147,483,648
68  return 0x0000000080000000ULL;
69 }
70 
72  // compress null point latitude: NULL ---> -2,147,483,648
73  return 0x0000000080000000ULL;
74 }
75 
76 }; // namespace Geo_namespace
77 
78 #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)