PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ 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 465 of file gbox.c.

466 {
467  POINT2D xmin, ymin, xmax, ymax;
468  POINT2D C;
469  int A2_side;
470  double radius_A;
471 
472  LWDEBUG(2, "lw_arc_calculate_gbox_cartesian_2d called.");
473 
474  radius_A = lw_arc_center(A1, A2, A3, &C);
475 
476  /* Negative radius signals straight line, p1/p2/p3 are collinear */
477  if (radius_A < 0.0)
478  {
479  gbox->xmin = FP_MIN(A1->x, A3->x);
480  gbox->ymin = FP_MIN(A1->y, A3->y);
481  gbox->xmax = FP_MAX(A1->x, A3->x);
482  gbox->ymax = FP_MAX(A1->y, A3->y);
483  return LW_SUCCESS;
484  }
485 
486  /* Matched start/end points imply circle */
487  if ( A1->x == A3->x && A1->y == A3->y )
488  {
489  gbox->xmin = C.x - radius_A;
490  gbox->ymin = C.y - radius_A;
491  gbox->xmax = C.x + radius_A;
492  gbox->ymax = C.y + radius_A;
493  return LW_SUCCESS;
494  }
495 
496  /* First approximation, bounds of start/end points */
497  gbox->xmin = FP_MIN(A1->x, A3->x);
498  gbox->ymin = FP_MIN(A1->y, A3->y);
499  gbox->xmax = FP_MAX(A1->x, A3->x);
500  gbox->ymax = FP_MAX(A1->y, A3->y);
501 
502  /* Create points for the possible extrema */
503  xmin.x = C.x - radius_A;
504  xmin.y = C.y;
505  ymin.x = C.x;
506  ymin.y = C.y - radius_A;
507  xmax.x = C.x + radius_A;
508  xmax.y = C.y;
509  ymax.x = C.x;
510  ymax.y = C.y + radius_A;
511 
512  /* Divide the circle into two parts, one on each side of a line
513  joining p1 and p3. The circle extrema on the same side of that line
514  as p2 is on, are also the extrema of the bbox. */
515 
516  A2_side = lw_segment_side(A1, A3, A2);
517 
518  if ( A2_side == lw_segment_side(A1, A3, &xmin) )
519  gbox->xmin = xmin.x;
520 
521  if ( A2_side == lw_segment_side(A1, A3, &ymin) )
522  gbox->ymin = ymin.y;
523 
524  if ( A2_side == lw_segment_side(A1, A3, &xmax) )
525  gbox->xmax = xmax.x;
526 
527  if ( A2_side == lw_segment_side(A1, A3, &ymax) )
528  gbox->ymax = ymax.y;
529 
530  return LW_SUCCESS;
531 }
#define LW_SUCCESS
Definition: liblwgeom.h:97
#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.
Definition: lwalgorithm.c:234
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:70
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
double ymax
Definition: liblwgeom.h:357
double xmax
Definition: liblwgeom.h:355
double ymin
Definition: liblwgeom.h:356
double xmin
Definition: liblwgeom.h:354
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390

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: