PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 1587 of file lwgeodetic.c.

1592{
1594 /* Reached the terminal leaf in recursion. Add */
1595 /* the left-most point to the pointarray here */
1596 /* We recurse down the left side first, so outputs should */
1597 /* end up added to the array in order this way */
1598 if (d <= max_seg_length)
1599 {
1600 POINT4D p;
1601 cart2geog(p1, &g);
1602 p.x = v1->x;
1603 p.y = v1->y;
1604 p.z = v1->z;
1605 p.m = v1->m;
1606 return ptarray_append_point(pa, &p, LW_FALSE);
1607 }
1608 /* Find the mid-point and recurse on the left and then the right */
1609 else
1610 {
1611 /* Calculate mid-point */
1612 POINT3D mid;
1613 mid.x = (p1->x + p2->x) / 2.0;
1614 mid.y = (p1->y + p2->y) / 2.0;
1615 mid.z = (p1->z + p2->z) / 2.0;
1616 normalize(&mid);
1617
1618 /* Calculate z/m mid-values */
1619 POINT4D midv;
1620 cart2geog(&mid, &g);
1621 midv.x = rad2deg(g.lon);
1622 midv.y = rad2deg(g.lat);
1623 midv.z = (v1->z + v2->z) / 2.0;
1624 midv.m = (v1->m + v2->m) / 2.0;
1625 /* Recurse on the left first */
1626 ptarray_segmentize_sphere_edge_recursive(p1, &mid, v1, &midv, d/2.0, max_seg_length, pa);
1627 ptarray_segmentize_sphere_edge_recursive(&mid, p2, &midv, v2, d/2.0, max_seg_length, pa);
1628 return LW_SUCCESS;
1629 }
1630}
#define LW_FALSE
Definition liblwgeom.h:94
#define LW_SUCCESS
Definition liblwgeom.h:97
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,...
Definition ptarray.c:147
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition lwgeodetic.c:615
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition lwgeodetic.c:414
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)
#define rad2deg(r)
Definition lwgeodetic.h:81
Point in spherical coordinates on the world.
Definition lwgeodetic.h:54
double z
Definition liblwgeom.h:402
double x
Definition liblwgeom.h:402
double y
Definition liblwgeom.h:402
double m
Definition liblwgeom.h:414
double x
Definition liblwgeom.h:414
double z
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414

References cart2geog(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LW_FALSE, LW_SUCCESS, POINT4D::m, normalize(), ptarray_append_point(), ptarray_segmentize_sphere_edge_recursive(), rad2deg, POINT3D::x, POINT4D::x, POINT3D::y, POINT4D::y, POINT3D::z, and POINT4D::z.

Referenced by ptarray_segmentize_sphere(), and ptarray_segmentize_sphere_edge_recursive().

Here is the call graph for this function:
Here is the caller graph for this function: