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

◆ lw_arc_calculate_gbox_cartesian_2d()

int lw_arc_calculate_gbox_cartesian_2d ( const POINT2D A1,
const POINT2D A2,
const POINT2D A3,
GBOX gbox 
)

Definition at line 453 of file gbox.c.

454{
455 POINT2D xmin, ymin, xmax, ymax;
456 POINT2D C;
457 int A2_side;
458 double radius_A;
459
460 LWDEBUG(2, "lw_arc_calculate_gbox_cartesian_2d called.");
461
462 radius_A = lw_arc_center(A1, A2, A3, &C);
463
464 /* Negative radius signals straight line, p1/p2/p3 are collinear */
465 if (radius_A < 0.0)
466 {
467 gbox->xmin = FP_MIN(A1->x, A3->x);
468 gbox->ymin = FP_MIN(A1->y, A3->y);
469 gbox->xmax = FP_MAX(A1->x, A3->x);
470 gbox->ymax = FP_MAX(A1->y, A3->y);
471 return LW_SUCCESS;
472 }
473
474 /* Matched start/end points imply circle */
475 if ( A1->x == A3->x && A1->y == A3->y )
476 {
477 gbox->xmin = C.x - radius_A;
478 gbox->ymin = C.y - radius_A;
479 gbox->xmax = C.x + radius_A;
480 gbox->ymax = C.y + radius_A;
481 return LW_SUCCESS;
482 }
483
484 /* First approximation, bounds of start/end points */
485 gbox->xmin = FP_MIN(A1->x, A3->x);
486 gbox->ymin = FP_MIN(A1->y, A3->y);
487 gbox->xmax = FP_MAX(A1->x, A3->x);
488 gbox->ymax = FP_MAX(A1->y, A3->y);
489
490 /* Create points for the possible extrema */
491 xmin.x = C.x - radius_A;
492 xmin.y = C.y;
493 ymin.x = C.x;
494 ymin.y = C.y - radius_A;
495 xmax.x = C.x + radius_A;
496 xmax.y = C.y;
497 ymax.x = C.x;
498 ymax.y = C.y + radius_A;
499
500 /* Divide the circle into two parts, one on each side of a line
501 joining p1 and p3. The circle extrema on the same side of that line
502 as p2 is on, are also the extrema of the bbox. */
503
504 A2_side = lw_segment_side(A1, A3, A2);
505
506 if ( A2_side == lw_segment_side(A1, A3, &xmin) )
507 gbox->xmin = xmin.x;
508
509 if ( A2_side == lw_segment_side(A1, A3, &ymin) )
510 gbox->ymin = ymin.y;
511
512 if ( A2_side == lw_segment_side(A1, A3, &xmax) )
513 gbox->xmax = xmax.x;
514
515 if ( A2_side == lw_segment_side(A1, A3, &ymax) )
516 gbox->ymax = ymax.y;
517
518 return LW_SUCCESS;
519}
#define LW_SUCCESS
Definition liblwgeom.h:111
#define FP_MAX(A, B)
#define FP_MIN(A, B)
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition lwalgorithm.c:65
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:83
double ymax
Definition liblwgeom.h:343
double xmax
Definition liblwgeom.h:341
double ymin
Definition liblwgeom.h:342
double xmin
Definition liblwgeom.h:340
double y
Definition liblwgeom.h:376
double x
Definition liblwgeom.h:376

References FP_MAX, FP_MIN, lw_arc_center(), lw_segment_side(), LW_SUCCESS, LWDEBUG, POINT2D::x, GBOX::xmax, GBOX::xmin, POINT2D::y, GBOX::ymax, and GBOX::ymin.

Referenced by lw_arc_calculate_gbox_cartesian(), ptarrayarc_contains_point_partial(), and rect_node_leaf_new().

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