PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwgeom_calculate_mbc()

LWBOUNDINGCIRCLE * lwgeom_calculate_mbc ( const LWGEOM g)

Definition at line 237 of file lwboundingcircle.c.

238{
239 SUPPORTING_POINTS* support;
241 LWPOINTITERATOR* it;
242 uint32_t num_points;
243 POINT2D** points;
244 POINT4D p;
245 uint32_t i;
246 int success;
247
248 if(g == NULL || lwgeom_is_empty(g))
249 return LW_FAILURE;
250
251 num_points = lwgeom_count_vertices(g);
253 points = lwalloc(num_points * sizeof(POINT2D*));
254 for (i = 0; i < num_points; i++)
255 {
256 if(!lwpointiterator_next(it, &p))
257 {
258 uint32_t j;
259 for (j = 0; j < i; j++)
260 {
261 lwfree(points[j]);
262 }
264 lwfree(points);
265 return LW_FAILURE;
266 }
267
268 points[i] = lwalloc(sizeof(POINT2D));
269 points[i]->x = p.x;
270 points[i]->y = p.y;
271 }
273
274 support = supporting_points_create();
276 /* Technically, a randomized algorithm would demand that we shuffle the input points
277 * before we call calculate_mbc(). However, we make the (perhaps poor) assumption that
278 * the order we happen to find the points is as good as random, or close enough.
279 * */
280 success = calculate_mbc((const POINT2D**) points, num_points, support, result);
281
282 for (i = 0; i < num_points; i++)
283 {
284 lwfree(points[i]);
285 }
286 lwfree(points);
288
289 if (!success)
290 return NULL;
291
292 return result;
293}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
#define LW_FAILURE
Definition liblwgeom.h:96
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition lwiterator.c:243
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point.
Definition lwiterator.c:210
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition lwiterator.c:268
void * lwalloc(size_t size)
Definition lwutil.c:227
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition lwgeom.c:1337
void lwfree(void *mem)
Definition lwutil.c:248
static void supporting_points_destroy(SUPPORTING_POINTS *s)
static int calculate_mbc(const POINT2D **points, uint32_t max_n, SUPPORTING_POINTS *support, LWBOUNDINGCIRCLE *mbc)
static SUPPORTING_POINTS * supporting_points_create()
static LWBOUNDINGCIRCLE * lwboundingcircle_create()
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414

References calculate_mbc(), LW_FAILURE, lwalloc(), lwboundingcircle_create(), lwfree(), lwgeom_count_vertices(), lwgeom_is_empty(), lwpointiterator_create(), lwpointiterator_destroy(), lwpointiterator_next(), result, supporting_points_create(), supporting_points_destroy(), POINT2D::x, POINT4D::x, POINT2D::y, and POINT4D::y.

Referenced by mbc_test(), ST_MinimumBoundingCircle(), ST_MinimumBoundingRadius(), and test_empty().

Here is the call graph for this function:
Here is the caller graph for this function: