Commit a7dc63d9 authored by Tomas Vondra's avatar Tomas Vondra

Refactor geometric functions and operators

The primary goal of this patch is to eliminate duplicate code and share
code between different geometric data types more often, to prepare the
ground for additional patches.  Until now the code reuse was limited,
probably because the simpler types (line and point) were implemented
after the more complex ones.

The changes are quite extensive and can be summarised as:

* Eliminate SQL-level function calls.
* Re-use more functions to implement others.
* Unify internal function names and signatures.
* Remove private functions from geo_decls.h.
* Replace should-not-happen checks with assertions.
* Add comments describe for various functions.
* Remove some unreachable code.
* Define delimiter symbols of line datatype like the other ones.
* Remove the GEODEBUG macro and printf() calls.
* Unify code style of a few oddly formatted lines.

While the goal was to cause minimal user-visible changes, it was not
possible to keep the original behavior in all cases - for example when
handling NaN values, or when reusing code makes the functions return
consistent results.

Author: Emre Hasegeli
Reviewed-by: Kyotaro Horiguchi, me

Discussion: https://www.postgresql.org/message-id/CAE2gYzxF7-5djV6-cEvqQu-fNsnt%3DEqbOURx7ZDg%2BVv6ZMTWbg%40mail.gmail.com
parent fa7d5b70
This diff is collapsed.
...@@ -793,7 +793,8 @@ spg_poly_quad_compress(PG_FUNCTION_ARGS) ...@@ -793,7 +793,8 @@ spg_poly_quad_compress(PG_FUNCTION_ARGS)
POLYGON *polygon = PG_GETARG_POLYGON_P(0); POLYGON *polygon = PG_GETARG_POLYGON_P(0);
BOX *box; BOX *box;
box = box_copy(&polygon->boundbox); box = (BOX *) palloc(sizeof(BOX));
*box = polygon->boundbox;
PG_RETURN_BOX_P(box); PG_RETURN_BOX_P(box);
} }
...@@ -178,10 +178,6 @@ typedef struct ...@@ -178,10 +178,6 @@ typedef struct
* in geo_ops.c * in geo_ops.c
*/ */
/* private routines */
extern double point_dt(Point *pt1, Point *pt2);
extern double point_sl(Point *pt1, Point *pt2);
extern double pg_hypot(double x, double y); extern double pg_hypot(double x, double y);
extern BOX *box_copy(BOX *box);
#endif /* GEO_DECLS_H */ #endif /* GEO_DECLS_H */
...@@ -176,8 +176,13 @@ pt_in_widget(PG_FUNCTION_ARGS) ...@@ -176,8 +176,13 @@ pt_in_widget(PG_FUNCTION_ARGS)
{ {
Point *point = PG_GETARG_POINT_P(0); Point *point = PG_GETARG_POINT_P(0);
WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1); WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
float8 distance;
PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius); distance = DatumGetFloat8(DirectFunctionCall2(point_distance,
PointPGetDatum(point),
PointPGetDatum(&widget->center)));
PG_RETURN_BOOL(distance < widget->radius);
} }
PG_FUNCTION_INFO_V1(reverse_name); PG_FUNCTION_INFO_V1(reverse_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment