PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ ptarray_segmentize_sphere_edge_recursive()

 static int ptarray_segmentize_sphere_edge_recursive ( const POINT3D * p1, const POINT3D * p2, const POINT4D * v1, const POINT4D * v2, double d, double max_seg_length, POINTARRAY * pa )
static

Definition at line 1542 of file lwgeodetic.c.

Referenced by ptarray_segmentize_sphere().

1547 {
1548  /* Reached the terminal leaf in recursion. Add */
1549  /* the left-most point to the pointarray here */
1550  /* We recurse down the left side first, so outputs should */
1551  /* end up added to the array in order this way */
1552  if (d <= max_seg_length)
1553  {
1554  GEOGRAPHIC_POINT g;
1555  POINT4D p;
1556  cart2geog(p1, &g);
1559  p.z = v1->z;
1560  p.m = v1->m;
1561  return ptarray_append_point(pa, &p, LW_FALSE);
1562  }
1563  /* Find the mid-point and recurse on the left and then the right */
1564  else
1565  {
1566  /* Calculate mid-point */
1567  POINT3D mid;
1568  mid.x = (p1->x + p2->x) / 2.0;
1569  mid.y = (p1->y + p2->y) / 2.0;
1570  mid.z = (p1->z + p2->z) / 2.0;
1571  normalize(&mid);
1572
1573  /* Calculate z/m mid-values */
1574  /* (ignore x/y, we get those from the 3-space calculations) */
1575  POINT4D midv;
1576  midv.z = (v1->z + v2->z) / 2.0;
1577  midv.m = (v1->m + v2->m) / 2.0;
1578  /* Recurse on the left first */
1579  ptarray_segmentize_sphere_edge_recursive(p1, &mid, v1, &midv, d/2.0, max_seg_length, pa);
1580  ptarray_segmentize_sphere_edge_recursive(&mid, p2, &midv, v2, d/2.0, max_seg_length, pa);
1581  return LW_SUCCESS;
1582  }
1583 }
double x
Definition: liblwgeom.h:351
double m
Definition: liblwgeom.h:351
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:580
double y
Definition: liblwgeom.h:339
#define LW_SUCCESS
Definition: liblwgeom.h:79
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:379
double x
Definition: liblwgeom.h:339
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
double z
Definition: liblwgeom.h:339
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:76