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
This commit is contained in:
Tomas Vondra 2018-07-29 02:02:48 +02:00
parent fa7d5b704a
commit a7dc63d904
4 changed files with 883 additions and 1039 deletions

File diff suppressed because it is too large Load Diff

View File

@ -793,7 +793,8 @@ spg_poly_quad_compress(PG_FUNCTION_ARGS)
POLYGON *polygon = PG_GETARG_POLYGON_P(0);
BOX *box;
box = box_copy(&polygon->boundbox);
box = (BOX *) palloc(sizeof(BOX));
*box = polygon->boundbox;
PG_RETURN_BOX_P(box);
}

View File

@ -178,10 +178,6 @@ typedef struct
* 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 BOX *box_copy(BOX *box);
#endif /* GEO_DECLS_H */

View File

@ -176,8 +176,13 @@ pt_in_widget(PG_FUNCTION_ARGS)
{
Point *point = PG_GETARG_POINT_P(0);
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);