PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rect_leaf_node_distance()

static double rect_leaf_node_distance ( const RECT_NODE_LEAF n1,
const RECT_NODE_LEAF n2,
RECT_TREE_DISTANCE_STATE state 
)
static

Definition at line 1100 of file lwtree.c.

1101 {
1102  const POINT2D *p1, *p2, *p3, *q1, *q2, *q3;
1103  DISTPTS dl;
1104 
1105  //lwnotice("rect_leaf_node_distance, %d<->%d", n1->seg_num, n2->seg_num);
1106 
1108 
1109  switch (n1->seg_type)
1110  {
1111  case RECT_NODE_SEG_POINT:
1112  {
1113  p1 = getPoint2d_cp(n1->pa, n1->seg_num);
1114 
1115  switch (n2->seg_type)
1116  {
1117  case RECT_NODE_SEG_POINT:
1118  q1 = getPoint2d_cp(n2->pa, n2->seg_num);
1119  lw_dist2d_pt_pt(q1, p1, &dl);
1120  break;
1121 
1122  case RECT_NODE_SEG_LINEAR:
1123  q1 = getPoint2d_cp(n2->pa, n2->seg_num);
1124  q2 = getPoint2d_cp(n2->pa, n2->seg_num+1);
1125  lw_dist2d_pt_seg(p1, q1, q2, &dl);
1126  break;
1127 
1129  q1 = getPoint2d_cp(n2->pa, n2->seg_num*2);
1130  q2 = getPoint2d_cp(n2->pa, n2->seg_num*2+1);
1131  q3 = getPoint2d_cp(n2->pa, n2->seg_num*2+2);
1132  lw_dist2d_pt_arc(p1, q1, q2, q3, &dl);
1133  break;
1134 
1135  default:
1136  lwerror("%s: unsupported segment type", __func__);
1137  }
1138  break;
1139  }
1140 
1141  case RECT_NODE_SEG_LINEAR:
1142  {
1143  p1 = getPoint2d_cp(n1->pa, n1->seg_num);
1144  p2 = getPoint2d_cp(n1->pa, n1->seg_num+1);
1145 
1146  switch (n2->seg_type)
1147  {
1148  case RECT_NODE_SEG_POINT:
1149  q1 = getPoint2d_cp(n2->pa, n2->seg_num);
1150  lw_dist2d_pt_seg(q1, p1, p2, &dl);
1151  break;
1152 
1153  case RECT_NODE_SEG_LINEAR:
1154  q1 = getPoint2d_cp(n2->pa, n2->seg_num);
1155  q2 = getPoint2d_cp(n2->pa, n2->seg_num+1);
1156  lw_dist2d_seg_seg(q1, q2, p1, p2, &dl);
1157  // lwnotice(
1158  // "%d\tLINESTRING(%g %g,%g %g)\t%d\tLINESTRING(%g %g,%g %g)\t%g\t%g\t%g",
1159  // n1->seg_num,
1160  // p1->x, p1->y, p2->x, p2->y,
1161  // n2->seg_num,
1162  // q1->x, q1->y, q2->x, q2->y,
1163  // dl.distance, state->min_dist, state->max_dist);
1164  break;
1165 
1167  q1 = getPoint2d_cp(n2->pa, n2->seg_num*2);
1168  q2 = getPoint2d_cp(n2->pa, n2->seg_num*2+1);
1169  q3 = getPoint2d_cp(n2->pa, n2->seg_num*2+2);
1170  lw_dist2d_seg_arc(p1, p2, q1, q2, q3, &dl);
1171  break;
1172 
1173  default:
1174  lwerror("%s: unsupported segment type", __func__);
1175  }
1176  break;
1177  }
1179  {
1180  p1 = getPoint2d_cp(n1->pa, n1->seg_num*2);
1181  p2 = getPoint2d_cp(n1->pa, n1->seg_num*2+1);
1182  p3 = getPoint2d_cp(n1->pa, n1->seg_num*2+2);
1183 
1184  switch (n2->seg_type)
1185  {
1186  case RECT_NODE_SEG_POINT:
1187  q1 = getPoint2d_cp(n2->pa, n2->seg_num);
1188  lw_dist2d_pt_arc(q1, p1, p2, p3, &dl);
1189  break;
1190 
1191  case RECT_NODE_SEG_LINEAR:
1192  q1 = getPoint2d_cp(n2->pa, n2->seg_num);
1193  q2 = getPoint2d_cp(n2->pa, n2->seg_num+1);
1194  lw_dist2d_seg_arc(q1, q2, p1, p2, p3, &dl);
1195  break;
1196 
1198  q1 = getPoint2d_cp(n2->pa, n2->seg_num*2);
1199  q2 = getPoint2d_cp(n2->pa, n2->seg_num*2+1);
1200  q3 = getPoint2d_cp(n2->pa, n2->seg_num*2+2);
1201  lw_dist2d_arc_arc(p1, p2, p3, q1, q2, q3, &dl);
1202  break;
1203 
1204  default:
1205  lwerror("%s: unsupported segment type", __func__);
1206  }
1207  break;
1208  }
1209  default:
1210  lwerror("%s: unsupported segment type", __func__);
1211  }
1212 
1213  /* If this is a new global minima, save it */
1214  if (dl.distance < state->min_dist)
1215  {
1216  state->min_dist = dl.distance;
1217  state->p1 = dl.p1;
1218  state->p2 = dl.p2;
1219  }
1220 
1221  return dl.distance;
1222 }
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwgeom_api.c:374
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
@ RECT_NODE_SEG_POINT
Definition: lwtree.h:43
@ RECT_NODE_SEG_LINEAR
Definition: lwtree.h:44
@ RECT_NODE_SEG_CIRCULAR
Definition: lwtree.h:45
int lw_dist2d_pt_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, DISTPTS *dl)
Definition: measures.c:1439
int lw_dist2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B, DISTPTS *dl)
lw_dist2d_comp from p to line A->B This one is now sending every occasion to lw_dist2d_pt_pt Before i...
Definition: measures.c:2206
int lw_dist2d_seg_seg(const POINT2D *A, const POINT2D *B, const POINT2D *C, const POINT2D *D, DISTPTS *dl)
Finds the shortest distance between two segments.
Definition: measures.c:1821
int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl)
Calculate the shortest distance between an arc and an edge.
Definition: measures.c:1292
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
int lw_dist2d_arc_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl)
Definition: measures.c:1497
int lw_dist2d_pt_pt(const POINT2D *thep1, const POINT2D *thep2, DISTPTS *dl)
Compares incoming points and stores the points closest to each other or most far away from each other...
Definition: measures.c:2282
#define DIST_MIN
Definition: measures.h:44
POINT2D p1
Definition: measures.h:52
POINT2D p2
Definition: measures.h:53
double distance
Definition: measures.h:51
Structure used in distance-calculations.
Definition: measures.h:50
const POINTARRAY * pa
Definition: lwtree.h:50
int seg_num
Definition: lwtree.h:52
RECT_NODE_SEG_TYPE seg_type
Definition: lwtree.h:51

References DIST_MIN, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_arc_arc(), lw_dist2d_distpts_init(), lw_dist2d_pt_arc(), lw_dist2d_pt_pt(), lw_dist2d_pt_seg(), lw_dist2d_seg_arc(), lw_dist2d_seg_seg(), lwerror(), rect_tree_distance_state::min_dist, rect_tree_distance_state::p1, DISTPTS::p1, rect_tree_distance_state::p2, DISTPTS::p2, RECT_NODE_LEAF::pa, RECT_NODE_SEG_CIRCULAR, RECT_NODE_SEG_LINEAR, RECT_NODE_SEG_POINT, RECT_NODE_LEAF::seg_num, and RECT_NODE_LEAF::seg_type.

Referenced by rect_tree_distance_tree_recursive().

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