PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lw_segment_intersects()

static void test_lw_segment_intersects ( void  )
static

Definition at line 119 of file cu_algorithm.c.

References lw_segment_intersects(), SEG_COLINEAR, SEG_CROSS_LEFT, SEG_CROSS_RIGHT, SEG_NO_INTERSECTION, setpoint, POINT2D::x, and POINT2D::y.

Referenced by algorithms_suite_setup().

120 {
121 
122 #define setpoint(p, x1, y1) {(p).x = (x1); (p).y = (y1);}
123 
124  POINT2D p1, p2, q1, q2;
125 
126  /* P: Vertical line at x=0 */
127  setpoint(p1, 0.0, 0.0);
128  p1.x = 0.0;
129  p1.y = 0.0;
130  p2.x = 0.0;
131  p2.y = 1.0;
132 
133  /* Q: Horizontal line crossing left to right */
134  q1.x = -0.5;
135  q1.y = 0.5;
136  q2.x = 0.5;
137  q2.y = 0.5;
138  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_CROSS_RIGHT );
139 
140  /* Q: Horizontal line crossing right to left */
141  q1.x = 0.5;
142  q1.y = 0.5;
143  q2.x = -0.5;
144  q2.y = 0.5;
145  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_CROSS_LEFT );
146 
147  /* Q: Horizontal line not crossing right to left */
148  q1.x = 0.5;
149  q1.y = 1.5;
150  q2.x = -0.5;
151  q2.y = 1.5;
152  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_NO_INTERSECTION );
153 
154  /* Q: Horizontal line crossing at second vertex right to left */
155  q1.x = 0.5;
156  q1.y = 1.0;
157  q2.x = -0.5;
158  q2.y = 1.0;
159  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_NO_INTERSECTION );
160 
161  /* Q: Horizontal line crossing at first vertex right to left */
162  q1.x = 0.5;
163  q1.y = 0.0;
164  q2.x = -0.5;
165  q2.y = 0.0;
166  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_CROSS_LEFT );
167 
168  /* Q: Diagonal line with large range crossing at first vertex right to left */
169  q1.x = 0.5;
170  q1.y = 10.0;
171  q2.x = -0.5;
172  q2.y = -10.0;
173  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_CROSS_LEFT );
174 
175  /* Q: Diagonal line with large range crossing at second vertex right to left */
176  q1.x = 0.5;
177  q1.y = 11.0;
178  q2.x = -0.5;
179  q2.y = -9.0;
180  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_NO_INTERSECTION );
181 
182  /* Q: Horizontal touching from left at second vertex*/
183  q1.x = -0.5;
184  q1.y = 0.5;
185  q2.x = 0.0;
186  q2.y = 0.5;
187  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_NO_INTERSECTION );
188 
189  /* Q: Horizontal touching from right at first vertex */
190  q1.x = 0.0;
191  q1.y = 0.5;
192  q2.x = 0.5;
193  q2.y = 0.5;
194  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_CROSS_RIGHT );
195 
196  /* Q: Horizontal touching from left and far below on second vertex */
197  q1.x = -0.5;
198  q1.y = -10.5;
199  q2.x = 0.0;
200  q2.y = 0.5;
201  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_NO_INTERSECTION );
202 
203  /* Q: Horizontal touching from right and far above on second vertex */
204  q1.x = 0.5;
205  q1.y = 10.5;
206  q2.x = 0.0;
207  q2.y = 0.5;
208  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_NO_INTERSECTION );
209 
210  /* Q: Co-linear from top */
211  q1.x = 0.0;
212  q1.y = 10.0;
213  q2.x = 0.0;
214  q2.y = 0.5;
215  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_COLINEAR );
216 
217  /* Q: Co-linear from bottom */
218  q1.x = 0.0;
219  q1.y = -10.0;
220  q2.x = 0.0;
221  q2.y = 0.5;
222  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_COLINEAR );
223 
224  /* Q: Co-linear contained */
225  q1.x = 0.0;
226  q1.y = 0.4;
227  q2.x = 0.0;
228  q2.y = 0.5;
229  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_COLINEAR );
230 
231  /* Q: Horizontal touching at end point from left */
232  q1.x = -0.5;
233  q1.y = 1.0;
234  q2.x = 0.0;
235  q2.y = 1.0;
236  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_NO_INTERSECTION );
237 
238  /* Q: Horizontal touching at end point from right */
239  q1.x = 0.0;
240  q1.y = 1.0;
241  q2.x = 0.0;
242  q2.y = 0.5;
243  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_COLINEAR );
244 
245  /* Q: Horizontal touching at start point from left */
246  q1.x = 0.0;
247  q1.y = 0.0;
248  q2.x = -0.5;
249  q2.y = 0.0;
250  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_CROSS_LEFT );
251 
252  /* Q: Horizontal touching at start point from right */
253  q1.x = 0.0;
254  q1.y = 0.0;
255  q2.x = 0.5;
256  q2.y = 0.0;
257  CU_ASSERT( lw_segment_intersects(&p1, &p2, &q1, &q2) == SEG_CROSS_RIGHT );
258 
259 }
double x
Definition: liblwgeom.h:328
double y
Definition: liblwgeom.h:328
#define setpoint(p, x1, y1)
int lw_segment_intersects(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2)
returns the kind of CG_SEGMENT_INTERSECTION_TYPE behavior of lineseg 1 (constructed from p1 and p2) a...
Definition: lwalgorithm.c:371
Here is the call graph for this function:
Here is the caller graph for this function: