PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 2056 of file measures.c.

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

Referenced by lw_dist2d_fast_ptarray_ptarray().

2057 {
2058  const POINT2D *p1, *p2, *p3, *p4, *p01, *p02;
2059  int pnr1,pnr2,pnr3,pnr4, n1, n2, i, u, r, twist;
2060  double maxmeasure;
2061  n1= l1->npoints;
2062  n2 = l2->npoints;
2063 
2064  LWDEBUG(2, "lw_dist2d_pre_seg_seg is called");
2065 
2066  p1 = getPoint2d_cp(l1, list1[0].pnr);
2067  p3 = getPoint2d_cp(l2, list2[0].pnr);
2068  lw_dist2d_pt_pt(p1, p3, dl);
2069  maxmeasure = sqrt(dl->distance*dl->distance + (dl->distance*dl->distance*k*k));
2070  twist = dl->twisted; /*to keep the incomming order between iterations*/
2071  for (i =(n1-1); i>=0; --i)
2072  {
2073  /*we break this iteration when we have checked every
2074  point closer to our perpendicular "checkline" than
2075  our shortest found distance*/
2076  if (((list2[0].themeasure-list1[i].themeasure)) > maxmeasure) break;
2077  for (r=-1; r<=1; r +=2) /*because we are not iterating in the original pointorder we have to check the segment before and after every point*/
2078  {
2079  pnr1 = list1[i].pnr;
2080  p1 = getPoint2d_cp(l1, pnr1);
2081  if (pnr1+r<0)
2082  {
2083  p01 = getPoint2d_cp(l1, (n1-1));
2084  if (( p1->x == p01->x) && (p1->y == p01->y)) pnr2 = (n1-1);
2085  else pnr2 = pnr1; /* if it is a line and the last and first point is not the same we avoid the edge between start and end this way*/
2086  }
2087 
2088  else if (pnr1+r>(n1-1))
2089  {
2090  p01 = getPoint2d_cp(l1, 0);
2091  if (( p1->x == p01->x) && (p1->y == p01->y)) pnr2 = 0;
2092  else pnr2 = pnr1; /* if it is a line and the last and first point is not the same we avoid the edge between start and end this way*/
2093  }
2094  else pnr2 = pnr1+r;
2095 
2096 
2097  p2 = getPoint2d_cp(l1, pnr2);
2098  for (u=0; u<n2; ++u)
2099  {
2100  if (((list2[u].themeasure-list1[i].themeasure)) >= maxmeasure) break;
2101  pnr3 = list2[u].pnr;
2102  p3 = getPoint2d_cp(l2, pnr3);
2103  if (pnr3==0)
2104  {
2105  p02 = getPoint2d_cp(l2, (n2-1));
2106  if (( p3->x == p02->x) && (p3->y == p02->y)) pnr4 = (n2-1);
2107  else pnr4 = pnr3; /* if it is a line and the last and first point is not the same we avoid the edge between start and end this way*/
2108  }
2109  else pnr4 = pnr3-1;
2110 
2111  p4 = getPoint2d_cp(l2, pnr4);
2112  dl->twisted=twist;
2113  if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl)) return LW_FALSE;
2114 
2115  if (pnr3>=(n2-1))
2116  {
2117  p02 = getPoint2d_cp(l2, 0);
2118  if (( p3->x == p02->x) && (p3->y == p02->y)) pnr4 = 0;
2119  else pnr4 = pnr3; /* if it is a line and the last and first point is not the same we avoid the edge between start and end this way*/
2120  }
2121 
2122  else pnr4 = pnr3+1;
2123 
2124  p4 = getPoint2d_cp(l2, pnr4);
2125  dl->twisted=twist; /*we reset the "twist" for each iteration*/
2126  if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl)) return LW_FALSE;
2127 
2128  maxmeasure = sqrt(dl->distance*dl->distance + (dl->distance*dl->distance*k*k));/*here we "translate" the found mindistance so it can be compared to our "z"-values*/
2129  }
2130  }
2131  }
2132 
2133  return LW_TRUE;
2134 }
char * r
Definition: cu_in_wkt.c:24
int npoints
Definition: liblwgeom.h:355
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
double x
Definition: liblwgeom.h:312
#define LW_FALSE
Definition: liblwgeom.h:62
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:472
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
double y
Definition: liblwgeom.h:312
int twisted
Definition: measures.h:28
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:2143
double distance
Definition: measures.h:24
int lw_dist2d_pt_pt(const POINT2D *thep1, const POINT2D *thep2, DISTPTS *dl)
Compares incomming points and stores the points closest to each other or most far away from each othe...
Definition: measures.c:2265
int pnr
Definition: measures.h:35

Here is the call graph for this function:

Here is the caller graph for this function: