PostGIS  2.2.7dev-r@@SVN_REVISION@@
int lw_arc_calculate_gbox_cartesian_2d ( const POINT2D A1,
const POINT2D A2,
const POINT2D A3,
GBOX gbox 
)

Definition at line 429 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().

430 {
431  POINT2D xmin, ymin, xmax, ymax;
432  POINT2D C;
433  int A2_side;
434  double radius_A;
435 
436  LWDEBUG(2, "lw_arc_calculate_gbox_cartesian_2d called.");
437 
438  radius_A = lw_arc_center(A1, A2, A3, &C);
439 
440  /* Negative radius signals straight line, p1/p2/p3 are colinear */
441  if (radius_A < 0.0)
442  {
443  gbox->xmin = FP_MIN(A1->x, A3->x);
444  gbox->ymin = FP_MIN(A1->y, A3->y);
445  gbox->xmax = FP_MAX(A1->x, A3->x);
446  gbox->ymax = FP_MAX(A1->y, A3->y);
447  return LW_SUCCESS;
448  }
449 
450  /* Matched start/end points imply circle */
451  if ( A1->x == A3->x && A1->y == A3->y )
452  {
453  gbox->xmin = C.x - radius_A;
454  gbox->ymin = C.y - radius_A;
455  gbox->xmax = C.x + radius_A;
456  gbox->ymax = C.y + radius_A;
457  return LW_SUCCESS;
458  }
459 
460  /* First approximation, bounds of start/end points */
461  gbox->xmin = FP_MIN(A1->x, A3->x);
462  gbox->ymin = FP_MIN(A1->y, A3->y);
463  gbox->xmax = FP_MAX(A1->x, A3->x);
464  gbox->ymax = FP_MAX(A1->y, A3->y);
465 
466  /* Create points for the possible extrema */
467  xmin.x = C.x - radius_A;
468  xmin.y = C.y;
469  ymin.x = C.x;
470  ymin.y = C.y - radius_A;
471  xmax.x = C.x + radius_A;
472  xmax.y = C.y;
473  ymax.x = C.x;
474  ymax.y = C.y + radius_A;
475 
476  /* Divide the circle into two parts, one on each side of a line
477  joining p1 and p3. The circle extrema on the same side of that line
478  as p2 is on, are also the extrema of the bbox. */
479 
480  A2_side = lw_segment_side(A1, A3, A2);
481 
482  if ( A2_side == lw_segment_side(A1, A3, &xmin) )
483  gbox->xmin = xmin.x;
484 
485  if ( A2_side == lw_segment_side(A1, A3, &ymin) )
486  gbox->ymin = ymin.y;
487 
488  if ( A2_side == lw_segment_side(A1, A3, &xmax) )
489  gbox->xmax = xmax.x;
490 
491  if ( A2_side == lw_segment_side(A1, A3, &ymax) )
492  gbox->ymax = ymax.y;
493 
494  return LW_SUCCESS;
495 }
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:213
double xmax
Definition: liblwgeom.h:277
#define LW_SUCCESS
Definition: liblwgeom.h:65
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
#define FP_MIN(A, B)
double x
Definition: liblwgeom.h:312
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
double ymax
Definition: liblwgeom.h:279
double y
Definition: liblwgeom.h:312
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:50
#define FP_MAX(A, B)

Here is the call graph for this function:

Here is the caller graph for this function: