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

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

389 {
390  POINT2D xmin, ymin, xmax, ymax;
391  POINT2D C;
392  int A2_side;
393  double radius_A;
394 
395  LWDEBUG(2, "lw_arc_calculate_gbox_cartesian_2d called.");
396 
397  radius_A = lw_arc_center(A1, A2, A3, &C);
398 
399  /* Negative radius signals straight line, p1/p2/p3 are colinear */
400  if (radius_A < 0.0)
401  {
402  gbox->xmin = FP_MIN(A1->x, A3->x);
403  gbox->ymin = FP_MIN(A1->y, A3->y);
404  gbox->xmax = FP_MAX(A1->x, A3->x);
405  gbox->ymax = FP_MAX(A1->y, A3->y);
406  return LW_SUCCESS;
407  }
408 
409  /* Matched start/end points imply circle */
410  if ( A1->x == A3->x && A1->y == A3->y )
411  {
412  gbox->xmin = C.x - radius_A;
413  gbox->ymin = C.y - radius_A;
414  gbox->xmax = C.x + radius_A;
415  gbox->ymax = C.y + radius_A;
416  return LW_SUCCESS;
417  }
418 
419  /* First approximation, bounds of start/end points */
420  gbox->xmin = FP_MIN(A1->x, A3->x);
421  gbox->ymin = FP_MIN(A1->y, A3->y);
422  gbox->xmax = FP_MAX(A1->x, A3->x);
423  gbox->ymax = FP_MAX(A1->y, A3->y);
424 
425  /* Create points for the possible extrema */
426  xmin.x = C.x - radius_A;
427  xmin.y = C.y;
428  ymin.x = C.x;
429  ymin.y = C.y - radius_A;
430  xmax.x = C.x + radius_A;
431  xmax.y = C.y;
432  ymax.x = C.x;
433  ymax.y = C.y + radius_A;
434 
435  /* Divide the circle into two parts, one on each side of a line
436  joining p1 and p3. The circle extrema on the same side of that line
437  as p2 is on, are also the extrema of the bbox. */
438 
439  A2_side = lw_segment_side(A1, A3, A2);
440 
441  if ( A2_side == lw_segment_side(A1, A3, &xmin) )
442  gbox->xmin = xmin.x;
443 
444  if ( A2_side == lw_segment_side(A1, A3, &ymin) )
445  gbox->ymin = ymin.y;
446 
447  if ( A2_side == lw_segment_side(A1, A3, &xmax) )
448  gbox->xmax = xmax.x;
449 
450  if ( A2_side == lw_segment_side(A1, A3, &ymax) )
451  gbox->ymax = ymax.y;
452 
453  return LW_SUCCESS;
454 }
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:228
double xmax
Definition: liblwgeom.h:249
#define LW_SUCCESS
Definition: liblwgeom.h:55
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
#define FP_MIN(A, B)
double x
Definition: liblwgeom.h:284
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
double ymax
Definition: liblwgeom.h:251
double y
Definition: liblwgeom.h:284
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:62
#define FP_MAX(A, B)

Here is the call graph for this function:

Here is the caller graph for this function: