PostGIS  2.4.9dev-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 464 of file g_box.c.

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(), and ptarrayarc_contains_point_partial().

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