679{
680 double max;
681 double d, d_min;
682 uint32_t i;
683
685
686
687
688
689
690
691
692 if( *min_dist < threshold || *min_dist == 0.0 )
693 return *min_dist;
694
695
697 {
698 LWDEBUGF(4,
"pruning pair %p, %p", n1, n2);
699 return FLT_MAX;
700 }
701
702
705 if( max < *max_dist )
706 *max_dist = max;
707
708
709
711 {
714 LWDEBUGF(4,
"n1 is polygon, testing if contains (%.5g,%.5g)", pt.
x, pt.
y);
716 {
718 *min_dist = 0.0;
721 return *min_dist;
722 }
723 }
724
725
727 {
730 LWDEBUGF(4,
"n2 is polygon, testing if contains (%.5g,%.5g)", pt.
x, pt.
y);
732 {
736 *min_dist = 0.0;
737 return *min_dist;
738 }
739 }
740
741
743 {
744 double d;
747
748 if ( n1->
p1 == n1->
p2 || n2->
p1 == n2->
p2 )
749 {
752
753
754 if ( n1->
p1 == n1->
p2 && n2->
p1 == n2->
p2 )
755 {
758 close1 = gp1; close2 = gp2;
760 }
761
762 else if ( n1->
p1 == n1->
p2 )
763 {
767 close1 = gp1;
769 }
770
771 else
772 {
776 close1 = gp1;
778 }
780 }
781
782 else
783 {
796 {
797 d = 0.0;
799 close1 = close2 = g;
800 }
801 else
802 {
804 }
805 LWDEBUGF(4,
"edge_distance_to_edge returned %g", d);
806 }
807 if ( d < *min_dist )
808 {
809 *min_dist = d;
810 *closest1 = close1;
811 *closest2 = close2;
812 }
813 return d;
814 }
815 else
816 {
817 d_min = FLT_MAX;
818
819
820
822 {
825 {
828 }
829 }
831 {
834 {
837 }
838 }
840 {
843 {
846 }
847 }
849 {
852 {
855 }
856 }
857 else
858 {
859
860 }
861
862 return d_min;
863 }
864}
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
double sphere_distance(const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
Given two points on a unit sphere, calculate their distance apart in radians.
int edge_intersection(const GEOGRAPHIC_EDGE *e1, const GEOGRAPHIC_EDGE *e2, GEOGRAPHIC_POINT *g)
Returns true if an intersection can be calculated, and places it in *g.
uint32_t edge_intersects(const POINT3D *A1, const POINT3D *A2, const POINT3D *B1, const POINT3D *B2)
Returns non-zero if edges A and B interact.
double edge_distance_to_point(const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *gp, GEOGRAPHIC_POINT *closest)
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesian coordinates on unit sphere.
double edge_distance_to_edge(const GEOGRAPHIC_EDGE *e1, const GEOGRAPHIC_EDGE *e2, GEOGRAPHIC_POINT *closest1, GEOGRAPHIC_POINT *closest2)
Calculate the distance between two edges.
int circ_tree_get_point(const CIRC_NODE *node, POINT2D *pt)
Returns a POINT2D that is a vertex of the input shape.
static double circ_node_max_distance(const CIRC_NODE *n1, const CIRC_NODE *n2)
static double circ_tree_distance_tree_internal(const CIRC_NODE *n1, const CIRC_NODE *n2, double threshold, double *min_dist, double *max_dist, GEOGRAPHIC_POINT *closest1, GEOGRAPHIC_POINT *closest2)
static int circ_node_is_leaf(const CIRC_NODE *node)
Internal nodes have their point references set to NULL.
static void circ_internal_nodes_sort(CIRC_NODE **nodes, uint32_t num_nodes, const CIRC_NODE *target_node)
static double circ_node_min_distance(const CIRC_NODE *n1, const CIRC_NODE *n2)
int circ_tree_contains_point(const CIRC_NODE *node, const POINT2D *pt, const POINT2D *pt_outside, int level, int *on_boundary)
Walk the tree and count intersections between the stab line and the edges.
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
Two-point great circle segment from a to b.
Point in spherical coordinates on the world.
struct circ_node ** nodes