PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ edge_calculate_gbox_slow()

int edge_calculate_gbox_slow ( const GEOGRAPHIC_EDGE e,
GBOX gbox 
)

Definition at line 1346 of file lwgeodetic.c.

1347 {
1348  int steps = 1000000;
1349  int i;
1350  double dx, dy, dz;
1351  double distance = sphere_distance(&(e->start), &(e->end));
1352  POINT3D pn, p, start, end;
1353 
1354  /* Edge is zero length, just return the naive box */
1355  if ( FP_IS_ZERO(distance) )
1356  {
1357  LWDEBUG(4, "edge is zero length. returning");
1358  geog2cart(&(e->start), &start);
1359  geog2cart(&(e->end), &end);
1360  gbox_init_point3d(&start, gbox);
1361  gbox_merge_point3d(&end, gbox);
1362  return LW_SUCCESS;
1363  }
1364 
1365  /* Edge is antipodal (one point on each side of the globe),
1366  set the box to contain the whole world and return */
1367  if ( FP_EQUALS(distance, M_PI) )
1368  {
1369  LWDEBUG(4, "edge is antipodal. setting to maximum size box, and returning");
1370  gbox->xmin = gbox->ymin = gbox->zmin = -1.0;
1371  gbox->xmax = gbox->ymax = gbox->zmax = 1.0;
1372  return LW_SUCCESS;
1373  }
1374 
1375  /* Walk along the chord between start and end incrementally,
1376  normalizing at each step. */
1377  geog2cart(&(e->start), &start);
1378  geog2cart(&(e->end), &end);
1379  dx = (end.x - start.x)/steps;
1380  dy = (end.y - start.y)/steps;
1381  dz = (end.z - start.z)/steps;
1382  p = start;
1383  gbox->xmin = gbox->xmax = p.x;
1384  gbox->ymin = gbox->ymax = p.y;
1385  gbox->zmin = gbox->zmax = p.z;
1386  for ( i = 0; i < steps; i++ )
1387  {
1388  p.x += dx;
1389  p.y += dy;
1390  p.z += dz;
1391  pn = p;
1392  normalize(&pn);
1393  gbox_merge_point3d(&pn, gbox);
1394  }
1395  return LW_SUCCESS;
1396 }
int gbox_merge_point3d(const POINT3D *p, GBOX *gbox)
Update the GBOX to be large enough to include itself and the new point.
Definition: gbox.c:228
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: gbox.c:239
#define LW_SUCCESS
Definition: liblwgeom.h:111
#define FP_EQUALS(A, B)
#define FP_IS_ZERO(A)
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:615
double sphere_distance(const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
Given two points on a unit sphere, calculate their distance apart in radians.
Definition: lwgeodetic.c:948
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesian coordinates on unit sphere.
Definition: lwgeodetic.c:404
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032
double ymax
Definition: liblwgeom.h:371
double zmax
Definition: liblwgeom.h:373
double xmax
Definition: liblwgeom.h:369
double zmin
Definition: liblwgeom.h:372
double ymin
Definition: liblwgeom.h:370
double xmin
Definition: liblwgeom.h:368
GEOGRAPHIC_POINT start
Definition: lwgeodetic.h:64
GEOGRAPHIC_POINT end
Definition: lwgeodetic.h:65
double z
Definition: liblwgeom.h:416
double x
Definition: liblwgeom.h:416
double y
Definition: liblwgeom.h:416

References distance(), GEOGRAPHIC_EDGE::end, FP_EQUALS, FP_IS_ZERO, gbox_init_point3d(), gbox_merge_point3d(), geog2cart(), LW_SUCCESS, LWDEBUG, normalize(), sphere_distance(), GEOGRAPHIC_EDGE::start, POINT3D::x, GBOX::xmax, GBOX::xmin, POINT3D::y, GBOX::ymax, GBOX::ymin, POINT3D::z, GBOX::zmax, and GBOX::zmin.

Here is the call graph for this function: