PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ lw_dist2d_pre_seg_seg()

int lw_dist2d_pre_seg_seg ( POINTARRAY l1,
POINTARRAY l2,
LISTSTRUCT list1,
LISTSTRUCT list2,
double  k,
DISTPTS dl 
)

preparation before lw_dist2d_seg_seg.

Definition at line 2104 of file measures.c.

2105 {
2106  const POINT2D *p1, *p2, *p3, *p4, *p01, *p02;
2107  int pnr1, pnr2, pnr3, pnr4, n1, n2, i, u, r, twist;
2108  double maxmeasure;
2109  n1 = l1->npoints;
2110  n2 = l2->npoints;
2111 
2112  LWDEBUG(2, "lw_dist2d_pre_seg_seg is called");
2113 
2114  p1 = getPoint2d_cp(l1, list1[0].pnr);
2115  p3 = getPoint2d_cp(l2, list2[0].pnr);
2116  lw_dist2d_pt_pt(p1, p3, dl);
2117  maxmeasure = sqrt(dl->distance * dl->distance + (dl->distance * dl->distance * k * k));
2118  twist = dl->twisted; /*to keep the incoming order between iterations*/
2119  for (i = (n1 - 1); i >= 0; --i)
2120  {
2121  /*we break this iteration when we have checked every point closer to our perpendicular "checkline" than
2122  * our shortest found distance*/
2123  if (((list2[0].themeasure - list1[i].themeasure)) > maxmeasure)
2124  break;
2125  /*because we are not iterating in the original point order we have to check the segment before and after
2126  * every point*/
2127  for (r = -1; r <= 1; r += 2)
2128  {
2129  pnr1 = list1[i].pnr;
2130  p1 = getPoint2d_cp(l1, pnr1);
2131  if (pnr1 + r < 0)
2132  {
2133  p01 = getPoint2d_cp(l1, (n1 - 1));
2134  if ((p1->x == p01->x) && (p1->y == p01->y))
2135  pnr2 = (n1 - 1);
2136  else
2137  pnr2 = pnr1; /* if it is a line and the last and first point is not the same we
2138  avoid the edge between start and end this way*/
2139  }
2140 
2141  else if (pnr1 + r > (n1 - 1))
2142  {
2143  p01 = getPoint2d_cp(l1, 0);
2144  if ((p1->x == p01->x) && (p1->y == p01->y))
2145  pnr2 = 0;
2146  else
2147  pnr2 = pnr1; /* if it is a line and the last and first point is not the same we
2148  avoid the edge between start and end this way*/
2149  }
2150  else
2151  pnr2 = pnr1 + r;
2152 
2153  p2 = getPoint2d_cp(l1, pnr2);
2154  for (u = 0; u < n2; ++u)
2155  {
2156  if (((list2[u].themeasure - list1[i].themeasure)) >= maxmeasure)
2157  break;
2158  pnr3 = list2[u].pnr;
2159  p3 = getPoint2d_cp(l2, pnr3);
2160  if (pnr3 == 0)
2161  {
2162  p02 = getPoint2d_cp(l2, (n2 - 1));
2163  if ((p3->x == p02->x) && (p3->y == p02->y))
2164  pnr4 = (n2 - 1);
2165  else
2166  pnr4 = pnr3; /* if it is a line and the last and first point is not the
2167  same we avoid the edge between start and end this way*/
2168  }
2169  else
2170  pnr4 = pnr3 - 1;
2171 
2172  p4 = getPoint2d_cp(l2, pnr4);
2173  dl->twisted = twist;
2174  if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl))
2175  return LW_FALSE;
2176 
2177  if (pnr3 >= (n2 - 1))
2178  {
2179  p02 = getPoint2d_cp(l2, 0);
2180  if ((p3->x == p02->x) && (p3->y == p02->y))
2181  pnr4 = 0;
2182  else
2183  pnr4 = pnr3; /* if it is a line and the last and first point is not the
2184  same we avoid the edge between start and end this way*/
2185  }
2186 
2187  else
2188  pnr4 = pnr3 + 1;
2189 
2190  p4 = getPoint2d_cp(l2, pnr4);
2191  dl->twisted = twist; /*we reset the "twist" for each iteration*/
2192  if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl))
2193  return LW_FALSE;
2194  /*here we "translate" the found mindistance so it can be compared to our "z"-values*/
2195  maxmeasure = sqrt(dl->distance * dl->distance + (dl->distance * dl->distance * k * k));
2196  }
2197  }
2198  }
2199 
2200  return LW_TRUE;
2201 }
char * r
Definition: cu_in_wkt.c:24
#define LW_FALSE
Definition: liblwgeom.h:108
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:101
int lw_dist2d_selected_seg_seg(const POINT2D *A, const POINT2D *B, const POINT2D *C, const POINT2D *D, DISTPTS *dl)
This is the same function as lw_dist2d_seg_seg but without any calculations to determine intersection...
Definition: measures.c:2209
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:2308
int twisted
Definition: measures.h:55
double distance
Definition: measures.h:51
int pnr
Definition: measures.h:62
double y
Definition: liblwgeom.h:404
double x
Definition: liblwgeom.h:404
uint32_t npoints
Definition: liblwgeom.h:441

References DISTPTS::distance, getPoint2d_cp(), lw_dist2d_pt_pt(), lw_dist2d_selected_seg_seg(), LW_FALSE, LW_TRUE, LWDEBUG, POINTARRAY::npoints, LISTSTRUCT::pnr, r, DISTPTS::twisted, POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_fast_ptarray_ptarray().

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