PostGIS 3.0.6dev-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 1633 of file lwgeodetic.c.

1638{
1640 /* Reached the terminal leaf in recursion. Add */
1641 /* the left-most point to the pointarray here */
1642 /* We recurse down the left side first, so outputs should */
1643 /* end up added to the array in order this way */
1644 if (d <= max_seg_length)
1645 {
1646 POINT4D p;
1647 cart2geog(p1, &g);
1648 p.x = v1->x;
1649 p.y = v1->y;
1650 p.z = v1->z;
1651 p.m = v1->m;
1652 return ptarray_append_point(pa, &p, LW_FALSE);
1653 }
1654 /* Find the mid-point and recurse on the left and then the right */
1655 else
1656 {
1657 /* Calculate mid-point */
1658 POINT3D mid;
1659 mid.x = (p1->x + p2->x) / 2.0;
1660 mid.y = (p1->y + p2->y) / 2.0;
1661 mid.z = (p1->z + p2->z) / 2.0;
1662 normalize(&mid);
1663
1664 /* Calculate z/m mid-values */
1665 POINT4D midv;
1666 cart2geog(&mid, &g);
1667 midv.x = rad2deg(g.lon);
1668 midv.y = rad2deg(g.lat);
1669 midv.z = (v1->z + v2->z) / 2.0;
1670 midv.m = (v1->m + v2->m) / 2.0;
1671 /* Recurse on the left first */
1672 ptarray_segmentize_sphere_edge_recursive(p1, &mid, v1, &midv, d/2.0, max_seg_length, pa);
1673 ptarray_segmentize_sphere_edge_recursive(&mid, p2, &midv, v2, d/2.0, max_seg_length, pa);
1674 return LW_SUCCESS;
1675 }
1676}
#define LW_FALSE
Definition liblwgeom.h:108
#define LW_SUCCESS
Definition liblwgeom.h:111
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:388
double x
Definition liblwgeom.h:388
double y
Definition liblwgeom.h:388
double m
Definition liblwgeom.h:400
double x
Definition liblwgeom.h:400
double z
Definition liblwgeom.h:400
double y
Definition liblwgeom.h:400

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: