PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ edge_calculate_gbox_slow()

int edge_calculate_gbox_slow ( const GEOGRAPHIC_EDGE e,
GBOX gbox 
)

Definition at line 1292 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.

1293 {
1294  int steps = 1000000;
1295  int i;
1296  double dx, dy, dz;
1297  double distance = sphere_distance(&(e->start), &(e->end));
1298  POINT3D pn, p, start, end;
1299 
1300  /* Edge is zero length, just return the naive box */
1301  if ( FP_IS_ZERO(distance) )
1302  {
1303  LWDEBUG(4, "edge is zero length. returning");
1304  geog2cart(&(e->start), &start);
1305  geog2cart(&(e->end), &end);
1306  gbox_init_point3d(&start, gbox);
1307  gbox_merge_point3d(&end, gbox);
1308  return LW_SUCCESS;
1309  }
1310 
1311  /* Edge is antipodal (one point on each side of the globe),
1312  set the box to contain the whole world and return */
1313  if ( FP_EQUALS(distance, M_PI) )
1314  {
1315  LWDEBUG(4, "edge is antipodal. setting to maximum size box, and returning");
1316  gbox->xmin = gbox->ymin = gbox->zmin = -1.0;
1317  gbox->xmax = gbox->ymax = gbox->zmax = 1.0;
1318  return LW_SUCCESS;
1319  }
1320 
1321  /* Walk along the chord between start and end incrementally,
1322  normalizing at each step. */
1323  geog2cart(&(e->start), &start);
1324  geog2cart(&(e->end), &end);
1325  dx = (end.x - start.x)/steps;
1326  dy = (end.y - start.y)/steps;
1327  dz = (end.z - start.z)/steps;
1328  p = start;
1329  gbox->xmin = gbox->xmax = p.x;
1330  gbox->ymin = gbox->ymax = p.y;
1331  gbox->zmin = gbox->zmax = p.z;
1332  for ( i = 0; i < steps; i++ )
1333  {
1334  p.x += dx;
1335  p.y += dy;
1336  p.z += dz;
1337  pn = p;
1338  normalize(&pn);
1339  gbox_merge_point3d(&pn, gbox);
1340  }
1341  return LW_SUCCESS;
1342 }
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:898
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:565
double y
Definition: liblwgeom.h:324
double xmax
Definition: liblwgeom.h:277
#define LW_SUCCESS
Definition: liblwgeom.h:65
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
double x
Definition: liblwgeom.h:324
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: g_box.c:216
#define FP_IS_ZERO(A)
double z
Definition: liblwgeom.h:324
double zmax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
GEOGRAPHIC_POINT start
Definition: lwgeodetic.h:43
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:205
double ymax
Definition: liblwgeom.h:279
GEOGRAPHIC_POINT end
Definition: lwgeodetic.h:44
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:354
double zmin
Definition: liblwgeom.h:280
#define FP_EQUALS(A, B)
Here is the call graph for this function: