337 spgPickSplitIn *in = (spgPickSplitIn *)PG_GETARG_POINTER(0);
338 spgPickSplitOut *out = (spgPickSplitOut *)PG_GETARG_POINTER(1);
341 double *lowXs = palloc(
sizeof(
double) * in->nTuples);
342 double *highXs = palloc(
sizeof(
double) * in->nTuples);
343 double *lowYs = palloc(
sizeof(
double) * in->nTuples);
344 double *highYs = palloc(
sizeof(
double) * in->nTuples);
347 for (i = 0; i < in->nTuples; i++)
349 BOX2DF *box = (BOX2DF *)DatumGetPointer(in->datums[i]);
351 lowXs[i] = (double)box->xmin;
352 highXs[i] = (
double)box->xmax;
353 lowYs[i] = (double)box->ymin;
354 highYs[i] = (
double)box->ymax;
362 median = in->nTuples / 2;
366 centroid->xmin = (float)lowXs[median];
367 centroid->xmax = (float)highXs[median];
368 centroid->ymin = (float)lowYs[median];
369 centroid->ymax = (float)highYs[median];
372 out->hasPrefix =
true;
373 out->prefixDatum = BoxPGetDatum(
centroid);
376 out->nodeLabels = NULL;
378 out->mapTuplesToNodes = palloc(
sizeof(
int) * in->nTuples);
379 out->leafTupleDatums = palloc(
sizeof(Datum) * in->nTuples);
384 for (i = 0; i < in->nTuples; i++)
386 BOX2DF *box = (BOX2DF *)DatumGetPointer(in->datums[i]);
389 out->leafTupleDatums[i] = PointerGetDatum(box);
390 out->mapTuplesToNodes[i] = quadrant;
static int compareDoubles(const void *a, const void *b)
static uint8 getQuadrant4D(BOX2DF *centroid, BOX2DF *inBox)
Datum centroid(PG_FUNCTION_ARGS)