PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 2159 of file measures.c.

2160{
2161 const POINT2D *p1, *p2, *p3, *p4, *p01, *p02;
2162 int pnr1, pnr2, pnr3, pnr4, n1, n2, i, u, r, twist;
2163 double maxmeasure;
2164 n1 = l1->npoints;
2165 n2 = l2->npoints;
2166
2167 LWDEBUG(2, "lw_dist2d_pre_seg_seg is called");
2168
2169 p1 = getPoint2d_cp(l1, list1[0].pnr);
2170 p3 = getPoint2d_cp(l2, list2[0].pnr);
2171 lw_dist2d_pt_pt(p1, p3, dl);
2172 maxmeasure = sqrt(dl->distance * dl->distance + (dl->distance * dl->distance * k * k));
2173 twist = dl->twisted; /*to keep the incoming order between iterations*/
2174 for (i = (n1 - 1); i >= 0; --i)
2175 {
2176 /*we break this iteration when we have checked every point closer to our perpendicular "checkline" than
2177 * our shortest found distance*/
2178 if (((list2[0].themeasure - list1[i].themeasure)) > maxmeasure)
2179 break;
2180 /*because we are not iterating in the original point order we have to check the segment before and after
2181 * every point*/
2182 for (r = -1; r <= 1; r += 2)
2183 {
2184 pnr1 = list1[i].pnr;
2185 p1 = getPoint2d_cp(l1, pnr1);
2186 if (pnr1 + r < 0)
2187 {
2188 p01 = getPoint2d_cp(l1, (n1 - 1));
2189 if ((p1->x == p01->x) && (p1->y == p01->y))
2190 pnr2 = (n1 - 1);
2191 else
2192 pnr2 = pnr1; /* if it is a line and the last and first point is not the same we
2193 avoid the edge between start and end this way*/
2194 }
2195
2196 else if (pnr1 + r > (n1 - 1))
2197 {
2198 p01 = getPoint2d_cp(l1, 0);
2199 if ((p1->x == p01->x) && (p1->y == p01->y))
2200 pnr2 = 0;
2201 else
2202 pnr2 = pnr1; /* if it is a line and the last and first point is not the same we
2203 avoid the edge between start and end this way*/
2204 }
2205 else
2206 pnr2 = pnr1 + r;
2207
2208 p2 = getPoint2d_cp(l1, pnr2);
2209 for (u = 0; u < n2; ++u)
2210 {
2211 if (((list2[u].themeasure - list1[i].themeasure)) >= maxmeasure)
2212 break;
2213 pnr3 = list2[u].pnr;
2214 p3 = getPoint2d_cp(l2, pnr3);
2215 if (pnr3 == 0)
2216 {
2217 p02 = getPoint2d_cp(l2, (n2 - 1));
2218 if ((p3->x == p02->x) && (p3->y == p02->y))
2219 pnr4 = (n2 - 1);
2220 else
2221 pnr4 = pnr3; /* if it is a line and the last and first point is not the
2222 same we avoid the edge between start and end this way*/
2223 }
2224 else
2225 pnr4 = pnr3 - 1;
2226
2227 p4 = getPoint2d_cp(l2, pnr4);
2228 dl->twisted = twist;
2229 if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl))
2230 return LW_FALSE;
2231
2232 if (pnr3 >= (n2 - 1))
2233 {
2234 p02 = getPoint2d_cp(l2, 0);
2235 if ((p3->x == p02->x) && (p3->y == p02->y))
2236 pnr4 = 0;
2237 else
2238 pnr4 = pnr3; /* if it is a line and the last and first point is not the
2239 same we avoid the edge between start and end this way*/
2240 }
2241
2242 else
2243 pnr4 = pnr3 + 1;
2244
2245 p4 = getPoint2d_cp(l2, pnr4);
2246 dl->twisted = twist; /*we reset the "twist" for each iteration*/
2247 if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl))
2248 return LW_FALSE;
2249 /*here we "translate" the found mindistance so it can be compared to our "z"-values*/
2250 maxmeasure = sqrt(dl->distance * dl->distance + (dl->distance * dl->distance * k * k));
2251 }
2252 }
2253 }
2254
2255 return LW_TRUE;
2256}
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:91
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:2264
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:2365
int twisted
Definition measures.h:55
double distance
Definition measures.h:51
double y
Definition liblwgeom.h:376
double x
Definition liblwgeom.h:376
uint32_t npoints
Definition liblwgeom.h:413

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: