75 #include "lwgeom_pg.h"
88 PG_RETURN_BOOL(resut);
100 PG_RETURN_BOOL(resut);
112 PG_RETURN_BOOL(resut);
124 PG_RETURN_BOOL(resut);
137 double x = *(
double *)a;
138 double y = *(
double *)b;
142 return (
x >
y) ? 1 : -1;
194 double infinity = DBL_MAX;
229 memcpy(next_cube_box, cube_box,
sizeof(
CubeBox3D));
261 return next_cube_box;
374 spgConfigOut *
cfg = (spgConfigOut *)PG_GETARG_POINTER(1);
376 Oid boxoid = InvalidOid;
378 postgis_initialize_cache();
379 boxoid = postgis_oid(BOX3DOID);
381 cfg->prefixType = boxoid;
382 cfg->labelType = VOIDOID;
383 cfg->leafType = boxoid;
384 cfg->canReturnData =
false;
385 cfg->longValuesOK =
false;
398 spgChooseIn *in = (spgChooseIn *)PG_GETARG_POINTER(0);
399 spgChooseOut *out = (spgChooseOut *)PG_GETARG_POINTER(1);
401 BOX3D *box = DatumGetBox3DP(in->leafDatum);
403 out->resultType = spgMatchNode;
404 out->result.matchNode.restDatum = Box3DPGetDatum(box);
423 spgPickSplitIn *in = (spgPickSplitIn *)PG_GETARG_POINTER(0);
424 spgPickSplitOut *out = (spgPickSplitOut *)PG_GETARG_POINTER(1);
427 double *lowXs = palloc(
sizeof(
double) * in->nTuples);
428 double *highXs = palloc(
sizeof(
double) * in->nTuples);
429 double *lowYs = palloc(
sizeof(
double) * in->nTuples);
430 double *highYs = palloc(
sizeof(
double) * in->nTuples);
431 double *lowZs = palloc(
sizeof(
double) * in->nTuples);
432 double *highZs = palloc(
sizeof(
double) * in->nTuples);
436 for (i = 0; i < in->nTuples; i++)
438 BOX3D* box_in = DatumGetBox3DP(in->datums[i]);
439 lowXs[i] = box_in->
xmin;
440 highXs[i] = box_in->
xmax;
441 lowYs[i] = box_in->
ymin;
442 highYs[i] = box_in->
ymax;
443 lowZs[i] = box_in->
zmin;
444 highZs[i] = box_in->
zmax;
457 median = in->nTuples / 2;
470 out->hasPrefix =
true;
471 out->prefixDatum = Box3DPGetDatum(
centroid);
474 out->nodeLabels = NULL;
476 out->mapTuplesToNodes = palloc(
sizeof(
int) * in->nTuples);
477 out->leafTupleDatums = palloc(
sizeof(Datum) * in->nTuples);
483 for (i = 0; i < in->nTuples; i++)
485 BOX3D* box_in = DatumGetBox3DP(in->datums[i]);
488 out->leafTupleDatums[i] = Box3DPGetDatum(box_in);
489 out->mapTuplesToNodes[i] = octant;
509 spgInnerConsistentIn *in = (spgInnerConsistentIn *)PG_GETARG_POINTER(0);
510 spgInnerConsistentOut *out = (spgInnerConsistentOut *)PG_GETARG_POINTER(1);
512 MemoryContext old_ctx;
517 void **traversalValues;
522 out->nNodes = in->nNodes;
523 out->nodeNumbers = (
int *)palloc(
sizeof(
int) * in->nNodes);
524 for (i = 0; i < in->nNodes; i++)
525 out->nodeNumbers[i] = i;
534 if (in->traversalValue)
535 cube_box = in->traversalValue;
539 centroid = DatumGetBox3DP(in->prefixDatum);
543 nodeNumbers = (
int *)palloc(
sizeof(
int) * in->nNodes);
544 traversalValues = (
void **)palloc(
sizeof(
void *) * in->nNodes);
551 old_ctx = MemoryContextSwitchTo(in->traversalMemoryContext);
553 for (octant = 0; octant < in->nNodes; octant++)
558 for (i = 0; i < in->nkeys; i++)
560 StrategyNumber strategy = in->scankeys[i].sk_strategy;
561 Datum query = in->scankeys[i].sk_argument;
581 flag = !
right6D(next_cube_box, box);
589 flag = !
left6D(next_cube_box, box);
597 flag = !
below6D(next_cube_box, box);
605 flag = !
above6D(next_cube_box, box);
613 flag = !
front6D(next_cube_box, box);
621 flag = !
back6D(next_cube_box, box);
625 elog(ERROR,
"unrecognized strategy: %d", strategy);
635 traversalValues[out->nNodes] = next_cube_box;
636 nodeNumbers[out->nNodes] = octant;
645 pfree(next_cube_box);
650 out->nodeNumbers = (
int *)palloc(
sizeof(
int) * out->nNodes);
651 out->traversalValues = (
void **)palloc(
sizeof(
void *) * out->nNodes);
652 for (i = 0; i < out->nNodes; i++)
654 out->nodeNumbers[i] = nodeNumbers[i];
655 out->traversalValues[i] = traversalValues[i];
658 pfree(traversalValues);
661 MemoryContextSwitchTo(old_ctx);
673 spgLeafConsistentIn *in = (spgLeafConsistentIn *)PG_GETARG_POINTER(0);
674 spgLeafConsistentOut *out = (spgLeafConsistentOut *)PG_GETARG_POINTER(1);
675 BOX3D *leaf = DatumGetBox3DP(in->leafDatum);
680 out->recheck =
false;
683 out->leafValue = in->leafDatum;
686 for (i = 0; i < in->nkeys; i++)
688 StrategyNumber strategy = in->scankeys[i].sk_strategy;
689 Datum query = in->scankeys[i].sk_argument;
759 elog(ERROR,
"unrecognized strategy: %d", strategy);
767 PG_RETURN_BOOL(flag);
783 PG_RETURN_POINTER(
result);
char result[OUT_DOUBLE_BUFFER_SIZE]
static bool front6D(CubeBox3D *cube_box, BOX3D *query)
static bool back6D(CubeBox3D *cube_box, BOX3D *query)
static bool right6D(CubeBox3D *cube_box, BOX3D *query)
Datum gserialized_overlaps_3d(PG_FUNCTION_ARGS)
static bool overBack6D(CubeBox3D *cube_box, BOX3D *query)
static bool overAbove6D(CubeBox3D *cube_box, BOX3D *query)
PG_FUNCTION_INFO_V1(gserialized_overlaps_3d)
static bool overlap6D(CubeBox3D *cube_box, BOX3D *query)
Datum gserialized_contains_3d(PG_FUNCTION_ARGS)
static uint8 getOctant(const BOX3D *centroid, const BOX3D *inBox)
static int compareDoubles(const void *a, const void *b)
static CubeBox3D * nextCubeBox3D(CubeBox3D *cube_box, BOX3D *centroid, uint8 octant)
PGDLLEXPORT Datum gserialized_spgist_picksplit_3d(PG_FUNCTION_ARGS)
static bool overRight6D(CubeBox3D *cube_box, BOX3D *query)
static bool overFront6D(CubeBox3D *cube_box, BOX3D *query)
PGDLLEXPORT Datum gserialized_spgist_config_3d(PG_FUNCTION_ARGS)
static CubeBox3D * initCubeBox(void)
PGDLLEXPORT Datum gserialized_spgist_inner_consistent_3d(PG_FUNCTION_ARGS)
Datum gserialized_same_3d(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum gserialized_spgist_compress_3d(PG_FUNCTION_ARGS)
static bool contain6D(CubeBox3D *cube_box, BOX3D *query)
static bool overBelow6D(CubeBox3D *cube_box, BOX3D *query)
static bool above6D(CubeBox3D *cube_box, BOX3D *query)
PGDLLEXPORT Datum gserialized_spgist_choose_3d(PG_FUNCTION_ARGS)
Datum gserialized_contained_3d(PG_FUNCTION_ARGS)
static bool below6D(CubeBox3D *cube_box, BOX3D *query)
static bool overLeft6D(CubeBox3D *cube_box, BOX3D *query)
PGDLLEXPORT Datum gserialized_spgist_leaf_consistent_3d(PG_FUNCTION_ARGS)
static bool left6D(CubeBox3D *cube_box, BOX3D *query)
#define SPGOverlapStrategyNumber
#define SPGOverLeftStrategyNumber
#define SPGLeftStrategyNumber
#define SPGAboveStrategyNumber
#define SPGSameStrategyNumber
#define SPGOverBackStrategyNumber
#define SPGContainedByStrategyNumber
#define SPGOverRightStrategyNumber
#define SPGFrontStrategyNumber
#define SPGBelowStrategyNumber
#define SPGRightStrategyNumber
#define SPGOverFrontStrategyNumber
#define SPGContainsStrategyNumber
#define SPGOverBelowStrategyNumber
#define SPGBackStrategyNumber
#define SPGOverAboveStrategyNumber
#define SRID_UNKNOWN
Unknown SRID value.
bool BOX3D_above_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_back_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overlaps_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_contains_internal(BOX3D *box1, BOX3D *box2)
needed for sp-gist support PostgreSQL 11+
bool BOX3D_overabove_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_right_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overback_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overleft_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_below_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_left_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overright_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_same_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_contained_internal(BOX3D *box1, BOX3D *box2)
Datum LWGEOM_to_BOX3D(PG_FUNCTION_ARGS)
bool BOX3D_front_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overfront_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overbelow_internal(BOX3D *box1, BOX3D *box2)
Datum centroid(PG_FUNCTION_ARGS)