339 spgPickSplitIn *in = (spgPickSplitIn *)PG_GETARG_POINTER(0);
340 spgPickSplitOut *out = (spgPickSplitOut *)PG_GETARG_POINTER(1);
343 double *lowXs = palloc(
sizeof(
double) * in->nTuples);
344 double *highXs = palloc(
sizeof(
double) * in->nTuples);
345 double *lowYs = palloc(
sizeof(
double) * in->nTuples);
346 double *highYs = palloc(
sizeof(
double) * in->nTuples);
349 for (i = 0; i < in->nTuples; i++)
351 BOX2DF *box = (BOX2DF *)DatumGetPointer(in->datums[i]);
353 lowXs[i] = (double)box->xmin;
354 highXs[i] = (
double)box->xmax;
355 lowYs[i] = (double)box->ymin;
356 highYs[i] = (
double)box->ymax;
364 median = in->nTuples / 2;
368 centroid->xmin = (float)lowXs[median];
369 centroid->xmax = (float)highXs[median];
370 centroid->ymin = (float)lowYs[median];
371 centroid->ymax = (float)highYs[median];
374 out->hasPrefix =
true;
375 out->prefixDatum = BoxPGetDatum(
centroid);
378 out->nodeLabels = NULL;
380 out->mapTuplesToNodes = palloc(
sizeof(
int) * in->nTuples);
381 out->leafTupleDatums = palloc(
sizeof(Datum) * in->nTuples);
386 for (i = 0; i < in->nTuples; i++)
388 BOX2DF *box = (BOX2DF *)DatumGetPointer(in->datums[i]);
391 out->leafTupleDatums[i] = PointerGetDatum(box);
392 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)