PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ edge_calculate_gbox_slow()

int edge_calculate_gbox_slow ( const GEOGRAPHIC_EDGE e,
GBOX gbox 
)

Definition at line 1340 of file lwgeodetic.c.

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.

1341 {
1342  int steps = 1000000;
1343  int i;
1344  double dx, dy, dz;
1345  double distance = sphere_distance(&(e->start), &(e->end));
1346  POINT3D pn, p, start, end;
1347 
1348  /* Edge is zero length, just return the naive box */
1349  if ( FP_IS_ZERO(distance) )
1350  {
1351  LWDEBUG(4, "edge is zero length. returning");
1352  geog2cart(&(e->start), &start);
1353  geog2cart(&(e->end), &end);
1354  gbox_init_point3d(&start, gbox);
1355  gbox_merge_point3d(&end, gbox);
1356  return LW_SUCCESS;
1357  }
1358 
1359  /* Edge is antipodal (one point on each side of the globe),
1360  set the box to contain the whole world and return */
1361  if ( FP_EQUALS(distance, M_PI) )
1362  {
1363  LWDEBUG(4, "edge is antipodal. setting to maximum size box, and returning");
1364  gbox->xmin = gbox->ymin = gbox->zmin = -1.0;
1365  gbox->xmax = gbox->ymax = gbox->zmax = 1.0;
1366  return LW_SUCCESS;
1367  }
1368 
1369  /* Walk along the chord between start and end incrementally,
1370  normalizing at each step. */
1371  geog2cart(&(e->start), &start);
1372  geog2cart(&(e->end), &end);
1373  dx = (end.x - start.x)/steps;
1374  dy = (end.y - start.y)/steps;
1375  dz = (end.z - start.z)/steps;
1376  p = start;
1377  gbox->xmin = gbox->xmax = p.x;
1378  gbox->ymin = gbox->ymax = p.y;
1379  gbox->zmin = gbox->zmax = p.z;
1380  for ( i = 0; i < steps; i++ )
1381  {
1382  p.x += dx;
1383  p.y += dy;
1384  p.z += dz;
1385  pn = p;
1386  normalize(&pn);
1387  gbox_merge_point3d(&pn, gbox);
1388  }
1389  return LW_SUCCESS;
1390 }
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:944
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:611
double y
Definition: liblwgeom.h:340
double xmax
Definition: liblwgeom.h:293
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
double x
Definition: liblwgeom.h:340
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: g_box.c:251
#define FP_IS_ZERO(A)
double z
Definition: liblwgeom.h:340
double zmax
Definition: liblwgeom.h:297
double ymin
Definition: liblwgeom.h:294
double xmin
Definition: liblwgeom.h:292
GEOGRAPHIC_POINT start
Definition: lwgeodetic.h:63
int gbox_merge_point3d(const POINT3D *p, GBOX *gbox)
Update the GBOX to be large enough to include itself and the new point.
Definition: g_box.c:240
double ymax
Definition: liblwgeom.h:295
GEOGRAPHIC_POINT end
Definition: lwgeodetic.h:64
Datum distance(PG_FUNCTION_ARGS)
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:400
double zmin
Definition: liblwgeom.h:296
#define FP_EQUALS(A, B)
Here is the call graph for this function: