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;
377 postgis_initialize_cache(fcinfo);
378 boxoid = postgis_oid(BOX3DOID);
380 cfg->prefixType = boxoid;
381 cfg->labelType = VOIDOID;
382 cfg->leafType = boxoid;
383 cfg->canReturnData =
false;
384 cfg->longValuesOK =
false;
397 spgChooseIn *in = (spgChooseIn *)PG_GETARG_POINTER(0);
398 spgChooseOut *out = (spgChooseOut *)PG_GETARG_POINTER(1);
400 BOX3D *box = DatumGetBox3DP(in->leafDatum);
402 out->resultType = spgMatchNode;
403 out->result.matchNode.restDatum = Box3DPGetDatum(box);
422 spgPickSplitIn *in = (spgPickSplitIn *)PG_GETARG_POINTER(0);
423 spgPickSplitOut *out = (spgPickSplitOut *)PG_GETARG_POINTER(1);
426 double *lowXs = palloc(
sizeof(
double) * in->nTuples);
427 double *highXs = palloc(
sizeof(
double) * in->nTuples);
428 double *lowYs = palloc(
sizeof(
double) * in->nTuples);
429 double *highYs = palloc(
sizeof(
double) * in->nTuples);
430 double *lowZs = palloc(
sizeof(
double) * in->nTuples);
431 double *highZs = palloc(
sizeof(
double) * in->nTuples);
432 BOX3D *box = DatumGetBox3DP(in->datums[0]);
433 int32_t srid = box->
srid;
436 for (i = 0; i < in->nTuples; i++)
438 BOX3D *box = DatumGetBox3DP(in->datums[i]);
440 lowXs[i] = box->
xmin;
441 highXs[i] = box->
xmax;
442 lowYs[i] = box->
ymin;
443 highYs[i] = box->
ymax;
444 lowZs[i] = box->
zmin;
445 highZs[i] = box->
zmax;
455 median = in->nTuples / 2;
468 out->hasPrefix =
true;
469 out->prefixDatum = Box3DPGetDatum(
centroid);
472 out->nodeLabels = NULL;
474 out->mapTuplesToNodes = palloc(
sizeof(
int) * in->nTuples);
475 out->leafTupleDatums = palloc(
sizeof(Datum) * in->nTuples);
481 for (i = 0; i < in->nTuples; i++)
483 BOX3D *box = DatumGetBox3DP(in->datums[i]);
486 out->leafTupleDatums[i] = Box3DPGetDatum(box);
487 out->mapTuplesToNodes[i] = octant;
507 spgInnerConsistentIn *in = (spgInnerConsistentIn *)PG_GETARG_POINTER(0);
508 spgInnerConsistentOut *out = (spgInnerConsistentOut *)PG_GETARG_POINTER(1);
510 MemoryContext old_ctx;
515 void **traversalValues;
520 out->nNodes = in->nNodes;
521 out->nodeNumbers = (
int *)palloc(
sizeof(
int) * in->nNodes);
522 for (i = 0; i < in->nNodes; i++)
523 out->nodeNumbers[i] = i;
532 if (in->traversalValue)
533 cube_box = in->traversalValue;
537 centroid = DatumGetBox3DP(in->prefixDatum);
541 nodeNumbers = (
int *)palloc(
sizeof(
int) * in->nNodes);
542 traversalValues = (
void **)palloc(
sizeof(
void *) * in->nNodes);
549 old_ctx = MemoryContextSwitchTo(in->traversalMemoryContext);
551 for (octant = 0; octant < in->nNodes; octant++)
556 for (i = 0; i < in->nkeys; i++)
558 StrategyNumber strategy = in->scankeys[i].sk_strategy;
559 Datum query = in->scankeys[i].sk_argument;
579 flag = !
right6D(next_cube_box, box);
587 flag = !
left6D(next_cube_box, box);
595 flag = !
below6D(next_cube_box, box);
603 flag = !
above6D(next_cube_box, box);
611 flag = !
front6D(next_cube_box, box);
619 flag = !
back6D(next_cube_box, box);
623 elog(ERROR,
"unrecognized strategy: %d", strategy);
633 traversalValues[out->nNodes] = next_cube_box;
634 nodeNumbers[out->nNodes] = octant;
643 pfree(next_cube_box);
648 out->nodeNumbers = (
int *)palloc(
sizeof(
int) * out->nNodes);
649 out->traversalValues = (
void **)palloc(
sizeof(
void *) * out->nNodes);
650 for (i = 0; i < out->nNodes; i++)
652 out->nodeNumbers[i] = nodeNumbers[i];
653 out->traversalValues[i] = traversalValues[i];
656 pfree(traversalValues);
659 MemoryContextSwitchTo(old_ctx);
671 spgLeafConsistentIn *in = (spgLeafConsistentIn *)PG_GETARG_POINTER(0);
672 spgLeafConsistentOut *out = (spgLeafConsistentOut *)PG_GETARG_POINTER(1);
673 BOX3D *leaf = DatumGetBox3DP(in->leafDatum);
678 out->recheck =
false;
681 out->leafValue = in->leafDatum;
684 for (i = 0; i < in->nkeys; i++)
686 StrategyNumber strategy = in->scankeys[i].sk_strategy;
687 Datum query = in->scankeys[i].sk_argument;
757 elog(ERROR,
"unrecognized strategy: %d", strategy);
765 PG_RETURN_BOOL(flag);
781 PG_RETURN_POINTER(result);
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 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)
static uint8 getOctant(BOX3D *centroid, BOX3D *inBox)
#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
Datum LWGEOM_to_BOX3D(PG_FUNCTION_ARGS)
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)
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)
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)