PostGIS  2.5.7dev-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 2073 of file measures.c.

2074 {
2075  const POINT2D *p1, *p2, *p3, *p4, *p01, *p02;
2076  int pnr1,pnr2,pnr3,pnr4, n1, n2, i, u, r, twist;
2077  double maxmeasure;
2078  n1= l1->npoints;
2079  n2 = l2->npoints;
2080 
2081  LWDEBUG(2, "lw_dist2d_pre_seg_seg is called");
2082 
2083  p1 = getPoint2d_cp(l1, list1[0].pnr);
2084  p3 = getPoint2d_cp(l2, list2[0].pnr);
2085  lw_dist2d_pt_pt(p1, p3, dl);
2086  maxmeasure = sqrt(dl->distance*dl->distance + (dl->distance*dl->distance*k*k));
2087  twist = dl->twisted; /*to keep the incoming order between iterations*/
2088  for (i =(n1-1); i>=0; --i)
2089  {
2090  /*we break this iteration when we have checked every
2091  point closer to our perpendicular "checkline" than
2092  our shortest found distance*/
2093  if (((list2[0].themeasure-list1[i].themeasure)) > maxmeasure) break;
2094  for (r=-1; r<=1; r +=2) /*because we are not iterating in the original point order we have to check the segment before and after every point*/
2095  {
2096  pnr1 = list1[i].pnr;
2097  p1 = getPoint2d_cp(l1, pnr1);
2098  if (pnr1+r<0)
2099  {
2100  p01 = getPoint2d_cp(l1, (n1-1));
2101  if (( p1->x == p01->x) && (p1->y == p01->y)) pnr2 = (n1-1);
2102  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*/
2103  }
2104 
2105  else if (pnr1+r>(n1-1))
2106  {
2107  p01 = getPoint2d_cp(l1, 0);
2108  if (( p1->x == p01->x) && (p1->y == p01->y)) pnr2 = 0;
2109  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*/
2110  }
2111  else pnr2 = pnr1+r;
2112 
2113 
2114  p2 = getPoint2d_cp(l1, pnr2);
2115  for (u=0; u<n2; ++u)
2116  {
2117  if (((list2[u].themeasure-list1[i].themeasure)) >= maxmeasure) break;
2118  pnr3 = list2[u].pnr;
2119  p3 = getPoint2d_cp(l2, pnr3);
2120  if (pnr3==0)
2121  {
2122  p02 = getPoint2d_cp(l2, (n2-1));
2123  if (( p3->x == p02->x) && (p3->y == p02->y)) pnr4 = (n2-1);
2124  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*/
2125  }
2126  else pnr4 = pnr3-1;
2127 
2128  p4 = getPoint2d_cp(l2, pnr4);
2129  dl->twisted=twist;
2130  if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl)) return LW_FALSE;
2131 
2132  if (pnr3>=(n2-1))
2133  {
2134  p02 = getPoint2d_cp(l2, 0);
2135  if (( p3->x == p02->x) && (p3->y == p02->y)) pnr4 = 0;
2136  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*/
2137  }
2138 
2139  else pnr4 = pnr3+1;
2140 
2141  p4 = getPoint2d_cp(l2, pnr4);
2142  dl->twisted=twist; /*we reset the "twist" for each iteration*/
2143  if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl)) return LW_FALSE;
2144 
2145  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*/
2146  }
2147  }
2148  }
2149 
2150  return LW_TRUE;
2151 }
char * r
Definition: cu_in_wkt.c:24
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
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
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
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:2160
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
int twisted
Definition: measures.h:55
double distance
Definition: measures.h:51
int pnr
Definition: measures.h:62
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
uint32_t npoints
Definition: liblwgeom.h:374

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: