PostGIS  2.4.9dev-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 1629 of file lwgeodetic.c.

Referenced by ptarray_segmentize_sphere().

1634 {
1635  GEOGRAPHIC_POINT g;
1636  /* Reached the terminal leaf in recursion. Add */
1637  /* the left-most point to the pointarray here */
1638  /* We recurse down the left side first, so outputs should */
1639  /* end up added to the array in order this way */
1640  if (d <= max_seg_length)
1641  {
1642  POINT4D p;
1643  cart2geog(p1, &g);
1644  p.x = v1->x;
1645  p.y = v1->y;
1646  p.z = v1->z;
1647  p.m = v1->m;
1648  return ptarray_append_point(pa, &p, LW_FALSE);
1649  }
1650  /* Find the mid-point and recurse on the left and then the right */
1651  else
1652  {
1653  /* Calculate mid-point */
1654  POINT3D mid;
1655  mid.x = (p1->x + p2->x) / 2.0;
1656  mid.y = (p1->y + p2->y) / 2.0;
1657  mid.z = (p1->z + p2->z) / 2.0;
1658  normalize(&mid);
1659
1660  /* Calculate z/m mid-values */
1661  POINT4D midv;
1662  cart2geog(&mid, &g);
1665  midv.z = (v1->z + v2->z) / 2.0;
1666  midv.m = (v1->m + v2->m) / 2.0;
1667  /* Recurse on the left first */
1668  ptarray_segmentize_sphere_edge_recursive(p1, &mid, v1, &midv, d/2.0, max_seg_length, pa);
1669  ptarray_segmentize_sphere_edge_recursive(&mid, p2, &midv, v2, d/2.0, max_seg_length, pa);
1670  return LW_SUCCESS;
1671  }
1672 }
double x
Definition: liblwgeom.h:352
double m
Definition: liblwgeom.h:352
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:611
double y
Definition: liblwgeom.h:340
#define LW_SUCCESS
Definition: liblwgeom.h:80
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:410
double x
Definition: liblwgeom.h:340
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:52
double z
Definition: liblwgeom.h:340
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:77