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(fcinfo);
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);
433 BOX3D *box = DatumGetBox3DP(in->datums[0]);
434 int32_t srid = box->
srid;
437 for (i = 0; i < in->nTuples; i++)
439 BOX3D *box = DatumGetBox3DP(in->datums[i]);
441 lowXs[i] = box->
xmin;
442 highXs[i] = box->
xmax;
443 lowYs[i] = box->
ymin;
444 highYs[i] = box->
ymax;
445 lowZs[i] = box->
zmin;
446 highZs[i] = box->
zmax;
456 median = in->nTuples / 2;
469 out->hasPrefix =
true;
470 out->prefixDatum = Box3DPGetDatum(
centroid);
473 out->nodeLabels = NULL;
475 out->mapTuplesToNodes = palloc(
sizeof(
int) * in->nTuples);
476 out->leafTupleDatums = palloc(
sizeof(Datum) * in->nTuples);
482 for (i = 0; i < in->nTuples; i++)
484 BOX3D *box = DatumGetBox3DP(in->datums[i]);
487 out->leafTupleDatums[i] = Box3DPGetDatum(box);
488 out->mapTuplesToNodes[i] = octant;
508 spgInnerConsistentIn *in = (spgInnerConsistentIn *)PG_GETARG_POINTER(0);
509 spgInnerConsistentOut *out = (spgInnerConsistentOut *)PG_GETARG_POINTER(1);
511 MemoryContext old_ctx;
516 void **traversalValues;
521 out->nNodes = in->nNodes;
522 out->nodeNumbers = (
int *)palloc(
sizeof(
int) * in->nNodes);
523 for (i = 0; i < in->nNodes; i++)
524 out->nodeNumbers[i] = i;
533 if (in->traversalValue)
534 cube_box = in->traversalValue;
538 centroid = DatumGetBox3DP(in->prefixDatum);
542 nodeNumbers = (
int *)palloc(
sizeof(
int) * in->nNodes);
543 traversalValues = (
void **)palloc(
sizeof(
void *) * in->nNodes);
550 old_ctx = MemoryContextSwitchTo(in->traversalMemoryContext);
552 for (octant = 0; octant < in->nNodes; octant++)
557 for (i = 0; i < in->nkeys; i++)
559 StrategyNumber strategy = in->scankeys[i].sk_strategy;
560 Datum query = in->scankeys[i].sk_argument;
580 flag = !
right6D(next_cube_box, box);
588 flag = !
left6D(next_cube_box, box);
596 flag = !
below6D(next_cube_box, box);
604 flag = !
above6D(next_cube_box, box);
612 flag = !
front6D(next_cube_box, box);
620 flag = !
back6D(next_cube_box, box);
624 elog(ERROR,
"unrecognized strategy: %d", strategy);
634 traversalValues[out->nNodes] = next_cube_box;
635 nodeNumbers[out->nNodes] = octant;
644 pfree(next_cube_box);
649 out->nodeNumbers = (
int *)palloc(
sizeof(
int) * out->nNodes);
650 out->traversalValues = (
void **)palloc(
sizeof(
void *) * out->nNodes);
651 for (i = 0; i < out->nNodes; i++)
653 out->nodeNumbers[i] = nodeNumbers[i];
654 out->traversalValues[i] = traversalValues[i];
657 pfree(traversalValues);
660 MemoryContextSwitchTo(old_ctx);
672 spgLeafConsistentIn *in = (spgLeafConsistentIn *)PG_GETARG_POINTER(0);
673 spgLeafConsistentOut *out = (spgLeafConsistentOut *)PG_GETARG_POINTER(1);
674 BOX3D *leaf = DatumGetBox3DP(in->leafDatum);
679 out->recheck =
false;
682 out->leafValue = in->leafDatum;
685 for (i = 0; i < in->nkeys; i++)
687 StrategyNumber strategy = in->scankeys[i].sk_strategy;
688 Datum query = in->scankeys[i].sk_argument;
758 elog(ERROR,
"unrecognized strategy: %d", strategy);
766 PG_RETURN_BOOL(flag);
782 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)