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

◆ circ_node_leaf_new()

static CIRC_NODE * circ_node_leaf_new ( const POINTARRAY pa,
int  i 
)
static

Create a new leaf node, storing pointers back to the end points for later.

Definition at line 68 of file lwgeodetic_tree.c.

69{
70 POINT2D *p1, *p2;
71 POINT3D q1, q2, c;
72 GEOGRAPHIC_POINT g1, g2, gc;
73 CIRC_NODE *node;
74 double diameter;
75
76 p1 = (POINT2D*)getPoint_internal(pa, i);
77 p2 = (POINT2D*)getPoint_internal(pa, i+1);
78 geographic_point_init(p1->x, p1->y, &g1);
79 geographic_point_init(p2->x, p2->y, &g2);
80
81 LWDEBUGF(3,"edge #%d (%g %g, %g %g)", i, p1->x, p1->y, p2->x, p2->y);
82
83 diameter = sphere_distance(&g1, &g2);
84
85 /* Zero length edge, doesn't get a node */
86 if ( FP_EQUALS(diameter, 0.0) )
87 return NULL;
88
89 /* Allocate */
90 node = lwalloc(sizeof(CIRC_NODE));
91 node->p1 = p1;
92 node->p2 = p2;
93
94 /* Convert ends to X/Y/Z, sum, and normalize to get mid-point */
95 geog2cart(&g1, &q1);
96 geog2cart(&g2, &q2);
97 vector_sum(&q1, &q2, &c);
98 normalize(&c);
99 cart2geog(&c, &gc);
100 node->center = gc;
101 node->radius = diameter / 2.0;
102
103 LWDEBUGF(3,"edge #%d CENTER(%g %g) RADIUS=%g", i, gc.lon, gc.lat, node->radius);
104
105 /* Leaf has no children */
106 node->num_nodes = 0;
107 node->nodes = NULL;
108 node->edge_num = i;
109
110 /* Zero out metadata */
111 node->pt_outside.x = 0.0;
112 node->pt_outside.y = 0.0;
113 node->geom_type = 0;
114
115 return node;
116}
void * lwalloc(size_t size)
Definition lwutil.c:227
#define FP_EQUALS(A, B)
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
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition lwgeodetic.c:180
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:896
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition lwgeodetic.c:465
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesian coordinates on unit sphere.
Definition lwgeodetic.c:404
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition lwinline.h:75
Point in spherical coordinates on the world.
Definition lwgeodetic.h:54
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390
uint32_t num_nodes
POINT2D * p2
struct circ_node ** nodes
POINT2D * p1
POINT2D pt_outside
GEOGRAPHIC_POINT center
uint32_t geom_type
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.

References cart2geog(), circ_node::center, circ_node::edge_num, FP_EQUALS, geog2cart(), geographic_point_init(), circ_node::geom_type, getPoint_internal(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, lwalloc(), LWDEBUGF, circ_node::nodes, normalize(), circ_node::num_nodes, circ_node::p1, circ_node::p2, circ_node::pt_outside, circ_node::radius, sphere_distance(), vector_sum(), POINT2D::x, and POINT2D::y.

Referenced by circ_tree_new().

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