OmniSciDB  04ee39c94c
ExtensionFunctions.hpp File Reference
#include "../Shared/funcannotations.h"
#include <cstdint>
#include <cmath>
#include <cstdlib>
#include "ExtensionFunctionsGeo.hpp"
+ Include dependency graph for ExtensionFunctions.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define EXTENSION_INLINE   extern "C" ALWAYS_INLINE DEVICE
 
#define EXTENSION_NOINLINE   extern "C" NEVER_INLINE DEVICE
 

Functions

EXTENSION_NOINLINE double Acos (const double x)
 
EXTENSION_NOINLINE double Asin (const double x)
 
EXTENSION_NOINLINE double Atan (const double x)
 
EXTENSION_NOINLINE double Atan2 (const double y, const double x)
 
EXTENSION_NOINLINE double Ceil (double x)
 
EXTENSION_NOINLINE float Ceil__ (float x)
 
EXTENSION_NOINLINE int16_t Ceil__1 (int16_t x)
 
EXTENSION_NOINLINE int32_t Ceil__2 (int32_t x)
 
EXTENSION_NOINLINE int64_t Ceil__3 (int64_t x)
 
EXTENSION_NOINLINE double Cos (const double x)
 
EXTENSION_NOINLINE double Cot (const double x)
 
EXTENSION_NOINLINE double degrees (double x)
 
EXTENSION_NOINLINE double Exp (double x)
 
EXTENSION_NOINLINE double Floor (double x)
 
EXTENSION_NOINLINE float Floor__ (float x)
 
EXTENSION_NOINLINE int16_t Floor__1 (int16_t x)
 
EXTENSION_NOINLINE int32_t Floor__2 (int32_t x)
 
EXTENSION_NOINLINE int64_t Floor__3 (int64_t x)
 
EXTENSION_NOINLINE double ln (const double x)
 
EXTENSION_NOINLINE double ln__ (const float x)
 
EXTENSION_NOINLINE double Log (const double x)
 
EXTENSION_NOINLINE double Log__ (const float x)
 
EXTENSION_NOINLINE double Log10 (const double x)
 
EXTENSION_NOINLINE double Log10__ (const float x)
 
EXTENSION_NOINLINE double pi ()
 
EXTENSION_NOINLINE double power (const double x, const double y)
 
EXTENSION_NOINLINE double radians (const double x)
 
EXTENSION_NOINLINE double Round (const double x, const int32_t y)
 
EXTENSION_NOINLINE float Round__ (const float x, const int32_t y)
 
EXTENSION_NOINLINE int16_t Round__1 (const int16_t x, const int32_t y)
 
EXTENSION_NOINLINE int32_t Round__2 (const int32_t x, const int32_t y)
 
EXTENSION_NOINLINE int64_t Round__3 (const int64_t x, const int32_t y)
 
EXTENSION_NOINLINE int64_t Round__4 (const int64_t x, const int32_t y0, const int32_t scale)
 
EXTENSION_NOINLINE double Round2_to_digit (const double x, const int32_t y)
 
EXTENSION_NOINLINE double round_to_digit (const double x, const int32_t y)
 
EXTENSION_NOINLINE double Sin (const double x)
 
EXTENSION_NOINLINE double Tan (const double x)
 
EXTENSION_NOINLINE double Tan__ (const float x)
 
EXTENSION_NOINLINE double Truncate (const double x, const int32_t y)
 
EXTENSION_NOINLINE float Truncate__ (const float x, const int32_t y)
 
EXTENSION_NOINLINE int16_t Truncate__1 (const int16_t x, const int32_t y)
 
EXTENSION_NOINLINE int32_t Truncate__2 (const int32_t x, const int32_t y)
 
EXTENSION_NOINLINE int64_t Truncate__3 (const int64_t x, const int32_t y)
 
EXTENSION_NOINLINE bool isNan (const double x)
 
EXTENSION_NOINLINE bool isNan__ (const float x)
 
EXTENSION_NOINLINE double conv_4326_900913_x (const double x)
 
EXTENSION_NOINLINE double conv_4326_900913_y (const double y)
 
EXTENSION_NOINLINE double distance_in_meters (const double fromlon, const double fromlat, const double tolon, const double tolat)
 Computes the distance, in meters, between two WGS-84 positions. More...
 
EXTENSION_NOINLINE double distance_in_meters__ (const float fromlon, const float fromlat, const float tolon, const float tolat)
 
EXTENSION_NOINLINE double approx_distance_in_meters (const float fromlon, const float fromlat, const float tolon, const float tolat)
 
EXTENSION_NOINLINE float rect_pixel_bin (const double val, const double min, const double max, const int32_t numbins, const int32_t dimensionsize)
 
EXTENSION_NOINLINE float rect_pixel_bin_x (const double valx, const double minx, const double maxx, const double rectwidth, const double offsetx, const int32_t imgwidth)
 
EXTENSION_NOINLINE float rect_pixel_bin_y (const double valy, const double miny, const double maxy, const double rectheight, const double offsety, const int32_t imgheight)
 
EXTENSION_NOINLINE float reg_hex_horiz_pixel_bin_x (const double valx, const double minx, const double maxx, const double valy, const double miny, const double maxy, const double hexwidth, const double hexheight, const double offsetx, const double offsety, const int32_t imgwidth, const int32_t imgheight)
 
EXTENSION_NOINLINE float reg_hex_horiz_pixel_bin_y (const double valx, const double minx, const double maxx, const double valy, const double miny, const double maxy, const double hexwidth, const double hexheight, const double offsetx, const double offsety, const int32_t imgwidth, const int32_t imgheight)
 
EXTENSION_NOINLINE float reg_hex_vert_pixel_bin_x (const double valx, const double minx, const double maxx, const double valy, const double miny, const double maxy, const double hexwidth, const double hexheight, const double offsetx, const double offsety, const int32_t imgwidth, const int32_t imgheight)
 
EXTENSION_NOINLINE float reg_hex_vert_pixel_bin_y (const double valx, const double minx, const double maxx, const double valy, const double miny, const double maxy, const double hexwidth, const double hexheight, const double offsetx, const double offsety, const int32_t imgwidth, const int32_t imgheight)
 
EXTENSION_NOINLINE double convert_meters_to_merc_pixel_width (const double meters, const double lon, const double lat, const double min_lon, const double max_lon, const int32_t img_width, const double min_width)
 
EXTENSION_NOINLINE double convert_meters_to_merc_pixel_height (const double meters, const double lon, const double lat, const double min_lat, const double max_lat, const int32_t img_height, const double min_height)
 
EXTENSION_INLINE bool is_point_in_merc_view (const double lon, const double lat, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
 
EXTENSION_NOINLINE bool is_point_size_in_merc_view (const double lon, const double lat, const double meters, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
 

Macro Definition Documentation

◆ EXTENSION_INLINE

◆ EXTENSION_NOINLINE

#define EXTENSION_NOINLINE   extern "C" NEVER_INLINE DEVICE

Definition at line 9 of file ExtensionFunctions.hpp.

Referenced by Acos(), approx_distance_in_meters(), area_polygon(), Asin(), Atan(), Atan2(), box_overlaps_box(), Ceil(), Ceil__(), Ceil__1(), Ceil__2(), Ceil__3(), conv_4326_900913_x(), conv_4326_900913_y(), convert_meters_to_merc_pixel_width(), convert_meters_to_pixel_width(), Cos(), Cot(), degrees(), distance_in_meters(), distance_in_meters__(), distance_point_linestring(), Exp(), Floor(), Floor__(), Floor__1(), Floor__2(), Floor__3(), isNan(), isNan__(), length_linestring(), ln(), ln__(), Log(), Log10(), Log10__(), Log__(), MapD_GeoPolyRenderGroup(), max_distance_point_linestring(), perimeter_multipolygon(), pi(), power(), radians(), rect_pixel_bin(), rect_pixel_bin_x(), rect_pixel_bin_y(), reg_hex_horiz_pixel_bin_x(), reg_hex_horiz_pixel_bin_y(), reg_hex_vert_pixel_bin_x(), reg_hex_vert_pixel_bin_y(), Round(), Round2_to_digit(), Round__(), Round__1(), Round__2(), Round__3(), Round__4(), round_to_digit(), Sin(), ST_Area_Polygon_Geodesic(), ST_Contains_LineString_LineString(), ST_Contains_LineString_Point(), ST_Contains_LineString_Polygon(), ST_Contains_MultiPolygon_Point(), ST_Contains_Point_LineString(), ST_Contains_Point_Point(), ST_Contains_Polygon_LineString(), ST_Contains_Polygon_Point(), ST_Contains_Polygon_Polygon(), ST_Distance_LineString_LineString(), ST_Distance_LineString_Point(), ST_Distance_LineString_Point_Geodesic(), ST_Distance_LineString_Polygon(), ST_Distance_MultiPolygon_Polygon(), ST_Distance_Point_ClosedLineString(), ST_Distance_Point_LineString(), ST_Distance_Point_Point(), ST_Distance_Point_Point_Geodesic(), ST_Distance_Point_Point_Squared(), ST_Distance_Point_Polygon(), ST_Distance_Polygon_LineString(), ST_Distance_Polygon_Polygon(), ST_Intersects_LineString_Linestring(), ST_Intersects_LineString_Point(), ST_Intersects_LineString_Polygon(), ST_Intersects_Point_Point(), ST_Intersects_Polygon_LineString(), ST_Intersects_Polygon_Polygon(), ST_Length_LineString(), ST_Length_LineString_Geodesic(), ST_MaxDistance_LineString_Point(), ST_MaxDistance_Point_LineString(), ST_NRings(), ST_Perimeter_MultiPolygon(), ST_Perimeter_Polygon(), ST_X_LineString(), ST_X_Point(), ST_XMax(), ST_XMin(), ST_Y_LineString(), ST_Y_Point(), ST_YMin(), Tan(), Tan__(), Truncate(), Truncate__(), Truncate__1(), Truncate__2(), and Truncate__3().

Function Documentation

◆ Acos()

EXTENSION_NOINLINE double Acos ( const double  x)

Definition at line 37 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

37  {
38  return acos(x);
39 }

◆ approx_distance_in_meters()

EXTENSION_NOINLINE double approx_distance_in_meters ( const float  fromlon,
const float  fromlat,
const float  tolon,
const float  tolat 
)

Definition at line 425 of file ExtensionFunctions.hpp.

References distance_in_meters__(), and EXTENSION_NOINLINE.

428  {
429 #ifdef __CUDACC__
430  float latitudeArc = (fromlat - tolat) * 0.017453292519943295769236907684886;
431  float longitudeArc = (fromlon - tolon) * 0.017453292519943295769236907684886;
432  float latitudeH = __sinf(latitudeArc * 0.5);
433  latitudeH *= latitudeH;
434  float lontitudeH = __sinf(longitudeArc * 0.5);
435  lontitudeH *= lontitudeH;
436  float tmp = __cosf(fromlat * 0.017453292519943295769236907684886) *
437  __cosf(tolat * 0.017453292519943295769236907684886);
438  return 6372797.560856 * (2.0 * asinf(__fsqrt_rd(latitudeH + tmp * lontitudeH)));
439 #else
440  return distance_in_meters__(fromlon, fromlat, tolon, tolat);
441 #endif
442 }
EXTENSION_NOINLINE double distance_in_meters__(const float fromlon, const float fromlat, const float tolon, const float tolat)
+ Here is the call graph for this function:

◆ Asin()

EXTENSION_NOINLINE double Asin ( const double  x)

Definition at line 42 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

42  {
43  return asin(x);
44 }

◆ Atan()

EXTENSION_NOINLINE double Atan ( const double  x)

Definition at line 47 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

47  {
48  return atan(x);
49 }

◆ Atan2()

EXTENSION_NOINLINE double Atan2 ( const double  y,
const double  x 
)

Definition at line 52 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

52  {
53  return atan2(y, x);
54 }

◆ Ceil()

EXTENSION_NOINLINE double Ceil ( double  x)

Definition at line 57 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

57  {
58  return ceil(x);
59 }

◆ Ceil__()

EXTENSION_NOINLINE float Ceil__ ( float  x)

Definition at line 62 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

62  {
63  return ceil(x);
64 }

◆ Ceil__1()

EXTENSION_NOINLINE int16_t Ceil__1 ( int16_t  x)

Definition at line 67 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

67  {
68  return x;
69 }

◆ Ceil__2()

EXTENSION_NOINLINE int32_t Ceil__2 ( int32_t  x)

Definition at line 72 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

72  {
73  return x;
74 }

◆ Ceil__3()

EXTENSION_NOINLINE int64_t Ceil__3 ( int64_t  x)

Definition at line 77 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

77  {
78  return x;
79 }

◆ conv_4326_900913_x()

EXTENSION_NOINLINE double conv_4326_900913_x ( const double  x)

Definition at line 362 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

Referenced by convert_meters_to_merc_pixel_width(), and transform_coord().

362  {
363  return x * 111319.490778;
364 }
+ Here is the caller graph for this function:

◆ conv_4326_900913_y()

EXTENSION_NOINLINE double conv_4326_900913_y ( const double  y)

Definition at line 367 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

Referenced by convert_meters_to_merc_pixel_height(), and transform_coord().

367  {
368  return 6378136.99911 * log(tan(.00872664626 * y + .785398163397));
369 }
+ Here is the caller graph for this function:

◆ convert_meters_to_merc_pixel_height()

EXTENSION_NOINLINE double convert_meters_to_merc_pixel_height ( const double  meters,
const double  lon,
const double  lat,
const double  min_lat,
const double  max_lat,
const int32_t  img_height,
const double  min_height 
)

Definition at line 833 of file ExtensionFunctions.hpp.

References conv_4326_900913_y(), and sz.

839  {
840  const double const1 = 0.017453292519943295769236907684886;
841  const double const2 = 6372797.560856;
842  const double latdiff = meters / (const1 * const2);
843  const double newlat =
844  (lat < 0) ? lat + latdiff : lat - latdiff; // assumes a lat range of [-90, 90]
845  double t1 = conv_4326_900913_y(lat);
846  double t2 = conv_4326_900913_y(newlat);
847  const double min_merc_y = conv_4326_900913_y(min_lat);
848  const double max_merc_y = conv_4326_900913_y(max_lat);
849  const double merc_diff = max_merc_y - min_merc_y;
850  t1 = ((t1 - min_merc_y) / merc_diff) * static_cast<double>(img_height);
851  t2 = ((t2 - min_merc_y) / merc_diff) * static_cast<double>(img_height);
852 
853  // TODO(croot): need to account for edge cases, such as getting close to the poles.
854  const double sz = fabs(t1 - t2);
855  return (sz < min_height ? min_height : sz);
856 }
int64_t const int32_t sz
EXTENSION_NOINLINE double conv_4326_900913_y(const double y)
+ Here is the call graph for this function:

◆ convert_meters_to_merc_pixel_width()

EXTENSION_NOINLINE double convert_meters_to_merc_pixel_width ( const double  meters,
const double  lon,
const double  lat,
const double  min_lon,
const double  max_lon,
const int32_t  img_width,
const double  min_width 
)

Definition at line 807 of file ExtensionFunctions.hpp.

References conv_4326_900913_x(), EXTENSION_NOINLINE, and sz.

813  {
814  const double const1 = 0.017453292519943295769236907684886;
815  const double const2 = 6372797.560856;
816  double t1 = sinf(meters / (2.0 * const2));
817  double t2 = cosf(const1 * lat);
818  const double newlon = lon - (2.0 * asinf(t1 / t2)) / const1;
819  t1 = conv_4326_900913_x(lon);
820  t2 = conv_4326_900913_x(newlon);
821  const double min_merc_x = conv_4326_900913_x(min_lon);
822  const double max_merc_x = conv_4326_900913_x(max_lon);
823  const double merc_diff = max_merc_x - min_merc_x;
824  t1 = ((t1 - min_merc_x) / merc_diff) * static_cast<double>(img_width);
825  t2 = ((t2 - min_merc_x) / merc_diff) * static_cast<double>(img_width);
826 
827  // TODO(croot): need to account for edge cases, such as getting close to the poles.
828  const double sz = fabs(t1 - t2);
829  return (sz < min_width ? min_width : sz);
830 }
int64_t const int32_t sz
EXTENSION_NOINLINE double conv_4326_900913_x(const double x)
+ Here is the call graph for this function:

◆ Cos()

EXTENSION_NOINLINE double Cos ( const double  x)

Definition at line 82 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

82  {
83  return cos(x);
84 }

◆ Cot()

EXTENSION_NOINLINE double Cot ( const double  x)

Definition at line 87 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

87  {
88  return 1 / tan(x);
89 }

◆ degrees()

EXTENSION_NOINLINE double degrees ( double  x)

Definition at line 92 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

92  {
93  return x * (180.0 / M_PI);
94 }

◆ distance_in_meters()

EXTENSION_NOINLINE double distance_in_meters ( const double  fromlon,
const double  fromlat,
const double  tolon,
const double  tolat 
)

Computes the distance, in meters, between two WGS-84 positions.

The result is equal to EARTH_RADIUS_IN_METERS*ArcInRadians(from,to)

ArcInRadians is equal to Distance(from,to)/EARTH_RADIUS_IN_METERS = 2*asin(sqrt(h(d/EARTH_RADIUS_IN_METERS )))

where:

  • d is the distance in meters between 'from' and 'to' positions.
  • h is the haversine function: h(x)=sinĀ²(x/2)

code attribution: http://blog.julien.cayzac.name/2008/10/arc-and-distance-between-two-points-on.html

The haversine formula gives: h(d/R) = h(from.lat-to.lat)+h(from.lon-to.lon)+cos(from.lat)*cos(to.lat)

See also
http://en.wikipedia.org/wiki/Law_of_haversines

Definition at line 393 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

Referenced by length_linestring(), ST_Distance_LineString_LineString_Geodesic(), ST_Distance_Point_LineString_Geodesic(), and ST_Distance_Point_Point_Geodesic().

396  {
397  double latitudeArc = (fromlat - tolat) * 0.017453292519943295769236907684886;
398  double longitudeArc = (fromlon - tolon) * 0.017453292519943295769236907684886;
399  double latitudeH = sin(latitudeArc * 0.5);
400  latitudeH *= latitudeH;
401  double lontitudeH = sin(longitudeArc * 0.5);
402  lontitudeH *= lontitudeH;
403  double tmp = cos(fromlat * 0.017453292519943295769236907684886) *
404  cos(tolat * 0.017453292519943295769236907684886);
405  return 6372797.560856 * (2.0 * asin(sqrt(latitudeH + tmp * lontitudeH)));
406 }
+ Here is the caller graph for this function:

◆ distance_in_meters__()

EXTENSION_NOINLINE double distance_in_meters__ ( const float  fromlon,
const float  fromlat,
const float  tolon,
const float  tolat 
)

Definition at line 409 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

Referenced by approx_distance_in_meters().

412  {
413  float latitudeArc = (fromlat - tolat) * 0.017453292519943295769236907684886;
414  float longitudeArc = (fromlon - tolon) * 0.017453292519943295769236907684886;
415  float latitudeH = sinf(latitudeArc * 0.5);
416  latitudeH *= latitudeH;
417  float lontitudeH = sinf(longitudeArc * 0.5);
418  lontitudeH *= lontitudeH;
419  float tmp = cosf(fromlat * 0.017453292519943295769236907684886) *
420  cosf(tolat * 0.017453292519943295769236907684886);
421  return 6372797.560856 * (2.0 * asinf(sqrtf(latitudeH + tmp * lontitudeH)));
422 }
+ Here is the caller graph for this function:

◆ Exp()

EXTENSION_NOINLINE double Exp ( double  x)

Definition at line 97 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

97  {
98  return exp(x);
99 }

◆ Floor()

EXTENSION_NOINLINE double Floor ( double  x)

Definition at line 102 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

102  {
103  return floor(x);
104 }

◆ Floor__()

EXTENSION_NOINLINE float Floor__ ( float  x)

Definition at line 107 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

107  {
108  return floor(x);
109 }

◆ Floor__1()

EXTENSION_NOINLINE int16_t Floor__1 ( int16_t  x)

Definition at line 112 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

112  {
113  return x;
114 }

◆ Floor__2()

EXTENSION_NOINLINE int32_t Floor__2 ( int32_t  x)

Definition at line 117 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

117  {
118  return x;
119 }

◆ Floor__3()

EXTENSION_NOINLINE int64_t Floor__3 ( int64_t  x)

Definition at line 122 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

122  {
123  return x;
124 }

◆ is_point_in_merc_view()

EXTENSION_INLINE bool is_point_in_merc_view ( const double  lon,
const double  lat,
const double  min_lon,
const double  max_lon,
const double  min_lat,
const double  max_lat 
)

Definition at line 858 of file ExtensionFunctions.hpp.

863  {
864  return !(lon < min_lon || lon > max_lon || lat < min_lat || lat > max_lat);
865 }

◆ is_point_size_in_merc_view()

EXTENSION_NOINLINE bool is_point_size_in_merc_view ( const double  lon,
const double  lat,
const double  meters,
const double  min_lon,
const double  max_lon,
const double  min_lat,
const double  max_lat 
)

Definition at line 867 of file ExtensionFunctions.hpp.

873  {
874  const double const1 = 0.017453292519943295769236907684886;
875  const double const2 = 6372797.560856;
876  const double latdiff = meters / (const1 * const2);
877  const double t1 = sinf(meters / (2.0 * const2));
878  const double t2 = cosf(const1 * lat);
879  const double londiff = (2.0 * asinf(t1 / t2)) / const1;
880  return !(lon + londiff < min_lon || lon - londiff > max_lon ||
881  lat + latdiff < min_lat || lat - latdiff > max_lat);
882 }

◆ isNan()

EXTENSION_NOINLINE bool isNan ( const double  x)

Definition at line 352 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

352  {
353  return std::isnan(x);
354 }

◆ isNan__()

EXTENSION_NOINLINE bool isNan__ ( const float  x)

Definition at line 357 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

357  {
358  return std::isnan(x);
359 }

◆ ln()

EXTENSION_NOINLINE double ln ( const double  x)

Definition at line 127 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

127  {
128  return log(x);
129 }

◆ ln__()

EXTENSION_NOINLINE double ln__ ( const float  x)

Definition at line 132 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

132  {
133  return logf(x);
134 }

◆ Log()

EXTENSION_NOINLINE double Log ( const double  x)

Definition at line 137 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

137  {
138  return log(x);
139 }

◆ Log10()

EXTENSION_NOINLINE double Log10 ( const double  x)

Definition at line 147 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

147  {
148  return log10(x);
149 }

◆ Log10__()

EXTENSION_NOINLINE double Log10__ ( const float  x)

Definition at line 152 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

152  {
153  return log10f(x);
154 }

◆ Log__()

EXTENSION_NOINLINE double Log__ ( const float  x)

Definition at line 142 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

142  {
143  return logf(x);
144 }

◆ pi()

EXTENSION_NOINLINE double pi ( )

Definition at line 157 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

Referenced by geotransform_4326_to_900913().

157  {
158  return M_PI;
159 }
+ Here is the caller graph for this function:

◆ power()

EXTENSION_NOINLINE double power ( const double  x,
const double  y 
)

Definition at line 162 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

162  {
163  return pow(x, y);
164 }

◆ radians()

EXTENSION_NOINLINE double radians ( const double  x)

Definition at line 167 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

167  {
168  return x * (M_PI / 180.0);
169 }

◆ rect_pixel_bin()

EXTENSION_NOINLINE float rect_pixel_bin ( const double  val,
const double  min,
const double  max,
const int32_t  numbins,
const int32_t  dimensionsize 
)

deprecated

Definition at line 445 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

449  {
451  float numbinsf = float(numbins);
452  return float(int32_t(float((val - min) / (max - min)) * numbinsf)) *
453  float(dimensionsize) / numbinsf;
454 }

◆ rect_pixel_bin_x()

EXTENSION_NOINLINE float rect_pixel_bin_x ( const double  valx,
const double  minx,
const double  maxx,
const double  rectwidth,
const double  offsetx,
const int32_t  imgwidth 
)

Definition at line 457 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

462  {
463  const float imgwidthf = float(imgwidth);
464  const float rectwidthf = float(rectwidth);
465  double min = minx;
466  float offset = offsetx;
467  if (offset != 0) {
468  offset = fmodf(offset, rectwidthf);
469  if (offset > 0) {
470  offset -= rectwidthf;
471  }
472  min += offset * (maxx - minx) / imgwidthf;
473  }
474  return float(int32_t(float((valx - min) / (maxx - min)) * (imgwidthf - offset) /
475  rectwidthf)) *
476  rectwidthf +
477  offset + rectwidthf / 2.0f;
478 }

◆ rect_pixel_bin_y()

EXTENSION_NOINLINE float rect_pixel_bin_y ( const double  valy,
const double  miny,
const double  maxy,
const double  rectheight,
const double  offsety,
const int32_t  imgheight 
)

Definition at line 481 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

486  {
487  const float imgheightf = float(imgheight);
488  const float rectheightf = rectheight;
489  double min = miny;
490  float offset = offsety;
491  if (offset != 0) {
492  offset = fmodf(offset, rectheightf);
493  if (offset > 0) {
494  offset -= rectheightf;
495  }
496  min += offset * (maxy - miny) / imgheightf;
497  }
498  return float(int32_t(float((valy - min) / (maxy - min)) * (imgheightf - offset) /
499  rectheightf)) *
500  rectheightf +
501  offset + rectheightf / 2.0f;
502 }

◆ reg_hex_horiz_pixel_bin_x()

EXTENSION_NOINLINE float reg_hex_horiz_pixel_bin_x ( const double  valx,
const double  minx,
const double  maxx,
const double  valy,
const double  miny,
const double  maxy,
const double  hexwidth,
const double  hexheight,
const double  offsetx,
const double  offsety,
const int32_t  imgwidth,
const int32_t  imgheight 
)

Definition at line 505 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

516  {
517  const float sqrt3 = 1.7320508075688772;
518  const float imgwidthf = float(imgwidth);
519  const float imgheightf = float(imgheight);
520  const float hexwidthf = float(hexwidth);
521  const float hexheightf = float(hexheight);
522 
523  // expand the bounds of the data according
524  // to the input offsets. This is done because
525  // we also expand the image size according to the
526  // offsets because this algorithm layers the hexagon
527  // bins starting at the bottom left corner
528  double xmin = minx;
529  float xoffset = offsetx;
530  if (xoffset != 0) {
531  xoffset = fmodf(xoffset, hexwidthf);
532  if (xoffset > 0) {
533  xoffset -= hexwidthf;
534  }
535  xmin += xoffset * (maxx - xmin) / imgwidthf;
536  }
537 
538  double ymin = miny;
539  float yoffset = offsety;
540  if (yoffset != 0) {
541  yoffset = fmodf(yoffset, 1.5f * hexheightf);
542  if (yoffset > 0) {
543  yoffset -= 1.5f * hexheightf;
544  }
545  ymin += yoffset * (maxy - ymin) / imgheightf;
546  }
547 
548  // get the pixel position of the point
549  // assumes a linear scale here
550  // Rounds to the nearest pixel.
551  const float pix_x =
552  roundf((imgwidthf - xoffset) * float((valx - xmin) / (maxx - xmin)));
553  const float pix_y =
554  roundf((imgheightf - yoffset) * float((valy - ymin) / (maxy - ymin)));
555 
556  // Now convert the pixel position into a
557  // cube-coordinate system representation
558  const float hexsize = hexheightf / 2.0f;
559  const float cube_x = ((pix_x / sqrt3) - (pix_y / 3.0)) / hexsize;
560  const float cube_z = (pix_y * 2.0f / 3.0f) / hexsize;
561  const float cube_y = -cube_x - cube_z;
562 
563  // need to round the cube coordinates above
564  float rx = round(cube_x);
565  float ry = round(cube_y);
566  float rz = round(cube_z);
567  const float x_diff = fabs(rx - cube_x);
568  const float y_diff = fabs(ry - cube_y);
569  const float z_diff = fabs(rz - cube_z);
570  if (x_diff > y_diff && x_diff > z_diff) {
571  rx = -ry - rz;
572  } else if (y_diff > z_diff) {
573  ry = -rx - rz;
574  } else {
575  rz = -rx - ry;
576  }
577 
578  // now convert the cube/hex coord to a pixel location
579  return hexsize * sqrt3 * (rx + rz / 2.0f) + xoffset;
580 }

◆ reg_hex_horiz_pixel_bin_y()

EXTENSION_NOINLINE float reg_hex_horiz_pixel_bin_y ( const double  valx,
const double  minx,
const double  maxx,
const double  valy,
const double  miny,
const double  maxy,
const double  hexwidth,
const double  hexheight,
const double  offsetx,
const double  offsety,
const int32_t  imgwidth,
const int32_t  imgheight 
)

Definition at line 583 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

594  {
595  const float sqrt3 = 1.7320508075688772;
596  const float imgwidthf = float(imgwidth);
597  const float imgheightf = float(imgheight);
598  const float hexwidthf = float(hexwidth);
599  const float hexheightf = float(hexheight);
600 
601  // expand the bounds of the data according
602  // to the input offsets. This is done because
603  // we also expand the image size according to the
604  // offsets because this algorithm layers the hexagon
605  // bins starting at the bottom left corner
606  double xmin = minx;
607  float xoffset = offsetx;
608  if (xoffset != 0) {
609  xoffset = fmodf(xoffset, hexwidthf);
610  if (xoffset > 0) {
611  xoffset -= hexwidthf;
612  }
613  xmin += xoffset * (maxx - xmin) / imgwidthf;
614  }
615 
616  double ymin = miny;
617  float yoffset = offsety;
618  if (yoffset != 0) {
619  yoffset = fmodf(yoffset, 1.5f * hexheightf);
620  if (yoffset > 0) {
621  yoffset -= 1.5f * hexheightf;
622  }
623  ymin += yoffset * (maxy - ymin) / imgheightf;
624  }
625 
626  // get the pixel position of the point
627  // assumes a linear scale here
628  // Rounds to the nearest pixel.
629  const float pix_x =
630  roundf((imgwidthf - xoffset) * float((valx - xmin) / (maxx - xmin)));
631  const float pix_y =
632  roundf((imgheightf - yoffset) * float((valy - ymin) / (maxy - ymin)));
633 
634  // Now convert the pixel position into a
635  // cube-coordinate system representation
636  const float hexsize = hexheightf / 2.0f;
637  const float cube_x = ((pix_x / sqrt3) - (pix_y / 3.0f)) / hexsize;
638  const float cube_z = (pix_y * 2.0f / 3.0f) / hexsize;
639  const float cube_y = -cube_x - cube_z;
640 
641  // need to round the cube coordinates above
642  float rx = round(cube_x);
643  float ry = round(cube_y);
644  float rz = round(cube_z);
645  const float x_diff = fabs(rx - cube_x);
646  const float y_diff = fabs(ry - cube_y);
647  const float z_diff = fabs(rz - cube_z);
648  if ((x_diff <= y_diff || x_diff <= z_diff) && y_diff <= z_diff) {
649  rz = -rx - ry;
650  }
651 
652  // now convert the cube/hex coord to a pixel location
653  return hexsize * 3.0f / 2.0f * rz + yoffset;
654 }

◆ reg_hex_vert_pixel_bin_x()

EXTENSION_NOINLINE float reg_hex_vert_pixel_bin_x ( const double  valx,
const double  minx,
const double  maxx,
const double  valy,
const double  miny,
const double  maxy,
const double  hexwidth,
const double  hexheight,
const double  offsetx,
const double  offsety,
const int32_t  imgwidth,
const int32_t  imgheight 
)

Definition at line 657 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

668  {
669  const float sqrt3 = 1.7320508075688772;
670  const float imgwidthf = float(imgwidth);
671  const float imgheightf = float(imgheight);
672  const float hexwidthf = float(hexwidth);
673  const float hexheightf = float(hexheight);
674 
675  // expand the bounds of the data according
676  // to the input offsets. This is done because
677  // we also expand the image size according to the
678  // offsets because this algorithm layers the hexagon
679  // bins starting at the bottom left corner
680  double xmin = minx;
681  float xoffset = offsetx;
682  if (xoffset != 0) {
683  xoffset = fmodf(xoffset, 1.5f * hexwidthf);
684  if (xoffset > 0) {
685  xoffset -= 1.5f * hexwidthf;
686  }
687  xmin += xoffset * (maxx - xmin) / imgwidthf;
688  }
689 
690  double ymin = miny;
691  float yoffset = offsety;
692  if (yoffset != 0) {
693  yoffset = fmodf(yoffset, hexheightf);
694  if (yoffset > 0) {
695  yoffset -= hexheightf;
696  }
697  ymin += yoffset * (maxy - ymin) / imgheightf;
698  }
699 
700  // get the pixel position of the point
701  // assumes a linear scale here
702  // Rounds to the nearest pixel.
703  const float pix_x =
704  roundf((imgwidthf - xoffset) * float((valx - xmin) / (maxx - xmin)));
705  const float pix_y =
706  roundf((imgheightf - yoffset) * float((valy - ymin) / (maxy - ymin)));
707 
708  // Now convert the pixel position into a
709  // cube-coordinate system representation
710  const float hexsize = hexwidthf / 2.0f;
711  const float cube_x = (pix_x * 2.0f / 3.0f) / hexsize;
712  const float cube_z = ((pix_y / sqrt3) - (pix_x / 3.0f)) / hexsize;
713  const float cube_y = -cube_x - cube_z;
714 
715  // need to round the cube coordinates above
716  float rx = round(cube_x);
717  float ry = round(cube_y);
718  float rz = round(cube_z);
719  const float x_diff = fabs(rx - cube_x);
720  const float y_diff = fabs(ry - cube_y);
721  const float z_diff = fabs(rz - cube_z);
722  if (x_diff > y_diff && x_diff > z_diff) {
723  rx = -ry - rz;
724  }
725 
726  // now convert the cube/hex coord to a pixel location
727  return hexsize * 3.0f / 2.0f * rx + xoffset;
728 }

◆ reg_hex_vert_pixel_bin_y()

EXTENSION_NOINLINE float reg_hex_vert_pixel_bin_y ( const double  valx,
const double  minx,
const double  maxx,
const double  valy,
const double  miny,
const double  maxy,
const double  hexwidth,
const double  hexheight,
const double  offsetx,
const double  offsety,
const int32_t  imgwidth,
const int32_t  imgheight 
)

Definition at line 731 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

742  {
743  const float sqrt3 = 1.7320508075688772;
744  const float imgwidthf = float(imgwidth);
745  const float imgheightf = float(imgheight);
746  const float hexwidthf = float(hexwidth);
747  const float hexheightf = float(hexheight);
748 
749  // expand the bounds of the data according
750  // to the input offsets. This is done because
751  // we also expand the image size according to the
752  // offsets because this algorithm layers the hexagon
753  // bins starting at the bottom left corner
754  float xmin = minx;
755  float xoffset = offsetx;
756  if (xoffset != 0) {
757  xoffset = fmodf(xoffset, 1.5f * hexwidthf);
758  if (xoffset > 0) {
759  xoffset -= 1.5f * hexwidthf;
760  }
761  xmin += xoffset * (maxx - xmin) / imgwidthf;
762  }
763 
764  float ymin = miny;
765  float yoffset = offsety;
766  if (yoffset != 0) {
767  yoffset = fmodf(yoffset, hexheightf);
768  if (yoffset > 0) {
769  yoffset -= hexheightf;
770  }
771  ymin += yoffset * (maxy - ymin) / imgheightf;
772  }
773 
774  // get the pixel position of the point
775  // assumes a linear scale here
776  // Rounds to the nearest pixel.
777  const float pix_x = roundf((imgwidthf - xoffset) * (valx - xmin) / (maxx - xmin));
778  const float pix_y = roundf((imgheightf - yoffset) * (valy - ymin) / (maxy - ymin));
779 
780  // Now convert the pixel position into a
781  // cube-coordinate system representation
782  const float hexsize = hexwidthf / 2.0f;
783  const float cube_x = (pix_x * 2.0f / 3.0f) / hexsize;
784  const float cube_z = ((pix_y / sqrt3) - (pix_x / 3.0f)) / hexsize;
785  const float cube_y = -cube_x - cube_z;
786 
787  // need to round the cube coordinates above
788  float rx = round(cube_x);
789  float ry = round(cube_y);
790  float rz = round(cube_z);
791  const float x_diff = fabs(rx - cube_x);
792  const float y_diff = fabs(ry - cube_y);
793  const float z_diff = fabs(rz - cube_z);
794  if (x_diff > y_diff && x_diff > z_diff) {
795  rx = -ry - rz;
796  } else if (y_diff > z_diff) {
797  ry = -rx - rz;
798  } else {
799  rz = -rx - ry;
800  }
801 
802  // now convert the cube/hex coord to a pixel location
803  return hexsize * sqrt3 * (rz + rx / 2.0f) + yoffset;
804 }

◆ Round()

EXTENSION_NOINLINE double Round ( const double  x,
const int32_t  y 
)

Definition at line 172 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

172  {
173  if (y == 0) {
174  return round(x) + 0.0;
175  }
176 
177  double exp = pow(10, y);
178 #if defined(__powerpc__) && !defined(__CUDACC__)
179  int32_t yy = y - 1;
180  exp = 10 * powf((float)10L, yy);
181 #endif
182  return (round(x * exp) / exp) + 0.0;
183 }

◆ Round2_to_digit()

EXTENSION_NOINLINE double Round2_to_digit ( const double  x,
const int32_t  y 
)

Definition at line 274 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

274  {
275  double exp = pow(10, y);
276  return round(x * exp) / exp;
277 }

◆ Round__()

EXTENSION_NOINLINE float Round__ ( const float  x,
const int32_t  y 
)

Definition at line 186 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

186  {
187  if (y == 0) {
188  return roundf(x) + 0.0f;
189  }
190 
191  float exp = powf((float)10L, y);
192 #if defined(__powerpc__) && !defined(__CUDACC__)
193  int32_t yy = y - 1;
194  exp = 10 * powf((float)10L, yy);
195 #endif
196  return roundf(x * exp) / exp + 0.0f;
197 }

◆ Round__1()

EXTENSION_NOINLINE int16_t Round__1 ( const int16_t  x,
const int32_t  y 
)

Definition at line 200 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

200  {
201  if (y >= 0) {
202  return x;
203  }
204 
205  int32_t p = pow((float)10L, std::abs(y));
206  int32_t p_half = p >> 1;
207 
208  int64_t temp = x;
209 #if defined(__powerpc__) && !defined(__CUDACC__)
210  int16_t xx = x;
211  xx += 1;
212  temp = xx;
213  temp -= 1;
214 #endif
215  temp = temp >= 0 ? temp + p_half : temp - p_half;
216  temp = temp / p;
217  return temp * p;
218 }

◆ Round__2()

EXTENSION_NOINLINE int32_t Round__2 ( const int32_t  x,
const int32_t  y 
)

Definition at line 221 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

221  {
222  if (y >= 0) {
223  return x;
224  }
225 
226  int32_t p = pow((float)10L, std::abs(y));
227  int32_t p_half = p >> 1;
228 
229  int64_t temp = x;
230 #if defined(__powerpc__) && !defined(__CUDACC__)
231  int32_t xx = x;
232  xx += 1;
233  temp = xx;
234  temp -= 1;
235 #endif
236  temp = temp >= 0 ? temp + p_half : temp - p_half;
237  temp = temp / p;
238  return temp * p;
239 }

◆ Round__3()

EXTENSION_NOINLINE int64_t Round__3 ( const int64_t  x,
const int32_t  y 
)

Definition at line 242 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

242  {
243  if (y >= 0) {
244  return x;
245  }
246 
247  int64_t p = pow((double)10L, std::abs(y));
248  int64_t p_half = p >> 1;
249 
250  int64_t temp = x;
251  temp = temp >= 0 ? temp + p_half : temp - p_half;
252  temp = temp / p;
253  return temp * p;
254 }

◆ Round__4()

EXTENSION_NOINLINE int64_t Round__4 ( const int64_t  x,
const int32_t  y0,
const int32_t  scale 
)

Definition at line 257 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

257  {
258  int32_t y = y0 - scale;
259 
260  if (y >= 0) {
261  return x;
262  }
263 
264  int64_t p = pow((double)10L, std::abs(y));
265  int64_t p_half = p >> 1;
266 
267  int64_t temp = x;
268  temp = temp >= 0 ? temp + p_half : temp - p_half;
269  temp = temp / p;
270  return temp * p;
271 }

◆ round_to_digit()

EXTENSION_NOINLINE double round_to_digit ( const double  x,
const int32_t  y 
)

Definition at line 280 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

280  {
281  double exp = pow(10, y);
282  return round(x * exp) / exp;
283 }

◆ Sin()

EXTENSION_NOINLINE double Sin ( const double  x)

Definition at line 286 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

286  {
287  return sin(x);
288 }

◆ Tan()

EXTENSION_NOINLINE double Tan ( const double  x)

Definition at line 291 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

291  {
292  return tan(x);
293 }

◆ Tan__()

EXTENSION_NOINLINE double Tan__ ( const float  x)

Definition at line 296 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

296  {
297  return tanf(x);
298 }

◆ Truncate()

EXTENSION_NOINLINE double Truncate ( const double  x,
const int32_t  y 
)

Definition at line 301 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF().

301  {
302  double p = pow((double)10L, y);
303  int64_t temp = x * p;
304  return temp / p;
305 }
+ Here is the caller graph for this function:

◆ Truncate__()

EXTENSION_NOINLINE float Truncate__ ( const float  x,
const int32_t  y 
)

Definition at line 308 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

308  {
309  float p = powf((float)10L, y);
310  int64_t temp = x * p;
311  return temp / p;
312 }

◆ Truncate__1()

EXTENSION_NOINLINE int16_t Truncate__1 ( const int16_t  x,
const int32_t  y 
)

Definition at line 315 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

315  {
316  if (y >= 0) {
317  return x;
318  }
319  int32_t p = pow((float)10L, std::abs(y));
320  int64_t temp = x / p;
321 #if defined(__powerpc__) && !defined(__CUDACC__)
322  int16_t xx = x;
323  xx += 1;
324  temp = xx;
325  temp -= 1;
326  temp /= p;
327 #endif
328  return temp * p;
329 }

◆ Truncate__2()

EXTENSION_NOINLINE int32_t Truncate__2 ( const int32_t  x,
const int32_t  y 
)

Definition at line 332 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

332  {
333  if (y >= 0) {
334  return x;
335  }
336  int32_t p = pow((float)10L, std::abs(y));
337  int64_t temp = x / p;
338  return temp * p;
339 }

◆ Truncate__3()

EXTENSION_NOINLINE int64_t Truncate__3 ( const int64_t  x,
const int32_t  y 
)

Definition at line 342 of file ExtensionFunctions.hpp.

References EXTENSION_NOINLINE.

342  {
343  if (y >= 0) {
344  return x;
345  }
346  int64_t p = pow((double)10L, std::abs(y));
347  int64_t temp = x / p;
348  return temp * p;
349 }