OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompressionRuntime.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 
24 #pragma once
25 
26 #include "../Shared/funcannotations.h"
27 
28 #define COMPRESSION_NONE 0
29 #define COMPRESSION_GEOINT32 1
30 #define COMPRESSION_GEOBBINT32 2
31 #define COMPRESSION_GEOBBINT16 3
32 #define COMPRESSION_GEOBBINT8 4
33 
34 #define TOLERANCE_DEFAULT 0.000000001
35 #define TOLERANCE_DEFAULT_SQUARED 0.000000000000000001
36 #define TOLERANCE_GEOINT32 0.0000001
37 
38 namespace Geospatial {
39 
40 DEVICE inline double decompress_longitude_coord_geoint32(const int32_t compressed) {
41  // decompress longitude: -2,147,483,647..2,147,483,647 ---> -180..180
42  return static_cast<double>(compressed) *
43  8.3819031754424345e-08; // (180.0 / 2147483647.0)
44 }
45 
46 DEVICE inline double decompress_latitude_coord_geoint32(const int32_t compressed) {
47  // decompress latitude: -2,147,483,647..2,147,483,647 ---> -90..90
48  return static_cast<double>(compressed) *
49  4.1909515877212172e-08; // // (90.0 / 2147483647.0)
50 }
51 
52 DEVICE inline bool is_null_point_longitude_geoint32(const int32_t compressed) {
53  // check compressed null point longitude: -2,147,483,648 ---> NULL
54  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
55 }
56 
57 DEVICE inline bool is_null_point_latitude_geoint32(const int32_t compressed) {
58  // check compressed null point latitude: -2,147,483,648 ---> NULL
59  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
60 }
61 
62 DEVICE inline uint64_t compress_longitude_coord_geoint32(const double coord) {
63  // compress longitude: -180..180 ---> -2,147,483,647..2,147,483,647
64  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 180.0));
65  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
66 }
67 
68 DEVICE inline uint64_t compress_latitude_coord_geoint32(const double coord) {
69  // compress latitude: -90..90 ---> -2,147,483,647..2,147,483,647
70  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 90.0));
71  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
72 }
73 
75  // compress null point longitude: NULL ---> -2,147,483,648
76  return 0x0000000080000000ULL;
77 }
78 
80  // compress null point latitude: NULL ---> -2,147,483,648
81  return 0x0000000080000000ULL;
82 }
83 
84 }; // namespace Geospatial
DEVICE double decompress_latitude_coord_geoint32(const int32_t compressed)
DEVICE uint64_t compress_longitude_coord_geoint32(const double coord)
DEVICE ALWAYS_INLINE int32_t compressed_coord(const int8_t *data, const int32_t index)
DEVICE ALWAYS_INLINE Point2D coord(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
#define DEVICE
DEVICE bool is_null_point_longitude_geoint32(const int32_t compressed)
DEVICE uint64_t compress_latitude_coord_geoint32(const double coord)
DEVICE constexpr uint64_t compress_null_point_latitude_geoint32()
DEVICE double decompress_longitude_coord_geoint32(const int32_t compressed)
DEVICE constexpr uint64_t compress_null_point_longitude_geoint32()
DEVICE bool is_null_point_latitude_geoint32(const int32_t compressed)