Create a new internal node, calculating the new measure range for the node, and storing pointers to the child nodes.
231{
234 double new_radius;
235 double offset1, dist, D, r1, ri;
236 uint32_t i, new_geom_type;
237
238 LWDEBUGF(3,
"called with %d nodes --", num_nodes);
239
240
241 if ( num_nodes < 1 )
242 return node;
243
244
245 new_center = c[0]->
center;
246 new_radius = c[0]->
radius;
248
249
250 for ( i = 1; i < num_nodes; i++ )
251 {
252 c1 = new_center;
253 r1 = new_radius;
254
257
258
259
260 if ( ! new_geom_type )
261 {
263 }
264
266 {
267
268 if ( new_geom_type != c[i]->geom_type )
269 {
271 }
272 else
273 {
275 }
276 }
277
279 {
281 }
282
283
284 LWDEBUGF(3,
"distance between new (%g %g) and %i (%g %g) is %g", c1.
lon, c1.
lat, i, c[i]->center.lon, c[i]->center.lat, dist);
285
287 {
288 LWDEBUG(3,
" distance between centers is zero");
289 new_radius = r1 + 2*dist;
290 new_center = c1;
291 }
292 else if ( dist < fabs(r1 - ri) )
293 {
294
295 if ( r1 > ri )
296 {
298 new_center = c1;
299 new_radius = r1;
300 }
301
302 else
303 {
305 new_center = c[i]->
center;
306 new_radius = ri;
307 }
308 }
309 else
310 {
311 LWDEBUG(3,
" calculating new center");
312
313 D = dist + r1 + ri;
315
316
317 new_radius = D / 2.0;
318
319
320 offset1 = ri + (D - (2.0*r1 + 2.0*ri)) / 2.0;
321 LWDEBUGF(3,
" offset1 is %g", offset1);
322
323
324
325
326
328 {
330 new_radius *= 1.1;
331 }
332 }
333 LWDEBUGF(3,
" new center is (%g %g) new radius is %g", new_center.
lon, new_center.
lat, new_radius);
334 }
335
339 node->
center = new_center;
340 node->
radius = new_radius;
347 return node;
348}
uint32_t lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
void * lwalloc(size_t size)
double sphere_distance(const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
Given two points on a unit sphere, calculate their distance apart in radians.
static int circ_center_spherical(const GEOGRAPHIC_POINT *c1, const GEOGRAPHIC_POINT *c2, double distance, double offset, GEOGRAPHIC_POINT *center)
Given the centers of two circles, and the offset distance we want to put the new center between them ...
static int circ_center_cartesian(const GEOGRAPHIC_POINT *c1, const GEOGRAPHIC_POINT *c2, double distance, double offset, GEOGRAPHIC_POINT *center)
Where the circ_center_spherical() function fails, we need a fall-back.
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
Point in spherical coordinates on the world.
struct circ_node ** nodes
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.