PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ 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 69 of file lwgeodetic_tree.c.

70 {
71  POINT2D *p1, *p2;
72  POINT3D q1, q2, c;
73  GEOGRAPHIC_POINT g1, g2, gc;
74  CIRC_NODE *node;
75  double diameter;
76 
77  p1 = (POINT2D*)getPoint_internal(pa, i);
78  p2 = (POINT2D*)getPoint_internal(pa, i+1);
79  geographic_point_init(p1->x, p1->y, &g1);
80  geographic_point_init(p2->x, p2->y, &g2);
81 
82  LWDEBUGF(3,"edge #%d (%g %g, %g %g)", i, p1->x, p1->y, p2->x, p2->y);
83 
84  diameter = sphere_distance(&g1, &g2);
85 
86  /* Zero length edge, doesn't get a node */
87  if ( FP_EQUALS(diameter, 0.0) )
88  return NULL;
89 
90  /* Allocate */
91  node = lwalloc(sizeof(CIRC_NODE));
92  node->p1 = p1;
93  node->p2 = p2;
94 
95  /* Convert ends to X/Y/Z, sum, and normalize to get mid-point */
96  geog2cart(&g1, &q1);
97  geog2cart(&g2, &q2);
98  vector_sum(&q1, &q2, &c);
99  normalize(&c);
100  cart2geog(&c, &gc);
101  node->center = gc;
102  node->radius = diameter / 2.0;
103 
104  LWDEBUGF(3,"edge #%d CENTER(%g %g) RADIUS=%g", i, gc.lon, gc.lat, node->radius);
105 
106  /* Leaf has no children */
107  node->num_nodes = 0;
108  node->nodes = NULL;
109  node->edge_num = i;
110 
111  /* Zero out metadata */
112  node->pt_outside.x = 0.0;
113  node->pt_outside.y = 0.0;
114  node->geom_type = 0;
115 
116  return node;
117 }
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: ptarray.c:1750
void * lwalloc(size_t size)
Definition: lwutil.c:229
#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:948
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:88
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:53
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
uint32_t num_nodes
POINT2D * p2
struct circ_node ** nodes
double radius
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: