PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@
cu_spatial_relationship.c
Go to the documentation of this file.
1 /*
2  * PostGIS Raster - Raster Types for PostGIS
3  * http://trac.osgeo.org/postgis/wiki/WKTRaster
4  *
5  * Copyright (C) 2012 Regents of the University of California
6  * <bkpark@ucdavis.edu>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #include "CUnit/Basic.h"
25 #include "cu_tester.h"
26 
28  rt_raster rast1;
29  rt_raster rast2;
30  rt_band band1;
31  rt_band band2;
32  double nodata;
33  int rtn;
34  int result;
35 
36  /*
37  rast1
38 
39  (-1, -1)
40  +-+-+
41  |1|1|
42  +-+-+
43  |1|1|
44  +-+-+
45  (1, 1)
46  */
47  rast1 = rt_raster_new(2, 2);
48  CU_ASSERT(rast1 != NULL);
49  rt_raster_set_scale(rast1, 1, 1);
50  rt_raster_set_offsets(rast1, -1, -1);
51 
52  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
53  CU_ASSERT(band1 != NULL);
54  rt_band_set_nodata(band1, 0, NULL);
55  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
56  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
57  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
58  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
59 
60  rt_band_get_nodata(band1, &nodata);
61  CU_ASSERT_EQUAL(nodata, 0);
62 
63  rtn = rt_raster_overlaps(
64  rast1, 0,
65  rast1, 0,
66  &result
67  );
68  CU_ASSERT_EQUAL(rtn, ES_NONE);
69  CU_ASSERT_NOT_EQUAL(result, 1);
70 
71  /*
72  rast2
73 
74  (0, 0)
75  +-+-+
76  |1|1|
77  +-+-+
78  |1|1|
79  +-+-+
80  (2, 2)
81  */
82  rast2 = rt_raster_new(2, 2);
83  CU_ASSERT(rast2 != NULL);
84  rt_raster_set_scale(rast2, 1, 1);
85 
86  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
87  CU_ASSERT(band2 != NULL);
88  rt_band_set_nodata(band2, 0, NULL);
89  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
90  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
91  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
92  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
93 
94  rt_band_get_nodata(band2, &nodata);
95  CU_ASSERT_EQUAL(nodata, 0);
96 
97  rtn = rt_raster_overlaps(
98  rast1, 0,
99  rast2, 0,
100  &result
101  );
102  CU_ASSERT_EQUAL(rtn, ES_NONE);
103  CU_ASSERT_EQUAL(result, 1);
104 
105  rtn = rt_raster_overlaps(
106  rast1, -1,
107  rast2, -1,
108  &result
109  );
110  CU_ASSERT_EQUAL(rtn, ES_NONE);
111  CU_ASSERT_EQUAL(result, 1);
112 
113  /*
114  rast2
115 
116  (0, 0)
117  +-+-+
118  |0|1|
119  +-+-+
120  |1|1|
121  +-+-+
122  (2, 2)
123  */
124  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
125 
126  rtn = rt_raster_overlaps(
127  rast1, 0,
128  rast2, 0,
129  &result
130  );
131  CU_ASSERT_EQUAL(rtn, ES_NONE);
132  CU_ASSERT_NOT_EQUAL(result, 1);
133 
134  /*
135  rast2
136 
137  (0, 0)
138  +-+-+
139  |1|0|
140  +-+-+
141  |1|1|
142  +-+-+
143  (2, 2)
144  */
145  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
146  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
147 
148  rtn = rt_raster_overlaps(
149  rast1, 0,
150  rast2, 0,
151  &result
152  );
153  CU_ASSERT_EQUAL(rtn, ES_NONE);
154  CU_ASSERT_EQUAL(result, 1);
155 
156  /*
157  rast2
158 
159  (0, 0)
160  +-+-+
161  |0|0|
162  +-+-+
163  |0|1|
164  +-+-+
165  (2, 2)
166  */
167  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
168  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
169  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
170 
171  rtn = rt_raster_overlaps(
172  rast1, 0,
173  rast2, 0,
174  &result
175  );
176  CU_ASSERT_EQUAL(rtn, ES_NONE);
177  CU_ASSERT_NOT_EQUAL(result, 1);
178 
179  /*
180  rast2
181 
182  (0, 0)
183  +-+-+
184  |0|0|
185  +-+-+
186  |0|0|
187  +-+-+
188  (2, 2)
189  */
190  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
191  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
192  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
193  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
194 
195  rtn = rt_raster_overlaps(
196  rast1, 0,
197  rast2, 0,
198  &result
199  );
200  CU_ASSERT_EQUAL(rtn, ES_NONE);
201  CU_ASSERT_NOT_EQUAL(result, 1);
202 
203  /*
204  rast2
205 
206  (2, 0)
207  +-+-+
208  |1|1|
209  +-+-+
210  |1|1|
211  +-+-+
212  (4, 2)
213  */
214  rt_raster_set_offsets(rast2, 2, 0);
215 
216  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
217  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
218  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
219  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
220 
221  rtn = rt_raster_overlaps(
222  rast1, 0,
223  rast2, 0,
224  &result
225  );
226  CU_ASSERT_EQUAL(rtn, ES_NONE);
227  CU_ASSERT_NOT_EQUAL(result, 1);
228 
229  /*
230  rast2
231 
232  (0.1, 0.1)
233  +-+-+
234  |1|1|
235  +-+-+
236  |1|1|
237  +-+-+
238  (0.9, 0.9)
239  */
240  rt_raster_set_offsets(rast2, 0.1, 0.1);
241  rt_raster_set_scale(rast2, 0.4, 0.4);
242 
243  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
244  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
245  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
246  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
247 
248  rtn = rt_raster_overlaps(
249  rast1, 0,
250  rast2, 0,
251  &result
252  );
253  CU_ASSERT_EQUAL(rtn, ES_NONE);
254  CU_ASSERT_NOT_EQUAL(result, 1);
255 
256  /*
257  rast2
258 
259  (-0.1, 0.1)
260  +-+-+
261  |1|1|
262  +-+-+
263  |1|1|
264  +-+-+
265  (0.9, 0.9)
266  */
267  rt_raster_set_offsets(rast2, -0.1, 0.1);
268 
269  rtn = rt_raster_overlaps(
270  rast1, 0,
271  rast2, 0,
272  &result
273  );
274  CU_ASSERT_EQUAL(rtn, ES_NONE);
275  CU_ASSERT_NOT_EQUAL(result, 1);
276 
277  cu_free_raster(rast2);
278 
279  /*
280  rast2
281 
282  (0, 0)
283  +-+-+-+
284  |1|1|1|
285  +-+-+-+
286  |1|1|1|
287  +-+-+-+
288  |1|1|1|
289  +-+-+-+
290  (3, 3)
291  */
292  rast2 = rt_raster_new(3, 3);
293  CU_ASSERT(rast2 != NULL);
294  rt_raster_set_scale(rast2, 1, 1);
295 
296  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
297  CU_ASSERT(band2 != NULL);
298  rt_band_set_nodata(band2, 0, NULL);
299  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
300  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
301  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
302  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
303  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
304  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
305  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
306  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
307  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
308 
309  rt_band_get_nodata(band2, &nodata);
310  CU_ASSERT_EQUAL(nodata, 0);
311 
312  rtn = rt_raster_overlaps(
313  rast1, 0,
314  rast2, 0,
315  &result
316  );
317  CU_ASSERT_EQUAL(rtn, ES_NONE);
318  CU_ASSERT_EQUAL(result, 1);
319 
320  /*
321  rast2
322 
323  (-2, -2)
324  +-+-+-+
325  |1|1|1|
326  +-+-+-+
327  |1|1|1|
328  +-+-+-+
329  |1|1|1|
330  +-+-+-+
331  (1, 1)
332  */
333  rt_raster_set_offsets(rast2, -2, -2);
334 
335  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
336  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
337  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
338  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
339  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
340  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
341  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
342  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
343  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
344 
345  rtn = rt_raster_overlaps(
346  rast1, 0,
347  rast2, 0,
348  &result
349  );
350  CU_ASSERT_EQUAL(rtn, ES_NONE);
351  CU_ASSERT_NOT_EQUAL(result, 1);
352 
353  /*
354  rast2
355 
356  (-2, -2)
357  +-+-+-+
358  |0|1|1|
359  +-+-+-+
360  |1|0|1|
361  +-+-+-+
362  |1|1|0|
363  +-+-+-+
364  (1, 1)
365  */
366  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
367  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
368  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
369  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
370  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
371  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
372  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
373  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
374  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
375 
376  rtn = rt_raster_overlaps(
377  rast1, 0,
378  rast2, 0,
379  &result
380  );
381  CU_ASSERT_EQUAL(rtn, ES_NONE);
382  CU_ASSERT_EQUAL(result, 1);
383 
384  /*
385  rast2
386 
387  (-2, -2)
388  +-+-+-+
389  |0|1|1|
390  +-+-+-+
391  |1|0|0|
392  +-+-+-+
393  |1|0|0|
394  +-+-+-+
395  (1, 1)
396  */
397  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
398  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
399  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
400  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
401  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
402  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
403  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
404  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
405  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
406 
407  rtn = rt_raster_overlaps(
408  rast1, 0,
409  rast2, 0,
410  &result
411  );
412  CU_ASSERT_EQUAL(rtn, ES_NONE);
413  CU_ASSERT_NOT_EQUAL(result, 1);
414 
415  /*
416  rast2
417 
418  (-2, -2)
419  +-+-+-+
420  |0|1|0|
421  +-+-+-+
422  |1|0|0|
423  +-+-+-+
424  |0|0|0|
425  +-+-+-+
426  (1, 1)
427  */
428  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
429  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
430  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
431  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
432  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
433  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
434  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
435  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
436  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
437 
438  rtn = rt_raster_overlaps(
439  rast1, 0,
440  rast2, 0,
441  &result
442  );
443  CU_ASSERT_EQUAL(rtn, ES_NONE);
444  CU_ASSERT_NOT_EQUAL(result, 1);
445 
446  cu_free_raster(rast2);
447 
448  /* skew tests */
449  /* rast2 (skewed by -0.5, 0.5) */
450  rast2 = rt_raster_new(3, 3);
451  CU_ASSERT(rast2 != NULL);
452  rt_raster_set_scale(rast2, 1, 1);
453  rt_raster_set_skews(rast2, -0.5, 0.5);
454 
455  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
456  CU_ASSERT(band2 != NULL);
457  rt_band_set_nodata(band2, 0, NULL);
458  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
459  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
460  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
461  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
462  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
463  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
464  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
465  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
466  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
467 
468  rtn = rt_raster_overlaps(
469  rast1, 0,
470  rast2, 0,
471  &result
472  );
473  CU_ASSERT_EQUAL(rtn, ES_NONE);
474  CU_ASSERT_EQUAL(result, 1);
475 
476  /* rast2 (skewed by -1, 1) */
477  rt_raster_set_skews(rast2, -1, 1);
478 
479  rtn = rt_raster_overlaps(
480  rast1, 0,
481  rast2, 0,
482  &result
483  );
484  CU_ASSERT_EQUAL(rtn, ES_NONE);
485  CU_ASSERT_EQUAL(result, 1);
486 
487  /* rast2 (skewed by 1, -1) */
488  rt_raster_set_skews(rast2, 1, -1);
489 
490  rtn = rt_raster_overlaps(
491  rast1, 0,
492  rast2, 0,
493  &result
494  );
495  CU_ASSERT_EQUAL(rtn, ES_NONE);
496  CU_ASSERT_EQUAL(result, 1);
497 
498  cu_free_raster(rast2);
499  cu_free_raster(rast1);
500 }
501 
503  rt_raster rast1;
504  rt_raster rast2;
505  rt_band band1;
506  rt_band band2;
507  double nodata;
508  int rtn;
509  int result;
510 
511  /*
512  rast1
513 
514  (-1, -1)
515  +-+-+
516  |1|1|
517  +-+-+
518  |1|1|
519  +-+-+
520  (1, 1)
521  */
522  rast1 = rt_raster_new(2, 2);
523  CU_ASSERT(rast1 != NULL);
524  rt_raster_set_scale(rast1, 1, 1);
525  rt_raster_set_offsets(rast1, -1, -1);
526 
527  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
528  CU_ASSERT(band1 != NULL);
529  rt_band_set_nodata(band1, 0, NULL);
530  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
531  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
532  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
533  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
534 
535  rt_band_get_nodata(band1, &nodata);
536  CU_ASSERT_EQUAL(nodata, 0);
537 
538  rtn = rt_raster_touches(
539  rast1, 0,
540  rast1, 0,
541  &result
542  );
543  CU_ASSERT_EQUAL(rtn, ES_NONE);
544  CU_ASSERT_NOT_EQUAL(result, 1);
545 
546  /*
547  rast2
548 
549  (0, 0)
550  +-+-+
551  |1|1|
552  +-+-+
553  |1|1|
554  +-+-+
555  (2, 2)
556  */
557  rast2 = rt_raster_new(2, 2);
558  CU_ASSERT(rast2 != NULL);
559  rt_raster_set_scale(rast2, 1, 1);
560 
561  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
562  CU_ASSERT(band2 != NULL);
563  rt_band_set_nodata(band2, 0, NULL);
564  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
565  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
566  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
567  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
568 
569  rt_band_get_nodata(band2, &nodata);
570  CU_ASSERT_EQUAL(nodata, 0);
571 
572  rtn = rt_raster_touches(
573  rast1, 0,
574  rast2, 0,
575  &result
576  );
577  CU_ASSERT_EQUAL(rtn, ES_NONE);
578  CU_ASSERT_NOT_EQUAL(result, 1);
579 
580  rtn = rt_raster_touches(
581  rast1, -1,
582  rast2, -1,
583  &result
584  );
585  CU_ASSERT_EQUAL(rtn, ES_NONE);
586  CU_ASSERT_NOT_EQUAL(result, 1);
587 
588  /*
589  rast2
590 
591  (0, 0)
592  +-+-+
593  |0|1|
594  +-+-+
595  |1|1|
596  +-+-+
597  (2, 2)
598  */
599  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
600 
601  rtn = rt_raster_touches(
602  rast1, 0,
603  rast2, 0,
604  &result
605  );
606  CU_ASSERT_EQUAL(rtn, ES_NONE);
607  CU_ASSERT_EQUAL(result, 1);
608 
609  /*
610  rast2
611 
612  (0, 0)
613  +-+-+
614  |1|0|
615  +-+-+
616  |1|1|
617  +-+-+
618  (2, 2)
619  */
620  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
621  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
622 
623  rtn = rt_raster_touches(
624  rast1, 0,
625  rast2, 0,
626  &result
627  );
628  CU_ASSERT_EQUAL(rtn, ES_NONE);
629  CU_ASSERT_NOT_EQUAL(result, 1);
630 
631  /*
632  rast2
633 
634  (0, 0)
635  +-+-+
636  |0|0|
637  +-+-+
638  |0|1|
639  +-+-+
640  (2, 2)
641  */
642  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
643  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
644  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
645 
646  rtn = rt_raster_touches(
647  rast1, 0,
648  rast2, 0,
649  &result
650  );
651  CU_ASSERT_EQUAL(rtn, ES_NONE);
652  CU_ASSERT_EQUAL(result, 1);
653 
654  /*
655  rast2
656 
657  (0, 0)
658  +-+-+
659  |0|0|
660  +-+-+
661  |0|0|
662  +-+-+
663  (2, 2)
664  */
665  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
666  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
667  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
668  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
669 
670  rtn = rt_raster_touches(
671  rast1, 0,
672  rast2, 0,
673  &result
674  );
675  CU_ASSERT_EQUAL(rtn, ES_NONE);
676  CU_ASSERT_NOT_EQUAL(result, 1);
677 
678  /*
679  rast2
680 
681  (2, 0)
682  +-+-+
683  |1|1|
684  +-+-+
685  |1|1|
686  +-+-+
687  (4, 2)
688  */
689  rt_raster_set_offsets(rast2, 2, 0);
690 
691  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
692  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
693  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
694  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
695 
696  rtn = rt_raster_touches(
697  rast1, 0,
698  rast2, 0,
699  &result
700  );
701  CU_ASSERT_EQUAL(rtn, ES_NONE);
702  CU_ASSERT_NOT_EQUAL(result, 1);
703 
704  /*
705  rast2
706 
707  (0, 1)
708  +-+-+
709  |1|1|
710  +-+-+
711  |1|1|
712  +-+-+
713  (2, 3)
714  */
715  rt_raster_set_offsets(rast2, 0, 1);
716 
717  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
718  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
719  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
720  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
721 
722  rtn = rt_raster_touches(
723  rast1, 0,
724  rast2, 0,
725  &result
726  );
727  CU_ASSERT_EQUAL(rtn, ES_NONE);
728  CU_ASSERT_EQUAL(result, 1);
729 
730  /*
731  rast2
732 
733  (-1, 1)
734  +-+-+
735  |1|1|
736  +-+-+
737  |1|1|
738  +-+-+
739  (1, 3)
740  */
741  rt_raster_set_offsets(rast2, -1, 1);
742 
743  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
744  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
745  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
746  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
747 
748  rtn = rt_raster_touches(
749  rast1, 0,
750  rast2, 0,
751  &result
752  );
753  CU_ASSERT_EQUAL(rtn, ES_NONE);
754  CU_ASSERT_EQUAL(result, 1);
755 
756  /*
757  rast2
758 
759  (0.1, 0.1)
760  +-+-+
761  |1|1|
762  +-+-+
763  |1|1|
764  +-+-+
765  (0.9, 0.9)
766  */
767  rt_raster_set_offsets(rast2, 0.1, 0.1);
768  rt_raster_set_scale(rast2, 0.4, 0.4);
769 
770  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
771  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
772  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
773  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
774 
775  rtn = rt_raster_touches(
776  rast1, 0,
777  rast2, 0,
778  &result
779  );
780  CU_ASSERT_EQUAL(rtn, ES_NONE);
781  CU_ASSERT_NOT_EQUAL(result, 1);
782 
783  /*
784  rast2
785 
786  (-0.1, 0.1)
787  +-+-+
788  |1|1|
789  +-+-+
790  |1|1|
791  +-+-+
792  (0.9, 0.9)
793  */
794  rt_raster_set_offsets(rast2, -0.1, 0.1);
795 
796  rtn = rt_raster_touches(
797  rast1, 0,
798  rast2, 0,
799  &result
800  );
801  CU_ASSERT_EQUAL(rtn, ES_NONE);
802  CU_ASSERT_NOT_EQUAL(result, 1);
803 
804  cu_free_raster(rast2);
805 
806  /*
807  rast2
808 
809  (0, 0)
810  +-+-+-+
811  |1|1|1|
812  +-+-+-+
813  |1|1|1|
814  +-+-+-+
815  |1|1|1|
816  +-+-+-+
817  (3, 3)
818  */
819  rast2 = rt_raster_new(3, 3);
820  CU_ASSERT(rast2 != NULL);
821  rt_raster_set_scale(rast2, 1, 1);
822 
823  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
824  CU_ASSERT(band2 != NULL);
825  rt_band_set_nodata(band2, 0, NULL);
826  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
827  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
828  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
829  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
830  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
831  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
832  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
833  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
834  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
835 
836  rt_band_get_nodata(band2, &nodata);
837  CU_ASSERT_EQUAL(nodata, 0);
838 
839  rtn = rt_raster_touches(
840  rast1, 0,
841  rast2, 0,
842  &result
843  );
844  CU_ASSERT_EQUAL(rtn, ES_NONE);
845  CU_ASSERT_NOT_EQUAL(result, 1);
846 
847  /*
848  rast2
849 
850  (-2, -2)
851  +-+-+-+
852  |1|1|1|
853  +-+-+-+
854  |1|1|1|
855  +-+-+-+
856  |1|1|1|
857  +-+-+-+
858  (1, 1)
859  */
860  rt_raster_set_offsets(rast2, -2, -2);
861 
862  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
863  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
864  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
865  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
866  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
867  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
868  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
869  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
870  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
871 
872  rtn = rt_raster_touches(
873  rast1, 0,
874  rast2, 0,
875  &result
876  );
877  CU_ASSERT_EQUAL(rtn, ES_NONE);
878  CU_ASSERT_NOT_EQUAL(result, 1);
879 
880  /*
881  rast2
882 
883  (-2, -2)
884  +-+-+-+
885  |0|1|1|
886  +-+-+-+
887  |1|0|1|
888  +-+-+-+
889  |1|1|0|
890  +-+-+-+
891  (1, 1)
892  */
893  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
894  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
895  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
896  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
897  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
898  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
899  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
900  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
901  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
902 
903  rtn = rt_raster_touches(
904  rast1, 0,
905  rast2, 0,
906  &result
907  );
908  CU_ASSERT_EQUAL(rtn, ES_NONE);
909  CU_ASSERT_NOT_EQUAL(result, 1);
910 
911  /*
912  rast2
913 
914  (-2, -2)
915  +-+-+-+
916  |0|1|1|
917  +-+-+-+
918  |1|0|0|
919  +-+-+-+
920  |1|0|0|
921  +-+-+-+
922  (1, 1)
923  */
924  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
925  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
926  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
927  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
928  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
929  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
930  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
931  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
932  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
933 
934  rtn = rt_raster_touches(
935  rast1, 0,
936  rast2, 0,
937  &result
938  );
939  CU_ASSERT_EQUAL(rtn, ES_NONE);
940  CU_ASSERT_EQUAL(result, 1);
941 
942  /*
943  rast2
944 
945  (-2, -2)
946  +-+-+-+
947  |0|1|0|
948  +-+-+-+
949  |1|0|0|
950  +-+-+-+
951  |0|0|0|
952  +-+-+-+
953  (1, 1)
954  */
955  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
956  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
957  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
958  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
959  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
960  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
961  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
962  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
963  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
964 
965  rtn = rt_raster_touches(
966  rast1, 0,
967  rast2, 0,
968  &result
969  );
970  CU_ASSERT_EQUAL(rtn, ES_NONE);
971  CU_ASSERT_EQUAL(result, 1);
972 
973  cu_free_raster(rast2);
974 
975  /* skew tests */
976  /* rast2 (skewed by -0.5, 0.5) */
977  rast2 = rt_raster_new(3, 3);
978  CU_ASSERT(rast2 != NULL);
979  rt_raster_set_scale(rast2, 1, 1);
980  rt_raster_set_skews(rast2, -0.5, 0.5);
981 
982  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
983  CU_ASSERT(band2 != NULL);
984  rt_band_set_nodata(band2, 0, NULL);
985  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
986  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
987  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
988  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
989  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
990  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
991  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
992  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
993  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
994 
995  rtn = rt_raster_touches(
996  rast1, 0,
997  rast2, 0,
998  &result
999  );
1000  CU_ASSERT_EQUAL(rtn, ES_NONE);
1001  CU_ASSERT_NOT_EQUAL(result, 1);
1002 
1003  /* rast2 (skewed by -1, 1) */
1004  rt_raster_set_skews(rast2, -1, 1);
1005 
1006  rtn = rt_raster_touches(
1007  rast1, 0,
1008  rast2, 0,
1009  &result
1010  );
1011  CU_ASSERT_EQUAL(rtn, ES_NONE);
1012  CU_ASSERT_NOT_EQUAL(result, 1);
1013 
1014  /* rast2 (skewed by 1, -1) */
1015  rt_raster_set_skews(rast2, 1, -1);
1016 
1017  rtn = rt_raster_touches(
1018  rast1, 0,
1019  rast2, 0,
1020  &result
1021  );
1022  CU_ASSERT_EQUAL(rtn, ES_NONE);
1023  CU_ASSERT_NOT_EQUAL(result, 1);
1024 
1025  cu_free_raster(rast2);
1026  cu_free_raster(rast1);
1027 }
1028 
1030  rt_raster rast1;
1031  rt_raster rast2;
1032  rt_band band1;
1033  rt_band band2;
1034  double nodata;
1035  int rtn;
1036  int result;
1037 
1038  /*
1039  rast1
1040 
1041  (-1, -1)
1042  +-+-+
1043  |1|1|
1044  +-+-+
1045  |1|1|
1046  +-+-+
1047  (1, 1)
1048  */
1049  rast1 = rt_raster_new(2, 2);
1050  CU_ASSERT(rast1 != NULL);
1051  rt_raster_set_scale(rast1, 1, 1);
1052  rt_raster_set_offsets(rast1, -1, -1);
1053 
1054  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
1055  CU_ASSERT(band1 != NULL);
1056  rt_band_set_nodata(band1, 0, NULL);
1057  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
1058  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
1059  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
1060  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
1061 
1062  rt_band_get_nodata(band1, &nodata);
1063  CU_ASSERT_EQUAL(nodata, 0);
1064 
1065  rtn = rt_raster_contains(
1066  rast1, 0,
1067  rast1, 0,
1068  &result
1069  );
1070  CU_ASSERT_EQUAL(rtn, ES_NONE);
1071  CU_ASSERT_EQUAL(result, 1);
1072 
1073  /*
1074  rast2
1075 
1076  (0, 0)
1077  +-+-+
1078  |1|1|
1079  +-+-+
1080  |1|1|
1081  +-+-+
1082  (2, 2)
1083  */
1084  rast2 = rt_raster_new(2, 2);
1085  CU_ASSERT(rast2 != NULL);
1086  rt_raster_set_scale(rast2, 1, 1);
1087 
1088  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
1089  CU_ASSERT(band2 != NULL);
1090  rt_band_set_nodata(band2, 0, NULL);
1091  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1092  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1093  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1094  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1095 
1096  rt_band_get_nodata(band2, &nodata);
1097  CU_ASSERT_EQUAL(nodata, 0);
1098 
1099  rtn = rt_raster_contains(
1100  rast1, 0,
1101  rast2, 0,
1102  &result
1103  );
1104  CU_ASSERT_EQUAL(rtn, ES_NONE);
1105  CU_ASSERT_NOT_EQUAL(result, 1);
1106 
1107  rtn = rt_raster_contains(
1108  rast1, -1,
1109  rast2, -1,
1110  &result
1111  );
1112  CU_ASSERT_EQUAL(rtn, ES_NONE);
1113  CU_ASSERT_NOT_EQUAL(result, 1);
1114 
1115  /*
1116  rast2
1117 
1118  (0, 0)
1119  +-+-+
1120  |0|1|
1121  +-+-+
1122  |1|1|
1123  +-+-+
1124  (2, 2)
1125  */
1126  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1127 
1128  rtn = rt_raster_contains(
1129  rast1, 0,
1130  rast2, 0,
1131  &result
1132  );
1133  CU_ASSERT_EQUAL(rtn, ES_NONE);
1134  CU_ASSERT_NOT_EQUAL(result, 1);
1135 
1136  /*
1137  rast2
1138 
1139  (0, 0)
1140  +-+-+
1141  |1|0|
1142  +-+-+
1143  |1|1|
1144  +-+-+
1145  (2, 2)
1146  */
1147  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1148  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1149 
1150  rtn = rt_raster_contains(
1151  rast1, 0,
1152  rast2, 0,
1153  &result
1154  );
1155  CU_ASSERT_EQUAL(rtn, ES_NONE);
1156  CU_ASSERT_NOT_EQUAL(result, 1);
1157 
1158  /*
1159  rast2
1160 
1161  (0, 0)
1162  +-+-+
1163  |0|0|
1164  +-+-+
1165  |0|1|
1166  +-+-+
1167  (2, 2)
1168  */
1169  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1170  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1171  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
1172 
1173  rtn = rt_raster_contains(
1174  rast1, 0,
1175  rast2, 0,
1176  &result
1177  );
1178  CU_ASSERT_EQUAL(rtn, ES_NONE);
1179  CU_ASSERT_NOT_EQUAL(result, 1);
1180 
1181  /*
1182  rast2
1183 
1184  (0, 0)
1185  +-+-+
1186  |0|0|
1187  +-+-+
1188  |0|0|
1189  +-+-+
1190  (2, 2)
1191  */
1192  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1193  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1194  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
1195  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1196 
1197  rtn = rt_raster_contains(
1198  rast1, 0,
1199  rast2, 0,
1200  &result
1201  );
1202  CU_ASSERT_EQUAL(rtn, ES_NONE);
1203  CU_ASSERT_NOT_EQUAL(result, 1);
1204 
1205  /*
1206  rast2
1207 
1208  (2, 0)
1209  +-+-+
1210  |1|1|
1211  +-+-+
1212  |1|1|
1213  +-+-+
1214  (4, 2)
1215  */
1216  rt_raster_set_offsets(rast2, 2, 0);
1217 
1218  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1219  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1220  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1221  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1222 
1223  rtn = rt_raster_contains(
1224  rast1, 0,
1225  rast2, 0,
1226  &result
1227  );
1228  CU_ASSERT_EQUAL(rtn, ES_NONE);
1229  CU_ASSERT_NOT_EQUAL(result, 1);
1230 
1231  /*
1232  rast2
1233 
1234  (0, 1)
1235  +-+-+
1236  |1|1|
1237  +-+-+
1238  |1|1|
1239  +-+-+
1240  (2, 3)
1241  */
1242  rt_raster_set_offsets(rast2, 0, 1);
1243 
1244  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1245  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1246  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1247  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1248 
1249  rtn = rt_raster_contains(
1250  rast1, 0,
1251  rast2, 0,
1252  &result
1253  );
1254  CU_ASSERT_EQUAL(rtn, ES_NONE);
1255  CU_ASSERT_NOT_EQUAL(result, 1);
1256 
1257  /*
1258  rast2
1259 
1260  (-1, 1)
1261  +-+-+
1262  |1|1|
1263  +-+-+
1264  |1|1|
1265  +-+-+
1266  (1, 3)
1267  */
1268  rt_raster_set_offsets(rast2, -1, 1);
1269 
1270  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1271  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1272  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1273  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1274 
1275  rtn = rt_raster_contains(
1276  rast1, 0,
1277  rast2, 0,
1278  &result
1279  );
1280  CU_ASSERT_EQUAL(rtn, ES_NONE);
1281  CU_ASSERT_NOT_EQUAL(result, 1);
1282 
1283  /*
1284  rast2
1285 
1286  (0.1, 0.1)
1287  +-+-+
1288  |1|1|
1289  +-+-+
1290  |1|1|
1291  +-+-+
1292  (0.9, 0.9)
1293  */
1294  rt_raster_set_offsets(rast2, 0.1, 0.1);
1295  rt_raster_set_scale(rast2, 0.4, 0.4);
1296 
1297  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1298  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1299  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1300  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1301 
1302  rtn = rt_raster_contains(
1303  rast1, 0,
1304  rast2, 0,
1305  &result
1306  );
1307  CU_ASSERT_EQUAL(rtn, ES_NONE);
1308  CU_ASSERT_EQUAL(result, 1);
1309 
1310  /*
1311  rast2
1312 
1313  (-0.1, 0.1)
1314  +-+-+
1315  |1|1|
1316  +-+-+
1317  |1|1|
1318  +-+-+
1319  (0.9, 0.9)
1320  */
1321  rt_raster_set_offsets(rast2, -0.1, 0.1);
1322 
1323  rtn = rt_raster_contains(
1324  rast1, 0,
1325  rast2, 0,
1326  &result
1327  );
1328  CU_ASSERT_EQUAL(rtn, ES_NONE);
1329  CU_ASSERT_EQUAL(result, 1);
1330 
1331  cu_free_raster(rast2);
1332 
1333  /*
1334  rast2
1335 
1336  (0, 0)
1337  +-+-+-+
1338  |1|1|1|
1339  +-+-+-+
1340  |1|1|1|
1341  +-+-+-+
1342  |1|1|1|
1343  +-+-+-+
1344  (3, 3)
1345  */
1346  rast2 = rt_raster_new(3, 3);
1347  CU_ASSERT(rast2 != NULL);
1348  rt_raster_set_scale(rast2, 1, 1);
1349 
1350  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
1351  CU_ASSERT(band2 != NULL);
1352  rt_band_set_nodata(band2, 0, NULL);
1353  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1354  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1355  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1356  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1357  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1358  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1359  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1360  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1361  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
1362 
1363  rt_band_get_nodata(band2, &nodata);
1364  CU_ASSERT_EQUAL(nodata, 0);
1365 
1366  rtn = rt_raster_contains(
1367  rast1, 0,
1368  rast2, 0,
1369  &result
1370  );
1371  CU_ASSERT_EQUAL(rtn, ES_NONE);
1372  CU_ASSERT_NOT_EQUAL(result, 1);
1373 
1374  /*
1375  rast2
1376 
1377  (-2, -2)
1378  +-+-+-+
1379  |1|1|1|
1380  +-+-+-+
1381  |1|1|1|
1382  +-+-+-+
1383  |1|1|1|
1384  +-+-+-+
1385  (1, 1)
1386  */
1387  rt_raster_set_offsets(rast2, -2, -2);
1388 
1389  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1390  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1391  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1392  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1393  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1394  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1395  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1396  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1397  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
1398 
1399  rtn = rt_raster_contains(
1400  rast1, 0,
1401  rast2, 0,
1402  &result
1403  );
1404  CU_ASSERT_EQUAL(rtn, ES_NONE);
1405  CU_ASSERT_NOT_EQUAL(result, 1);
1406 
1407  /*
1408  rast2
1409 
1410  (-2, -2)
1411  +-+-+-+
1412  |0|1|1|
1413  +-+-+-+
1414  |1|0|1|
1415  +-+-+-+
1416  |1|1|0|
1417  +-+-+-+
1418  (1, 1)
1419  */
1420  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1421  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1422  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1423  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1424  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1425  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1426  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1427  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1428  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
1429 
1430  rtn = rt_raster_contains(
1431  rast1, 0,
1432  rast2, 0,
1433  &result
1434  );
1435  CU_ASSERT_EQUAL(rtn, ES_NONE);
1436  CU_ASSERT_NOT_EQUAL(result, 1);
1437 
1438  /*
1439  rast2
1440 
1441  (-2, -2)
1442  +-+-+-+
1443  |0|1|1|
1444  +-+-+-+
1445  |1|0|0|
1446  +-+-+-+
1447  |1|0|0|
1448  +-+-+-+
1449  (1, 1)
1450  */
1451  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1452  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1453  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1454  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1455  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1456  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
1457  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1458  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
1459  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
1460 
1461  rtn = rt_raster_contains(
1462  rast1, 0,
1463  rast2, 0,
1464  &result
1465  );
1466  CU_ASSERT_EQUAL(rtn, ES_NONE);
1467  CU_ASSERT_NOT_EQUAL(result, 1);
1468 
1469  /*
1470  rast2
1471 
1472  (-2, -2)
1473  +-+-+-+
1474  |0|1|0|
1475  +-+-+-+
1476  |1|0|0|
1477  +-+-+-+
1478  |0|0|0|
1479  +-+-+-+
1480  (1, 1)
1481  */
1482  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1483  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1484  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
1485  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1486  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1487  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
1488  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
1489  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
1490  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
1491 
1492  rtn = rt_raster_contains(
1493  rast1, 0,
1494  rast2, 0,
1495  &result
1496  );
1497  CU_ASSERT_EQUAL(rtn, ES_NONE);
1498  CU_ASSERT_NOT_EQUAL(result, 1);
1499 
1500  cu_free_raster(rast2);
1501 
1502  /* skew tests */
1503  /* rast2 (skewed by -0.5, 0.5) */
1504  rast2 = rt_raster_new(3, 3);
1505  CU_ASSERT(rast2 != NULL);
1506  rt_raster_set_scale(rast2, 1, 1);
1507  rt_raster_set_skews(rast2, -0.5, 0.5);
1508 
1509  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
1510  CU_ASSERT(band2 != NULL);
1511  rt_band_set_nodata(band2, 0, NULL);
1512  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1513  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
1514  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
1515  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1516  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
1517  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
1518  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1519  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
1520  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
1521 
1522  rtn = rt_raster_contains(
1523  rast1, 0,
1524  rast2, 0,
1525  &result
1526  );
1527  CU_ASSERT_EQUAL(rtn, ES_NONE);
1528  CU_ASSERT_NOT_EQUAL(result, 1);
1529 
1530  /* rast2 (skewed by -1, 1) */
1531  rt_raster_set_skews(rast2, -1, 1);
1532 
1533  rtn = rt_raster_contains(
1534  rast1, 0,
1535  rast2, 0,
1536  &result
1537  );
1538  CU_ASSERT_EQUAL(rtn, ES_NONE);
1539  CU_ASSERT_NOT_EQUAL(result, 1);
1540 
1541  /* rast2 (skewed by 1, -1) */
1542  rt_raster_set_skews(rast2, 1, -1);
1543 
1544  rtn = rt_raster_contains(
1545  rast1, 0,
1546  rast2, 0,
1547  &result
1548  );
1549  CU_ASSERT_EQUAL(rtn, ES_NONE);
1550  CU_ASSERT_NOT_EQUAL(result, 1);
1551 
1552  cu_free_raster(rast2);
1553  cu_free_raster(rast1);
1554 }
1555 
1557  rt_raster rast1;
1558  rt_raster rast2;
1559  rt_band band1;
1560  rt_band band2;
1561  double nodata;
1562  int rtn;
1563  int result;
1564 
1565  /*
1566  rast1
1567 
1568  (-1, -1)
1569  +-+-+
1570  |1|1|
1571  +-+-+
1572  |1|1|
1573  +-+-+
1574  (1, 1)
1575  */
1576  rast1 = rt_raster_new(2, 2);
1577  CU_ASSERT(rast1 != NULL);
1578  rt_raster_set_scale(rast1, 1, 1);
1579  rt_raster_set_offsets(rast1, -1, -1);
1580 
1581  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
1582  CU_ASSERT(band1 != NULL);
1583  rt_band_set_nodata(band1, 0, NULL);
1584  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
1585  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
1586  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
1587  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
1588 
1589  rt_band_get_nodata(band1, &nodata);
1590  CU_ASSERT_EQUAL(nodata, 0);
1591 
1593  rast1, 0,
1594  rast1, 0,
1595  &result
1596  );
1597  CU_ASSERT_EQUAL(rtn, ES_NONE);
1598  CU_ASSERT_NOT_EQUAL(result, 1);
1599 
1600  /*
1601  rast2
1602 
1603  (0, 0)
1604  +-+-+
1605  |1|1|
1606  +-+-+
1607  |1|1|
1608  +-+-+
1609  (2, 2)
1610  */
1611  rast2 = rt_raster_new(2, 2);
1612  CU_ASSERT(rast2 != NULL);
1613  rt_raster_set_scale(rast2, 1, 1);
1614 
1615  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
1616  CU_ASSERT(band2 != NULL);
1617  rt_band_set_nodata(band2, 0, NULL);
1618  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1619  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1620  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1621  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1622 
1623  rt_band_get_nodata(band2, &nodata);
1624  CU_ASSERT_EQUAL(nodata, 0);
1625 
1627  rast1, 0,
1628  rast2, 0,
1629  &result
1630  );
1631  CU_ASSERT_EQUAL(rtn, ES_NONE);
1632  CU_ASSERT_NOT_EQUAL(result, 1);
1633 
1635  rast1, -1,
1636  rast2, -1,
1637  &result
1638  );
1639  CU_ASSERT_EQUAL(rtn, ES_NONE);
1640  CU_ASSERT_NOT_EQUAL(result, 1);
1641 
1642  /*
1643  rast2
1644 
1645  (0, 0)
1646  +-+-+
1647  |0|1|
1648  +-+-+
1649  |1|1|
1650  +-+-+
1651  (2, 2)
1652  */
1653  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1654 
1656  rast1, 0,
1657  rast2, 0,
1658  &result
1659  );
1660  CU_ASSERT_EQUAL(rtn, ES_NONE);
1661  CU_ASSERT_NOT_EQUAL(result, 1);
1662 
1663  /*
1664  rast2
1665 
1666  (0, 0)
1667  +-+-+
1668  |1|0|
1669  +-+-+
1670  |1|1|
1671  +-+-+
1672  (2, 2)
1673  */
1674  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1675  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1676 
1678  rast1, 0,
1679  rast2, 0,
1680  &result
1681  );
1682  CU_ASSERT_EQUAL(rtn, ES_NONE);
1683  CU_ASSERT_NOT_EQUAL(result, 1);
1684 
1685  /*
1686  rast2
1687 
1688  (0, 0)
1689  +-+-+
1690  |0|0|
1691  +-+-+
1692  |0|1|
1693  +-+-+
1694  (2, 2)
1695  */
1696  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1697  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1698  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
1699 
1701  rast1, 0,
1702  rast2, 0,
1703  &result
1704  );
1705  CU_ASSERT_EQUAL(rtn, ES_NONE);
1706  CU_ASSERT_NOT_EQUAL(result, 1);
1707 
1708  /*
1709  rast2
1710 
1711  (0, 0)
1712  +-+-+
1713  |0|0|
1714  +-+-+
1715  |0|0|
1716  +-+-+
1717  (2, 2)
1718  */
1719  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1720  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1721  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
1722  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1723 
1725  rast1, 0,
1726  rast2, 0,
1727  &result
1728  );
1729  CU_ASSERT_EQUAL(rtn, ES_NONE);
1730  CU_ASSERT_NOT_EQUAL(result, 1);
1731 
1732  /*
1733  rast2
1734 
1735  (2, 0)
1736  +-+-+
1737  |1|1|
1738  +-+-+
1739  |1|1|
1740  +-+-+
1741  (4, 2)
1742  */
1743  rt_raster_set_offsets(rast2, 2, 0);
1744 
1745  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1746  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1747  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1748  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1749 
1751  rast1, 0,
1752  rast2, 0,
1753  &result
1754  );
1755  CU_ASSERT_EQUAL(rtn, ES_NONE);
1756  CU_ASSERT_NOT_EQUAL(result, 1);
1757 
1758  /*
1759  rast2
1760 
1761  (0, 1)
1762  +-+-+
1763  |1|1|
1764  +-+-+
1765  |1|1|
1766  +-+-+
1767  (2, 3)
1768  */
1769  rt_raster_set_offsets(rast2, 0, 1);
1770 
1771  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1772  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1773  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1774  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1775 
1777  rast1, 0,
1778  rast2, 0,
1779  &result
1780  );
1781  CU_ASSERT_EQUAL(rtn, ES_NONE);
1782  CU_ASSERT_NOT_EQUAL(result, 1);
1783 
1784  /*
1785  rast2
1786 
1787  (-1, 1)
1788  +-+-+
1789  |1|1|
1790  +-+-+
1791  |1|1|
1792  +-+-+
1793  (1, 3)
1794  */
1795  rt_raster_set_offsets(rast2, -1, 1);
1796 
1797  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1798  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1799  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1800  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1801 
1803  rast1, 0,
1804  rast2, 0,
1805  &result
1806  );
1807  CU_ASSERT_EQUAL(rtn, ES_NONE);
1808  CU_ASSERT_NOT_EQUAL(result, 1);
1809 
1810  /*
1811  rast2
1812 
1813  (0.1, 0.1)
1814  +-+-+
1815  |1|1|
1816  +-+-+
1817  |1|1|
1818  +-+-+
1819  (0.9, 0.9)
1820  */
1821  rt_raster_set_offsets(rast2, 0.1, 0.1);
1822  rt_raster_set_scale(rast2, 0.4, 0.4);
1823 
1824  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1825  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1826  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1827  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1828 
1830  rast1, 0,
1831  rast2, 0,
1832  &result
1833  );
1834  CU_ASSERT_EQUAL(rtn, ES_NONE);
1835  CU_ASSERT_EQUAL(result, 1);
1836 
1837  /*
1838  rast2
1839 
1840  (-0.1, 0.1)
1841  +-+-+
1842  |1|1|
1843  +-+-+
1844  |1|1|
1845  +-+-+
1846  (0.9, 0.9)
1847  */
1848  rt_raster_set_offsets(rast2, -0.1, 0.1);
1849 
1851  rast1, 0,
1852  rast2, 0,
1853  &result
1854  );
1855  CU_ASSERT_EQUAL(rtn, ES_NONE);
1856  CU_ASSERT_EQUAL(result, 1);
1857 
1858  cu_free_raster(rast2);
1859 
1860  /*
1861  rast2
1862 
1863  (0, 0)
1864  +-+-+-+
1865  |1|1|1|
1866  +-+-+-+
1867  |1|1|1|
1868  +-+-+-+
1869  |1|1|1|
1870  +-+-+-+
1871  (3, 3)
1872  */
1873  rast2 = rt_raster_new(3, 3);
1874  CU_ASSERT(rast2 != NULL);
1875  rt_raster_set_scale(rast2, 1, 1);
1876 
1877  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
1878  CU_ASSERT(band2 != NULL);
1879  rt_band_set_nodata(band2, 0, NULL);
1880  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1881  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1882  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1883  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1884  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1885  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1886  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1887  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1888  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
1889 
1890  rt_band_get_nodata(band2, &nodata);
1891  CU_ASSERT_EQUAL(nodata, 0);
1892 
1894  rast1, 0,
1895  rast2, 0,
1896  &result
1897  );
1898  CU_ASSERT_EQUAL(rtn, ES_NONE);
1899  CU_ASSERT_NOT_EQUAL(result, 1);
1900 
1901  /*
1902  rast2
1903 
1904  (-2, -2)
1905  +-+-+-+
1906  |1|1|1|
1907  +-+-+-+
1908  |1|1|1|
1909  +-+-+-+
1910  |1|1|1|
1911  +-+-+-+
1912  (1, 1)
1913  */
1914  rt_raster_set_offsets(rast2, -2, -2);
1915 
1916  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1917  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1918  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1919  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1920  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1921  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1922  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1923  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1924  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
1925 
1927  rast1, 0,
1928  rast2, 0,
1929  &result
1930  );
1931  CU_ASSERT_EQUAL(rtn, ES_NONE);
1932  CU_ASSERT_NOT_EQUAL(result, 1);
1933 
1934  /*
1935  rast2
1936 
1937  (-2, -2)
1938  +-+-+-+
1939  |0|1|1|
1940  +-+-+-+
1941  |1|0|1|
1942  +-+-+-+
1943  |1|1|0|
1944  +-+-+-+
1945  (1, 1)
1946  */
1947  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1948  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1949  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1950  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1951  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1952  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1953  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1954  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1955  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
1956 
1958  rast1, 0,
1959  rast2, 0,
1960  &result
1961  );
1962  CU_ASSERT_EQUAL(rtn, ES_NONE);
1963  CU_ASSERT_NOT_EQUAL(result, 1);
1964 
1965  /*
1966  rast2
1967 
1968  (-2, -2)
1969  +-+-+-+
1970  |0|1|1|
1971  +-+-+-+
1972  |1|0|0|
1973  +-+-+-+
1974  |1|0|0|
1975  +-+-+-+
1976  (1, 1)
1977  */
1978  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1979  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1980  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1981  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1982  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1983  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
1984  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1985  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
1986  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
1987 
1989  rast1, 0,
1990  rast2, 0,
1991  &result
1992  );
1993  CU_ASSERT_EQUAL(rtn, ES_NONE);
1994  CU_ASSERT_NOT_EQUAL(result, 1);
1995 
1996  /*
1997  rast2
1998 
1999  (-2, -2)
2000  +-+-+-+
2001  |0|1|0|
2002  +-+-+-+
2003  |1|0|0|
2004  +-+-+-+
2005  |0|0|0|
2006  +-+-+-+
2007  (1, 1)
2008  */
2009  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2010  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2011  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
2012  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2013  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2014  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
2015  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
2016  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
2017  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
2018 
2020  rast1, 0,
2021  rast2, 0,
2022  &result
2023  );
2024  CU_ASSERT_EQUAL(rtn, ES_NONE);
2025  CU_ASSERT_NOT_EQUAL(result, 1);
2026 
2027  cu_free_raster(rast2);
2028 
2029  /* skew tests */
2030  /* rast2 (skewed by -0.5, 0.5) */
2031  rast2 = rt_raster_new(3, 3);
2032  CU_ASSERT(rast2 != NULL);
2033  rt_raster_set_scale(rast2, 1, 1);
2034  rt_raster_set_skews(rast2, -0.5, 0.5);
2035 
2036  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2037  CU_ASSERT(band2 != NULL);
2038  rt_band_set_nodata(band2, 0, NULL);
2039  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2040  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
2041  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
2042  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2043  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
2044  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
2045  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2046  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
2047  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
2048 
2050  rast1, 0,
2051  rast2, 0,
2052  &result
2053  );
2054  CU_ASSERT_EQUAL(rtn, ES_NONE);
2055  CU_ASSERT_NOT_EQUAL(result, 1);
2056 
2057  /* rast2 (skewed by -1, 1) */
2058  rt_raster_set_skews(rast2, -1, 1);
2059 
2061  rast1, 0,
2062  rast2, 0,
2063  &result
2064  );
2065  CU_ASSERT_EQUAL(rtn, ES_NONE);
2066  CU_ASSERT_NOT_EQUAL(result, 1);
2067 
2068  /* rast2 (skewed by 1, -1) */
2069  rt_raster_set_skews(rast2, 1, -1);
2070 
2072  rast1, 0,
2073  rast2, 0,
2074  &result
2075  );
2076  CU_ASSERT_EQUAL(rtn, ES_NONE);
2077  CU_ASSERT_NOT_EQUAL(result, 1);
2078 
2079  cu_free_raster(rast2);
2080  cu_free_raster(rast1);
2081 }
2082 
2084  rt_raster rast1;
2085  rt_raster rast2;
2086  rt_band band1;
2087  rt_band band2;
2088  double nodata;
2089  int rtn;
2090  int result;
2091 
2092  /*
2093  rast1
2094 
2095  (-1, -1)
2096  +-+-+
2097  |1|1|
2098  +-+-+
2099  |1|1|
2100  +-+-+
2101  (1, 1)
2102  */
2103  rast1 = rt_raster_new(2, 2);
2104  CU_ASSERT(rast1 != NULL);
2105  rt_raster_set_scale(rast1, 1, 1);
2106  rt_raster_set_offsets(rast1, -1, -1);
2107 
2108  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
2109  CU_ASSERT(band1 != NULL);
2110  rt_band_set_nodata(band1, 0, NULL);
2111  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
2112  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
2113  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
2114  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
2115 
2116  rt_band_get_nodata(band1, &nodata);
2117  CU_ASSERT_EQUAL(nodata, 0);
2118 
2119  rtn = rt_raster_covers(
2120  rast1, 0,
2121  rast1, 0,
2122  &result
2123  );
2124  CU_ASSERT_EQUAL(rtn, ES_NONE);
2125  CU_ASSERT_EQUAL(result, 1);
2126 
2127  /*
2128  rast2
2129 
2130  (0, 0)
2131  +-+-+
2132  |1|1|
2133  +-+-+
2134  |1|1|
2135  +-+-+
2136  (2, 2)
2137  */
2138  rast2 = rt_raster_new(2, 2);
2139  CU_ASSERT(rast2 != NULL);
2140  rt_raster_set_scale(rast2, 1, 1);
2141 
2142  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2143  CU_ASSERT(band2 != NULL);
2144  rt_band_set_nodata(band2, 0, NULL);
2145  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2146  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2147  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2148  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2149 
2150  rt_band_get_nodata(band2, &nodata);
2151  CU_ASSERT_EQUAL(nodata, 0);
2152 
2153  rtn = rt_raster_covers(
2154  rast1, 0,
2155  rast2, 0,
2156  &result
2157  );
2158  CU_ASSERT_EQUAL(rtn, ES_NONE);
2159  CU_ASSERT_NOT_EQUAL(result, 1);
2160 
2161  rtn = rt_raster_covers(
2162  rast1, -1,
2163  rast2, -1,
2164  &result
2165  );
2166  CU_ASSERT_EQUAL(rtn, ES_NONE);
2167  CU_ASSERT_NOT_EQUAL(result, 1);
2168 
2169  /*
2170  rast2
2171 
2172  (0, 0)
2173  +-+-+
2174  |0|1|
2175  +-+-+
2176  |1|1|
2177  +-+-+
2178  (2, 2)
2179  */
2180  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2181 
2182  rtn = rt_raster_covers(
2183  rast1, 0,
2184  rast2, 0,
2185  &result
2186  );
2187  CU_ASSERT_EQUAL(rtn, ES_NONE);
2188  CU_ASSERT_NOT_EQUAL(result, 1);
2189 
2190  /*
2191  rast2
2192 
2193  (0, 0)
2194  +-+-+
2195  |1|0|
2196  +-+-+
2197  |1|1|
2198  +-+-+
2199  (2, 2)
2200  */
2201  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2202  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2203 
2204  rtn = rt_raster_covers(
2205  rast1, 0,
2206  rast2, 0,
2207  &result
2208  );
2209  CU_ASSERT_EQUAL(rtn, ES_NONE);
2210  CU_ASSERT_NOT_EQUAL(result, 1);
2211 
2212  /*
2213  rast2
2214 
2215  (0, 0)
2216  +-+-+
2217  |0|0|
2218  +-+-+
2219  |0|1|
2220  +-+-+
2221  (2, 2)
2222  */
2223  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2224  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2225  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
2226 
2227  rtn = rt_raster_covers(
2228  rast1, 0,
2229  rast2, 0,
2230  &result
2231  );
2232  CU_ASSERT_EQUAL(rtn, ES_NONE);
2233  CU_ASSERT_NOT_EQUAL(result, 1);
2234 
2235  /*
2236  rast2
2237 
2238  (0, 0)
2239  +-+-+
2240  |0|0|
2241  +-+-+
2242  |0|0|
2243  +-+-+
2244  (2, 2)
2245  */
2246  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2247  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2248  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
2249  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2250 
2251  rtn = rt_raster_covers(
2252  rast1, 0,
2253  rast2, 0,
2254  &result
2255  );
2256  CU_ASSERT_EQUAL(rtn, ES_NONE);
2257  CU_ASSERT_NOT_EQUAL(result, 1);
2258 
2259  /*
2260  rast2
2261 
2262  (2, 0)
2263  +-+-+
2264  |1|1|
2265  +-+-+
2266  |1|1|
2267  +-+-+
2268  (4, 2)
2269  */
2270  rt_raster_set_offsets(rast2, 2, 0);
2271 
2272  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2273  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2274  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2275  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2276 
2277  rtn = rt_raster_covers(
2278  rast1, 0,
2279  rast2, 0,
2280  &result
2281  );
2282  CU_ASSERT_EQUAL(rtn, ES_NONE);
2283  CU_ASSERT_NOT_EQUAL(result, 1);
2284 
2285  /*
2286  rast2
2287 
2288  (0, 1)
2289  +-+-+
2290  |1|1|
2291  +-+-+
2292  |1|1|
2293  +-+-+
2294  (2, 3)
2295  */
2296  rt_raster_set_offsets(rast2, 0, 1);
2297 
2298  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2299  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2300  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2301  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2302 
2303  rtn = rt_raster_covers(
2304  rast1, 0,
2305  rast2, 0,
2306  &result
2307  );
2308  CU_ASSERT_EQUAL(rtn, ES_NONE);
2309  CU_ASSERT_NOT_EQUAL(result, 1);
2310 
2311  /*
2312  rast2
2313 
2314  (-1, 1)
2315  +-+-+
2316  |1|1|
2317  +-+-+
2318  |1|1|
2319  +-+-+
2320  (1, 3)
2321  */
2322  rt_raster_set_offsets(rast2, -1, 1);
2323 
2324  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2325  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2326  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2327  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2328 
2329  rtn = rt_raster_covers(
2330  rast1, 0,
2331  rast2, 0,
2332  &result
2333  );
2334  CU_ASSERT_EQUAL(rtn, ES_NONE);
2335  CU_ASSERT_NOT_EQUAL(result, 1);
2336 
2337  /*
2338  rast2
2339 
2340  (0.1, 0.1)
2341  +-+-+
2342  |1|1|
2343  +-+-+
2344  |1|1|
2345  +-+-+
2346  (0.9, 0.9)
2347  */
2348  rt_raster_set_offsets(rast2, 0.1, 0.1);
2349  rt_raster_set_scale(rast2, 0.4, 0.4);
2350 
2351  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2352  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2353  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2354  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2355 
2356  rtn = rt_raster_covers(
2357  rast1, 0,
2358  rast2, 0,
2359  &result
2360  );
2361  CU_ASSERT_EQUAL(rtn, ES_NONE);
2362  CU_ASSERT_EQUAL(result, 1);
2363 
2364  /*
2365  rast2
2366 
2367  (-0.1, 0.1)
2368  +-+-+
2369  |1|1|
2370  +-+-+
2371  |1|1|
2372  +-+-+
2373  (0.9, 0.9)
2374  */
2375  rt_raster_set_offsets(rast2, -0.1, 0.1);
2376 
2377  rtn = rt_raster_covers(
2378  rast1, 0,
2379  rast2, 0,
2380  &result
2381  );
2382  CU_ASSERT_EQUAL(rtn, ES_NONE);
2383  CU_ASSERT_EQUAL(result, 1);
2384 
2385  cu_free_raster(rast2);
2386 
2387  /*
2388  rast2
2389 
2390  (0, 0)
2391  +-+-+-+
2392  |1|1|1|
2393  +-+-+-+
2394  |1|1|1|
2395  +-+-+-+
2396  |1|1|1|
2397  +-+-+-+
2398  (3, 3)
2399  */
2400  rast2 = rt_raster_new(3, 3);
2401  CU_ASSERT(rast2 != NULL);
2402  rt_raster_set_scale(rast2, 1, 1);
2403 
2404  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2405  CU_ASSERT(band2 != NULL);
2406  rt_band_set_nodata(band2, 0, NULL);
2407  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2408  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2409  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2410  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2411  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2412  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2413  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2414  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2415  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
2416 
2417  rt_band_get_nodata(band2, &nodata);
2418  CU_ASSERT_EQUAL(nodata, 0);
2419 
2420  rtn = rt_raster_covers(
2421  rast1, 0,
2422  rast2, 0,
2423  &result
2424  );
2425  CU_ASSERT_EQUAL(rtn, ES_NONE);
2426  CU_ASSERT_NOT_EQUAL(result, 1);
2427 
2428  /*
2429  rast2
2430 
2431  (-2, -2)
2432  +-+-+-+
2433  |1|1|1|
2434  +-+-+-+
2435  |1|1|1|
2436  +-+-+-+
2437  |1|1|1|
2438  +-+-+-+
2439  (1, 1)
2440  */
2441  rt_raster_set_offsets(rast2, -2, -2);
2442 
2443  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2444  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2445  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2446  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2447  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2448  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2449  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2450  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2451  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
2452 
2453  rtn = rt_raster_covers(
2454  rast1, 0,
2455  rast2, 0,
2456  &result
2457  );
2458  CU_ASSERT_EQUAL(rtn, ES_NONE);
2459  CU_ASSERT_NOT_EQUAL(result, 1);
2460 
2461  /*
2462  rast2
2463 
2464  (-2, -2)
2465  +-+-+-+
2466  |0|1|1|
2467  +-+-+-+
2468  |1|0|1|
2469  +-+-+-+
2470  |1|1|0|
2471  +-+-+-+
2472  (1, 1)
2473  */
2474  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2475  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2476  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2477  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2478  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2479  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2480  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2481  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2482  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
2483 
2484  rtn = rt_raster_covers(
2485  rast1, 0,
2486  rast2, 0,
2487  &result
2488  );
2489  CU_ASSERT_EQUAL(rtn, ES_NONE);
2490  CU_ASSERT_NOT_EQUAL(result, 1);
2491 
2492  /*
2493  rast2
2494 
2495  (-2, -2)
2496  +-+-+-+
2497  |0|1|1|
2498  +-+-+-+
2499  |1|0|0|
2500  +-+-+-+
2501  |1|0|0|
2502  +-+-+-+
2503  (1, 1)
2504  */
2505  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2506  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2507  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2508  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2509  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2510  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
2511  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2512  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
2513  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
2514 
2515  rtn = rt_raster_covers(
2516  rast1, 0,
2517  rast2, 0,
2518  &result
2519  );
2520  CU_ASSERT_EQUAL(rtn, ES_NONE);
2521  CU_ASSERT_NOT_EQUAL(result, 1);
2522 
2523  /*
2524  rast2
2525 
2526  (-2, -2)
2527  +-+-+-+
2528  |0|1|0|
2529  +-+-+-+
2530  |1|0|0|
2531  +-+-+-+
2532  |0|0|0|
2533  +-+-+-+
2534  (1, 1)
2535  */
2536  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2537  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2538  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
2539  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2540  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2541  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
2542  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
2543  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
2544  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
2545 
2546  rtn = rt_raster_covers(
2547  rast1, 0,
2548  rast2, 0,
2549  &result
2550  );
2551  CU_ASSERT_EQUAL(rtn, ES_NONE);
2552  CU_ASSERT_NOT_EQUAL(result, 1);
2553 
2554  cu_free_raster(rast2);
2555 
2556  /* skew tests */
2557  /* rast2 (skewed by -0.5, 0.5) */
2558  rast2 = rt_raster_new(3, 3);
2559  CU_ASSERT(rast2 != NULL);
2560  rt_raster_set_scale(rast2, 1, 1);
2561  rt_raster_set_skews(rast2, -0.5, 0.5);
2562 
2563  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2564  CU_ASSERT(band2 != NULL);
2565  rt_band_set_nodata(band2, 0, NULL);
2566  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2567  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
2568  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
2569  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2570  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
2571  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
2572  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2573  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
2574  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
2575 
2576  rtn = rt_raster_covers(
2577  rast1, 0,
2578  rast2, 0,
2579  &result
2580  );
2581  CU_ASSERT_EQUAL(rtn, ES_NONE);
2582  CU_ASSERT_NOT_EQUAL(result, 1);
2583 
2584  /* rast2 (skewed by -1, 1) */
2585  rt_raster_set_skews(rast2, -1, 1);
2586 
2587  rtn = rt_raster_covers(
2588  rast1, 0,
2589  rast2, 0,
2590  &result
2591  );
2592  CU_ASSERT_EQUAL(rtn, ES_NONE);
2593  CU_ASSERT_NOT_EQUAL(result, 1);
2594 
2595  /* rast2 (skewed by 1, -1) */
2596  rt_raster_set_skews(rast2, 1, -1);
2597 
2598  rtn = rt_raster_covers(
2599  rast1, 0,
2600  rast2, 0,
2601  &result
2602  );
2603  CU_ASSERT_EQUAL(rtn, ES_NONE);
2604  CU_ASSERT_NOT_EQUAL(result, 1);
2605 
2606  cu_free_raster(rast2);
2607  cu_free_raster(rast1);
2608 }
2609 
2611  rt_raster rast1;
2612  rt_raster rast2;
2613  rt_band band1;
2614  rt_band band2;
2615  double nodata;
2616  int rtn;
2617  int result;
2618 
2619  /*
2620  rast1
2621 
2622  (-1, -1)
2623  +-+-+
2624  |1|1|
2625  +-+-+
2626  |1|1|
2627  +-+-+
2628  (1, 1)
2629  */
2630  rast1 = rt_raster_new(2, 2);
2631  CU_ASSERT(rast1 != NULL);
2632  rt_raster_set_scale(rast1, 1, 1);
2633  rt_raster_set_offsets(rast1, -1, -1);
2634 
2635  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
2636  CU_ASSERT(band1 != NULL);
2637  rt_band_set_nodata(band1, 0, NULL);
2638  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
2639  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
2640  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
2641  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
2642 
2643  rt_band_get_nodata(band1, &nodata);
2644  CU_ASSERT_EQUAL(nodata, 0);
2645 
2646  rtn = rt_raster_coveredby(
2647  rast1, 0,
2648  rast1, 0,
2649  &result
2650  );
2651  CU_ASSERT_EQUAL(rtn, ES_NONE);
2652  CU_ASSERT_EQUAL(result, 1);
2653 
2654  /*
2655  rast2
2656 
2657  (0, 0)
2658  +-+-+
2659  |1|1|
2660  +-+-+
2661  |1|1|
2662  +-+-+
2663  (2, 2)
2664  */
2665  rast2 = rt_raster_new(2, 2);
2666  CU_ASSERT(rast2 != NULL);
2667  rt_raster_set_scale(rast2, 1, 1);
2668 
2669  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2670  CU_ASSERT(band2 != NULL);
2671  rt_band_set_nodata(band2, 0, NULL);
2672  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2673  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2674  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2675  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2676 
2677  rt_band_get_nodata(band2, &nodata);
2678  CU_ASSERT_EQUAL(nodata, 0);
2679 
2680  rtn = rt_raster_coveredby(
2681  rast2, 0,
2682  rast1, 0,
2683  &result
2684  );
2685  CU_ASSERT_EQUAL(rtn, ES_NONE);
2686  CU_ASSERT_NOT_EQUAL(result, 1);
2687 
2688  rtn = rt_raster_coveredby(
2689  rast2, -1,
2690  rast1, -1,
2691  &result
2692  );
2693  CU_ASSERT_EQUAL(rtn, ES_NONE);
2694  CU_ASSERT_NOT_EQUAL(result, 1);
2695 
2696  /*
2697  rast2
2698 
2699  (0, 0)
2700  +-+-+
2701  |0|1|
2702  +-+-+
2703  |1|1|
2704  +-+-+
2705  (2, 2)
2706  */
2707  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2708 
2709  rtn = rt_raster_coveredby(
2710  rast2, 0,
2711  rast1, 0,
2712  &result
2713  );
2714  CU_ASSERT_EQUAL(rtn, ES_NONE);
2715  CU_ASSERT_NOT_EQUAL(result, 1);
2716 
2717  /*
2718  rast2
2719 
2720  (0, 0)
2721  +-+-+
2722  |1|0|
2723  +-+-+
2724  |1|1|
2725  +-+-+
2726  (2, 2)
2727  */
2728  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2729  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2730 
2731  rtn = rt_raster_coveredby(
2732  rast2, 0,
2733  rast1, 0,
2734  &result
2735  );
2736  CU_ASSERT_EQUAL(rtn, ES_NONE);
2737  CU_ASSERT_NOT_EQUAL(result, 1);
2738 
2739  /*
2740  rast2
2741 
2742  (0, 0)
2743  +-+-+
2744  |0|0|
2745  +-+-+
2746  |0|1|
2747  +-+-+
2748  (2, 2)
2749  */
2750  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2751  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2752  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
2753 
2754  rtn = rt_raster_coveredby(
2755  rast2, 0,
2756  rast1, 0,
2757  &result
2758  );
2759  CU_ASSERT_EQUAL(rtn, ES_NONE);
2760  CU_ASSERT_NOT_EQUAL(result, 1);
2761 
2762  /*
2763  rast2
2764 
2765  (0, 0)
2766  +-+-+
2767  |0|0|
2768  +-+-+
2769  |0|0|
2770  +-+-+
2771  (2, 2)
2772  */
2773  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2774  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2775  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
2776  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2777 
2778  rtn = rt_raster_coveredby(
2779  rast2, 0,
2780  rast1, 0,
2781  &result
2782  );
2783  CU_ASSERT_EQUAL(rtn, ES_NONE);
2784  CU_ASSERT_NOT_EQUAL(result, 1);
2785 
2786  /*
2787  rast2
2788 
2789  (2, 0)
2790  +-+-+
2791  |1|1|
2792  +-+-+
2793  |1|1|
2794  +-+-+
2795  (4, 2)
2796  */
2797  rt_raster_set_offsets(rast2, 2, 0);
2798 
2799  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2800  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2801  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2802  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2803 
2804  rtn = rt_raster_coveredby(
2805  rast2, 0,
2806  rast1, 0,
2807  &result
2808  );
2809  CU_ASSERT_EQUAL(rtn, ES_NONE);
2810  CU_ASSERT_NOT_EQUAL(result, 1);
2811 
2812  /*
2813  rast2
2814 
2815  (0, 1)
2816  +-+-+
2817  |1|1|
2818  +-+-+
2819  |1|1|
2820  +-+-+
2821  (2, 3)
2822  */
2823  rt_raster_set_offsets(rast2, 0, 1);
2824 
2825  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2826  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2827  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2828  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2829 
2830  rtn = rt_raster_coveredby(
2831  rast2, 0,
2832  rast1, 0,
2833  &result
2834  );
2835  CU_ASSERT_EQUAL(rtn, ES_NONE);
2836  CU_ASSERT_NOT_EQUAL(result, 1);
2837 
2838  /*
2839  rast2
2840 
2841  (-1, 1)
2842  +-+-+
2843  |1|1|
2844  +-+-+
2845  |1|1|
2846  +-+-+
2847  (1, 3)
2848  */
2849  rt_raster_set_offsets(rast2, -1, 1);
2850 
2851  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2852  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2853  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2854  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2855 
2856  rtn = rt_raster_coveredby(
2857  rast2, 0,
2858  rast1, 0,
2859  &result
2860  );
2861  CU_ASSERT_EQUAL(rtn, ES_NONE);
2862  CU_ASSERT_NOT_EQUAL(result, 1);
2863 
2864  /*
2865  rast2
2866 
2867  (0.1, 0.1)
2868  +-+-+
2869  |1|1|
2870  +-+-+
2871  |1|1|
2872  +-+-+
2873  (0.9, 0.9)
2874  */
2875  rt_raster_set_offsets(rast2, 0.1, 0.1);
2876  rt_raster_set_scale(rast2, 0.4, 0.4);
2877 
2878  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2879  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2880  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2881  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2882 
2883  rtn = rt_raster_coveredby(
2884  rast2, 0,
2885  rast1, 0,
2886  &result
2887  );
2888  CU_ASSERT_EQUAL(rtn, ES_NONE);
2889  CU_ASSERT_EQUAL(result, 1);
2890 
2891  /*
2892  rast2
2893 
2894  (-0.1, 0.1)
2895  +-+-+
2896  |1|1|
2897  +-+-+
2898  |1|1|
2899  +-+-+
2900  (0.9, 0.9)
2901  */
2902  rt_raster_set_offsets(rast2, -0.1, 0.1);
2903 
2904  rtn = rt_raster_coveredby(
2905  rast2, 0,
2906  rast1, 0,
2907  &result
2908  );
2909  CU_ASSERT_EQUAL(rtn, ES_NONE);
2910  CU_ASSERT_EQUAL(result, 1);
2911 
2912  cu_free_raster(rast2);
2913 
2914  /*
2915  rast2
2916 
2917  (0, 0)
2918  +-+-+-+
2919  |1|1|1|
2920  +-+-+-+
2921  |1|1|1|
2922  +-+-+-+
2923  |1|1|1|
2924  +-+-+-+
2925  (3, 3)
2926  */
2927  rast2 = rt_raster_new(3, 3);
2928  CU_ASSERT(rast2 != NULL);
2929  rt_raster_set_scale(rast2, 1, 1);
2930 
2931  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2932  CU_ASSERT(band2 != NULL);
2933  rt_band_set_nodata(band2, 0, NULL);
2934  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2935  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2936  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2937  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2938  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2939  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2940  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2941  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2942  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
2943 
2944  rt_band_get_nodata(band2, &nodata);
2945  CU_ASSERT_EQUAL(nodata, 0);
2946 
2947  rtn = rt_raster_coveredby(
2948  rast2, 0,
2949  rast1, 0,
2950  &result
2951  );
2952  CU_ASSERT_EQUAL(rtn, ES_NONE);
2953  CU_ASSERT_NOT_EQUAL(result, 1);
2954 
2955  /*
2956  rast2
2957 
2958  (-2, -2)
2959  +-+-+-+
2960  |1|1|1|
2961  +-+-+-+
2962  |1|1|1|
2963  +-+-+-+
2964  |1|1|1|
2965  +-+-+-+
2966  (1, 1)
2967  */
2968  rt_raster_set_offsets(rast2, -2, -2);
2969 
2970  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2971  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2972  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2973  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2974  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2975  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2976  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2977  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2978  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
2979 
2980  rtn = rt_raster_coveredby(
2981  rast2, 0,
2982  rast1, 0,
2983  &result
2984  );
2985  CU_ASSERT_EQUAL(rtn, ES_NONE);
2986  CU_ASSERT_NOT_EQUAL(result, 1);
2987 
2988  /*
2989  rast2
2990 
2991  (-2, -2)
2992  +-+-+-+
2993  |0|1|1|
2994  +-+-+-+
2995  |1|0|1|
2996  +-+-+-+
2997  |1|1|0|
2998  +-+-+-+
2999  (1, 1)
3000  */
3001  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3002  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3003  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3004  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3005  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3006  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3007  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3008  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3009  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3010 
3011  rtn = rt_raster_coveredby(
3012  rast2, 0,
3013  rast1, 0,
3014  &result
3015  );
3016  CU_ASSERT_EQUAL(rtn, ES_NONE);
3017  CU_ASSERT_NOT_EQUAL(result, 1);
3018 
3019  /*
3020  rast2
3021 
3022  (-2, -2)
3023  +-+-+-+
3024  |0|1|1|
3025  +-+-+-+
3026  |1|0|0|
3027  +-+-+-+
3028  |1|0|0|
3029  +-+-+-+
3030  (1, 1)
3031  */
3032  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3033  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3034  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3035  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3036  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3037  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
3038  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3039  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
3040  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3041 
3042  rtn = rt_raster_coveredby(
3043  rast2, 0,
3044  rast1, 0,
3045  &result
3046  );
3047  CU_ASSERT_EQUAL(rtn, ES_NONE);
3048  CU_ASSERT_NOT_EQUAL(result, 1);
3049 
3050  /*
3051  rast2
3052 
3053  (-2, -2)
3054  +-+-+-+
3055  |0|1|0|
3056  +-+-+-+
3057  |1|0|0|
3058  +-+-+-+
3059  |0|0|0|
3060  +-+-+-+
3061  (1, 1)
3062  */
3063  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3064  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3065  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
3066  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3067  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3068  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
3069  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
3070  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
3071  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3072 
3073  rtn = rt_raster_coveredby(
3074  rast2, 0,
3075  rast1, 0,
3076  &result
3077  );
3078  CU_ASSERT_EQUAL(rtn, ES_NONE);
3079  CU_ASSERT_NOT_EQUAL(result, 1);
3080 
3081  cu_free_raster(rast2);
3082 
3083  /* skew tests */
3084  /* rast2 (skewed by -0.5, 0.5) */
3085  rast2 = rt_raster_new(3, 3);
3086  CU_ASSERT(rast2 != NULL);
3087  rt_raster_set_scale(rast2, 1, 1);
3088  rt_raster_set_skews(rast2, -0.5, 0.5);
3089 
3090  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3091  CU_ASSERT(band2 != NULL);
3092  rt_band_set_nodata(band2, 0, NULL);
3093  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3094  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
3095  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
3096  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3097  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
3098  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
3099  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3100  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
3101  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
3102 
3103  rtn = rt_raster_coveredby(
3104  rast2, 0,
3105  rast1, 0,
3106  &result
3107  );
3108  CU_ASSERT_EQUAL(rtn, ES_NONE);
3109  CU_ASSERT_NOT_EQUAL(result, 1);
3110 
3111  /* rast2 (skewed by -1, 1) */
3112  rt_raster_set_skews(rast2, -1, 1);
3113 
3114  rtn = rt_raster_coveredby(
3115  rast2, 0,
3116  rast1, 0,
3117  &result
3118  );
3119  CU_ASSERT_EQUAL(rtn, ES_NONE);
3120  CU_ASSERT_NOT_EQUAL(result, 1);
3121 
3122  /* rast2 (skewed by 1, -1) */
3123  rt_raster_set_skews(rast2, 1, -1);
3124 
3125  rtn = rt_raster_coveredby(
3126  rast2, 0,
3127  rast1, 0,
3128  &result
3129  );
3130  CU_ASSERT_EQUAL(rtn, ES_NONE);
3131  CU_ASSERT_NOT_EQUAL(result, 1);
3132 
3133  cu_free_raster(rast2);
3134  cu_free_raster(rast1);
3135 }
3136 
3138  rt_raster rast1;
3139  rt_raster rast2;
3140  rt_band band1;
3141  rt_band band2;
3142  double nodata;
3143  int rtn;
3144  int result;
3145 
3146  /*
3147  rast1
3148 
3149  (-1, -1)
3150  +-+-+
3151  |1|1|
3152  +-+-+
3153  |1|1|
3154  +-+-+
3155  (1, 1)
3156  */
3157  rast1 = rt_raster_new(2, 2);
3158  CU_ASSERT(rast1 != NULL);
3159  rt_raster_set_scale(rast1, 1, 1);
3160  rt_raster_set_offsets(rast1, -1, -1);
3161 
3162  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
3163  CU_ASSERT(band1 != NULL);
3164  rt_band_set_nodata(band1, 0, NULL);
3165  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
3166  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
3167  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
3168  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
3169 
3170  rt_band_get_nodata(band1, &nodata);
3171  CU_ASSERT_EQUAL(nodata, 0);
3172 
3174  rast1, 0,
3175  rast1, 0,
3176  0.,
3177  &result
3178  );
3179  CU_ASSERT_EQUAL(rtn, ES_NONE);
3180  CU_ASSERT_EQUAL(result, 1);
3181 
3183  rast1, 0,
3184  rast1, 0,
3185  -1.,
3186  &result
3187  );
3188  CU_ASSERT_NOT_EQUAL(rtn, ES_NONE);
3189 
3190  /*
3191  rast2
3192 
3193  (0, 0)
3194  +-+-+
3195  |1|1|
3196  +-+-+
3197  |1|1|
3198  +-+-+
3199  (2, 2)
3200  */
3201  rast2 = rt_raster_new(2, 2);
3202  CU_ASSERT(rast2 != NULL);
3203  rt_raster_set_scale(rast2, 1, 1);
3204 
3205  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3206  CU_ASSERT(band2 != NULL);
3207  rt_band_set_nodata(band2, 0, NULL);
3208  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3209  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3210  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3211  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3212 
3213  rt_band_get_nodata(band2, &nodata);
3214  CU_ASSERT_EQUAL(nodata, 0);
3215 
3217  rast1, 0,
3218  rast2, 0,
3219  0.,
3220  &result
3221  );
3222  CU_ASSERT_EQUAL(rtn, ES_NONE);
3223  CU_ASSERT_EQUAL(result, 1);
3224 
3226  rast1, 0,
3227  rast2, 0,
3228  1.,
3229  &result
3230  );
3231  CU_ASSERT_EQUAL(rtn, ES_NONE);
3232  CU_ASSERT_EQUAL(result, 1);
3233 
3235  rast1, -1,
3236  rast2, -1,
3237  2.,
3238  &result
3239  );
3240  CU_ASSERT_EQUAL(rtn, ES_NONE);
3241  CU_ASSERT_EQUAL(result, 1);
3242 
3243  /*
3244  rast2
3245 
3246  (0, 0)
3247  +-+-+
3248  |0|1|
3249  +-+-+
3250  |1|1|
3251  +-+-+
3252  (2, 2)
3253  */
3254  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3255 
3257  rast1, 0,
3258  rast2, 0,
3259  0.,
3260  &result
3261  );
3262  CU_ASSERT_EQUAL(rtn, ES_NONE);
3263  CU_ASSERT_EQUAL(result, 1);
3264 
3265  /*
3266  rast2
3267 
3268  (0, 0)
3269  +-+-+
3270  |1|0|
3271  +-+-+
3272  |1|1|
3273  +-+-+
3274  (2, 2)
3275  */
3276  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3277  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3278 
3280  rast1, 0,
3281  rast2, 0,
3282  0.,
3283  &result
3284  );
3285  CU_ASSERT_EQUAL(rtn, ES_NONE);
3286  CU_ASSERT_EQUAL(result, 1);
3287 
3288  /*
3289  rast2
3290 
3291  (0, 0)
3292  +-+-+
3293  |0|0|
3294  +-+-+
3295  |0|1|
3296  +-+-+
3297  (2, 2)
3298  */
3299  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3300  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3301  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
3302 
3304  rast1, 0,
3305  rast2, 0,
3306  0,
3307  &result
3308  );
3309  CU_ASSERT_EQUAL(rtn, ES_NONE);
3310  CU_ASSERT_EQUAL(result, 1);
3311 
3312  /*
3313  rast2
3314 
3315  (0, 0)
3316  +-+-+
3317  |0|0|
3318  +-+-+
3319  |0|0|
3320  +-+-+
3321  (2, 2)
3322  */
3323  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3324  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3325  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
3326  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3327 
3329  rast1, 0,
3330  rast2, 0,
3331  0,
3332  &result
3333  );
3334  CU_ASSERT_EQUAL(rtn, ES_NONE);
3335  CU_ASSERT_NOT_EQUAL(result, 1);
3336 
3337  /*
3338  rast2
3339 
3340  (2, 0)
3341  +-+-+
3342  |1|1|
3343  +-+-+
3344  |1|1|
3345  +-+-+
3346  (4, 2)
3347  */
3348  rt_raster_set_offsets(rast2, 2, 0);
3349 
3350  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3351  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3352  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3353  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3354 
3356  rast1, 0,
3357  rast2, 0,
3358  0,
3359  &result
3360  );
3361  CU_ASSERT_EQUAL(rtn, ES_NONE);
3362  CU_ASSERT_NOT_EQUAL(result, 1);
3363 
3365  rast1, 0,
3366  rast2, 0,
3367  1.1,
3368  &result
3369  );
3370  CU_ASSERT_EQUAL(rtn, ES_NONE);
3371  CU_ASSERT_EQUAL(result, 1);
3372 
3373  /*
3374  rast2
3375 
3376  (0.1, 0.1)
3377  +-+-+
3378  |1|1|
3379  +-+-+
3380  |1|1|
3381  +-+-+
3382  (0.9, 0.9)
3383  */
3384  rt_raster_set_offsets(rast2, 0.1, 0.1);
3385  rt_raster_set_scale(rast2, 0.4, 0.4);
3386 
3387  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3388  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3389  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3390  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3391 
3393  rast1, 0,
3394  rast2, 0,
3395  0,
3396  &result
3397  );
3398  CU_ASSERT_EQUAL(rtn, ES_NONE);
3399  CU_ASSERT_EQUAL(result, 1);
3400 
3401  /*
3402  rast2
3403 
3404  (-0.1, 0.1)
3405  +-+-+
3406  |1|1|
3407  +-+-+
3408  |1|1|
3409  +-+-+
3410  (0.9, 0.9)
3411  */
3412  rt_raster_set_offsets(rast2, -0.1, 0.1);
3413 
3415  rast1, 0,
3416  rast2, 0,
3417  0,
3418  &result
3419  );
3420  CU_ASSERT_EQUAL(rtn, ES_NONE);
3421  CU_ASSERT_EQUAL(result, 1);
3422 
3423  cu_free_raster(rast2);
3424 
3425  /*
3426  rast2
3427 
3428  (0, 0)
3429  +-+-+-+
3430  |1|1|1|
3431  +-+-+-+
3432  |1|1|1|
3433  +-+-+-+
3434  |1|1|1|
3435  +-+-+-+
3436  (3, 3)
3437  */
3438  rast2 = rt_raster_new(3, 3);
3439  CU_ASSERT(rast2 != NULL);
3440  rt_raster_set_scale(rast2, 1, 1);
3441 
3442  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3443  CU_ASSERT(band2 != NULL);
3444  rt_band_set_nodata(band2, 0, NULL);
3445  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3446  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3447  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3448  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3449  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3450  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3451  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3452  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3453  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
3454 
3455  rt_band_get_nodata(band2, &nodata);
3456  CU_ASSERT_EQUAL(nodata, 0);
3457 
3459  rast1, 0,
3460  rast2, 0,
3461  0,
3462  &result
3463  );
3464  CU_ASSERT_EQUAL(rtn, ES_NONE);
3465  CU_ASSERT_EQUAL(result, 1);
3466 
3467  /*
3468  rast2
3469 
3470  (-2, -2)
3471  +-+-+-+
3472  |1|1|1|
3473  +-+-+-+
3474  |1|1|1|
3475  +-+-+-+
3476  |1|1|1|
3477  +-+-+-+
3478  (1, 1)
3479  */
3480  rt_raster_set_offsets(rast2, -2, -2);
3481 
3482  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3483  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3484  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3485  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3486  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3487  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3488  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3489  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3490  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
3491 
3493  rast1, 0,
3494  rast2, 0,
3495  0,
3496  &result
3497  );
3498  CU_ASSERT_EQUAL(rtn, ES_NONE);
3499  CU_ASSERT_EQUAL(result, 1);
3500 
3501  /*
3502  rast2
3503 
3504  (-2, -2)
3505  +-+-+-+
3506  |0|1|1|
3507  +-+-+-+
3508  |1|0|1|
3509  +-+-+-+
3510  |1|1|0|
3511  +-+-+-+
3512  (1, 1)
3513  */
3514  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3515  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3516  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3517  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3518  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3519  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3520  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3521  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3522  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3523 
3525  rast1, 0,
3526  rast2, 0,
3527  0,
3528  &result
3529  );
3530  CU_ASSERT_EQUAL(rtn, ES_NONE);
3531  CU_ASSERT_EQUAL(result, 1);
3532 
3533  /*
3534  rast2
3535 
3536  (-2, -2)
3537  +-+-+-+
3538  |0|1|1|
3539  +-+-+-+
3540  |1|0|0|
3541  +-+-+-+
3542  |1|0|0|
3543  +-+-+-+
3544  (1, 1)
3545  */
3546  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3547  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3548  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3549  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3550  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3551  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
3552  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3553  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
3554  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3555 
3557  rast1, 0,
3558  rast2, 0,
3559  0,
3560  &result
3561  );
3562  CU_ASSERT_EQUAL(rtn, ES_NONE);
3563  CU_ASSERT_EQUAL(result, 1);
3564 
3565  /*
3566  rast2
3567 
3568  (-2, -2)
3569  +-+-+-+
3570  |0|1|0|
3571  +-+-+-+
3572  |1|0|0|
3573  +-+-+-+
3574  |0|0|0|
3575  +-+-+-+
3576  (1, 1)
3577  */
3578  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3579  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3580  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
3581  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3582  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3583  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
3584  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
3585  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
3586  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3587 
3589  rast1, 0,
3590  rast2, 0,
3591  0,
3592  &result
3593  );
3594  CU_ASSERT_EQUAL(rtn, ES_NONE);
3595  CU_ASSERT_EQUAL(result, 1);
3596 
3597  /*
3598  rast2
3599 
3600  (-10, -1)
3601  +-+-+-+
3602  |1|1|1|
3603  +-+-+-+
3604  |1|1|1|
3605  +-+-+-+
3606  |1|1|1|
3607  +-+-+-+
3608  (-7, 2)
3609  */
3610  rt_raster_set_offsets(rast2, -10, -1);
3611 
3612  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3613  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3614  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3615  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3616  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3617  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3618  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3619  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3620  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
3621 
3623  rast1, 0,
3624  rast2, 0,
3625  5,
3626  &result
3627  );
3628  CU_ASSERT_EQUAL(rtn, ES_NONE);
3629  CU_ASSERT_NOT_EQUAL(result, 1);
3630 
3632  rast1, 0,
3633  rast2, 0,
3634  6,
3635  &result
3636  );
3637  CU_ASSERT_EQUAL(rtn, ES_NONE);
3638  CU_ASSERT_EQUAL(result, 1);
3639 
3640  cu_free_raster(rast2);
3641 
3642  /* skew tests */
3643  /* rast2 (skewed by -0.5, 0.5) */
3644  rast2 = rt_raster_new(3, 3);
3645  CU_ASSERT(rast2 != NULL);
3646  rt_raster_set_scale(rast2, 1, 1);
3647  rt_raster_set_skews(rast2, -0.5, 0.5);
3648 
3649  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3650  CU_ASSERT(band2 != NULL);
3651  rt_band_set_nodata(band2, 0, NULL);
3652  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3653  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
3654  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
3655  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3656  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
3657  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
3658  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3659  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
3660  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
3661 
3663  rast1, 0,
3664  rast2, 0,
3665  0,
3666  &result
3667  );
3668  CU_ASSERT_EQUAL(rtn, ES_NONE);
3669  CU_ASSERT_EQUAL(result, 1);
3670 
3671  /* rast2 (skewed by -1, 1) */
3672  rt_raster_set_skews(rast2, -1, 1);
3673 
3675  rast1, 0,
3676  rast2, 0,
3677  0,
3678  &result
3679  );
3680  CU_ASSERT_EQUAL(rtn, ES_NONE);
3681  CU_ASSERT_EQUAL(result, 1);
3682 
3683  /* rast2 (skewed by 1, -1) */
3684  rt_raster_set_skews(rast2, 1, -1);
3685 
3687  rast1, 0,
3688  rast2, 0,
3689  0,
3690  &result
3691  );
3692  CU_ASSERT_EQUAL(rtn, ES_NONE);
3693  CU_ASSERT_EQUAL(result, 1);
3694 
3695  cu_free_raster(rast2);
3696  cu_free_raster(rast1);
3697 }
3698 
3700  rt_raster rast1;
3701  rt_raster rast2;
3702  rt_band band1;
3703  rt_band band2;
3704  double nodata;
3705  int rtn;
3706  int result;
3707 
3708  /*
3709  rast1
3710 
3711  (-1, -1)
3712  +-+-+
3713  |1|1|
3714  +-+-+
3715  |1|1|
3716  +-+-+
3717  (1, 1)
3718  */
3719  rast1 = rt_raster_new(2, 2);
3720  CU_ASSERT(rast1 != NULL);
3721  rt_raster_set_scale(rast1, 1, 1);
3722  rt_raster_set_offsets(rast1, -1, -1);
3723 
3724  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
3725  CU_ASSERT(band1 != NULL);
3726  rt_band_set_nodata(band1, 0, NULL);
3727  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
3728  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
3729  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
3730  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
3731 
3732  rt_band_get_nodata(band1, &nodata);
3733  CU_ASSERT_EQUAL(nodata, 0);
3734 
3736  rast1, 0,
3737  rast1, 0,
3738  0.,
3739  &result
3740  );
3741  CU_ASSERT_EQUAL(rtn, ES_NONE);
3742  CU_ASSERT_NOT_EQUAL(result, 1);
3743 
3745  rast1, 0,
3746  rast1, 0,
3747  -1.,
3748  &result
3749  );
3750  CU_ASSERT_NOT_EQUAL(rtn, ES_NONE);
3751 
3752  /*
3753  rast2
3754 
3755  (0, 0)
3756  +-+-+
3757  |1|1|
3758  +-+-+
3759  |1|1|
3760  +-+-+
3761  (2, 2)
3762  */
3763  rast2 = rt_raster_new(2, 2);
3764  CU_ASSERT(rast2 != NULL);
3765  rt_raster_set_scale(rast2, 1, 1);
3766 
3767  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3768  CU_ASSERT(band2 != NULL);
3769  rt_band_set_nodata(band2, 0, NULL);
3770  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3771  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3772  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3773  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3774 
3775  rt_band_get_nodata(band2, &nodata);
3776  CU_ASSERT_EQUAL(nodata, 0);
3777 
3779  rast1, 0,
3780  rast2, 0,
3781  0.,
3782  &result
3783  );
3784  CU_ASSERT_EQUAL(rtn, ES_NONE);
3785  CU_ASSERT_NOT_EQUAL(result, 1);
3786 
3788  rast1, 0,
3789  rast2, 0,
3790  1.,
3791  &result
3792  );
3793  CU_ASSERT_EQUAL(rtn, ES_NONE);
3794  CU_ASSERT_NOT_EQUAL(result, 1);
3795 
3797  rast1, -1,
3798  rast2, -1,
3799  5.,
3800  &result
3801  );
3802  CU_ASSERT_EQUAL(rtn, ES_NONE);
3803  CU_ASSERT_EQUAL(result, 1);
3804 
3805  /*
3806  rast2
3807 
3808  (0, 0)
3809  +-+-+
3810  |0|1|
3811  +-+-+
3812  |1|1|
3813  +-+-+
3814  (2, 2)
3815  */
3816  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3817 
3819  rast1, 0,
3820  rast2, 0,
3821  2.,
3822  &result
3823  );
3824  CU_ASSERT_EQUAL(rtn, ES_NONE);
3825  CU_ASSERT_NOT_EQUAL(result, 1);
3826 
3827  /*
3828  rast2
3829 
3830  (0, 0)
3831  +-+-+
3832  |1|0|
3833  +-+-+
3834  |1|1|
3835  +-+-+
3836  (2, 2)
3837  */
3838  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3839  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3840 
3842  rast1, 0,
3843  rast2, 0,
3844  5.,
3845  &result
3846  );
3847  CU_ASSERT_EQUAL(rtn, ES_NONE);
3848  CU_ASSERT_EQUAL(result, 1);
3849 
3850  /*
3851  rast2
3852 
3853  (0, 0)
3854  +-+-+
3855  |0|0|
3856  +-+-+
3857  |0|1|
3858  +-+-+
3859  (2, 2)
3860  */
3861  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3862  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3863  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
3864 
3866  rast1, 0,
3867  rast2, 0,
3868  5,
3869  &result
3870  );
3871  CU_ASSERT_EQUAL(rtn, ES_NONE);
3872  CU_ASSERT_EQUAL(result, 1);
3873 
3874  /*
3875  rast2
3876 
3877  (0, 0)
3878  +-+-+
3879  |0|0|
3880  +-+-+
3881  |0|0|
3882  +-+-+
3883  (2, 2)
3884  */
3885  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3886  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3887  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
3888  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3889 
3891  rast1, 0,
3892  rast2, 0,
3893  10,
3894  &result
3895  );
3896  CU_ASSERT_EQUAL(rtn, ES_NONE);
3897  CU_ASSERT_NOT_EQUAL(result, 1);
3898 
3899  /*
3900  rast2
3901 
3902  (2, 0)
3903  +-+-+
3904  |1|1|
3905  +-+-+
3906  |1|1|
3907  +-+-+
3908  (4, 2)
3909  */
3910  rt_raster_set_offsets(rast2, 2, 0);
3911 
3912  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3913  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3914  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3915  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3916 
3918  rast1, 0,
3919  rast2, 0,
3920  0,
3921  &result
3922  );
3923  CU_ASSERT_EQUAL(rtn, ES_NONE);
3924  CU_ASSERT_NOT_EQUAL(result, 1);
3925 
3927  rast1, 0,
3928  rast2, 0,
3929  5.9,
3930  &result
3931  );
3932  CU_ASSERT_EQUAL(rtn, ES_NONE);
3933  CU_ASSERT_EQUAL(result, 1);
3934 
3935  /*
3936  rast2
3937 
3938  (0.1, 0.1)
3939  +-+-+
3940  |1|1|
3941  +-+-+
3942  |1|1|
3943  +-+-+
3944  (0.9, 0.9)
3945  */
3946  rt_raster_set_offsets(rast2, 0.1, 0.1);
3947  rt_raster_set_scale(rast2, 0.4, 0.4);
3948 
3949  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3950  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3951  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3952  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3953 
3955  rast1, 0,
3956  rast2, 0,
3957  3,
3958  &result
3959  );
3960  CU_ASSERT_EQUAL(rtn, ES_NONE);
3961  CU_ASSERT_EQUAL(result, 1);
3962 
3963  /*
3964  rast2
3965 
3966  (-0.1, 0.1)
3967  +-+-+
3968  |1|1|
3969  +-+-+
3970  |1|1|
3971  +-+-+
3972  (0.9, 0.9)
3973  */
3974  rt_raster_set_offsets(rast2, -0.1, 0.1);
3975 
3977  rast1, 0,
3978  rast2, 0,
3979  2,
3980  &result
3981  );
3982  CU_ASSERT_EQUAL(rtn, ES_NONE);
3983  CU_ASSERT_NOT_EQUAL(result, 1);
3984 
3985  cu_free_raster(rast2);
3986 
3987  /*
3988  rast2
3989 
3990  (0, 0)
3991  +-+-+-+
3992  |1|1|1|
3993  +-+-+-+
3994  |1|1|1|
3995  +-+-+-+
3996  |1|1|1|
3997  +-+-+-+
3998  (3, 3)
3999  */
4000  rast2 = rt_raster_new(3, 3);
4001  CU_ASSERT(rast2 != NULL);
4002  rt_raster_set_scale(rast2, 1, 1);
4003 
4004  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4005  CU_ASSERT(band2 != NULL);
4006  rt_band_set_nodata(band2, 0, NULL);
4007  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4008  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4009  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4010  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4011  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4012  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4013  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4014  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4015  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4016 
4017  rt_band_get_nodata(band2, &nodata);
4018  CU_ASSERT_EQUAL(nodata, 0);
4019 
4021  rast1, 0,
4022  rast2, 0,
4023  6,
4024  &result
4025  );
4026  CU_ASSERT_EQUAL(rtn, ES_NONE);
4027  CU_ASSERT_EQUAL(result, 1);
4028 
4029  /*
4030  rast2
4031 
4032  (-2, -2)
4033  +-+-+-+
4034  |1|1|1|
4035  +-+-+-+
4036  |1|1|1|
4037  +-+-+-+
4038  |1|1|1|
4039  +-+-+-+
4040  (1, 1)
4041  */
4042  rt_raster_set_offsets(rast2, -2, -2);
4043 
4044  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4045  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4046  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4047  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4048  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4049  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4050  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4051  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4052  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4053 
4055  rast1, 0,
4056  rast2, 0,
4057  4.25,
4058  &result
4059  );
4060  CU_ASSERT_EQUAL(rtn, ES_NONE);
4061  CU_ASSERT_EQUAL(result, 1);
4062 
4063  /*
4064  rast2
4065 
4066  (-2, -2)
4067  +-+-+-+
4068  |0|1|1|
4069  +-+-+-+
4070  |1|0|1|
4071  +-+-+-+
4072  |1|1|0|
4073  +-+-+-+
4074  (1, 1)
4075  */
4076  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4077  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4078  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4079  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4080  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4081  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4082  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4083  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4084  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4085 
4087  rast1, 0,
4088  rast2, 0,
4089  3.5,
4090  &result
4091  );
4092  CU_ASSERT_EQUAL(rtn, ES_NONE);
4093  CU_ASSERT_NOT_EQUAL(result, 1);
4094 
4095  /*
4096  rast2
4097 
4098  (-2, -2)
4099  +-+-+-+
4100  |0|1|1|
4101  +-+-+-+
4102  |1|0|0|
4103  +-+-+-+
4104  |1|0|0|
4105  +-+-+-+
4106  (1, 1)
4107  */
4108  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4109  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4110  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4111  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4112  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4113  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
4114  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4115  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
4116  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4117 
4119  rast1, 0,
4120  rast2, 0,
4121  3.65,
4122  &result
4123  );
4124  CU_ASSERT_EQUAL(rtn, ES_NONE);
4125  CU_ASSERT_EQUAL(result, 1);
4126 
4127  /*
4128  rast2
4129 
4130  (-2, -2)
4131  +-+-+-+
4132  |0|1|0|
4133  +-+-+-+
4134  |1|0|0|
4135  +-+-+-+
4136  |0|0|0|
4137  +-+-+-+
4138  (1, 1)
4139  */
4140  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4141  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4142  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
4143  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4144  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4145  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
4146  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
4147  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
4148  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4149 
4151  rast1, 0,
4152  rast2, 0,
4153  3.6,
4154  &result
4155  );
4156  CU_ASSERT_EQUAL(rtn, ES_NONE);
4157  CU_ASSERT_NOT_EQUAL(result, 1);
4158 
4159  /*
4160  rast2
4161 
4162  (-10, -1)
4163  +-+-+-+
4164  |1|1|1|
4165  +-+-+-+
4166  |1|1|1|
4167  +-+-+-+
4168  |1|1|1|
4169  +-+-+-+
4170  (-7, 2)
4171  */
4172  rt_raster_set_offsets(rast2, -10, -1);
4173 
4174  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4175  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4176  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4177  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4178  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4179  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4180  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4181  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4182  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4183 
4185  rast1, 0,
4186  rast2, 0,
4187  5,
4188  &result
4189  );
4190  CU_ASSERT_EQUAL(rtn, ES_NONE);
4191  CU_ASSERT_NOT_EQUAL(result, 1);
4192 
4194  rast1, 0,
4195  rast2, 0,
4196  11.5,
4197  &result
4198  );
4199  CU_ASSERT_EQUAL(rtn, ES_NONE);
4200  CU_ASSERT_EQUAL(result, 1);
4201 
4202  cu_free_raster(rast2);
4203 
4204  /* skew tests */
4205  /* rast2 (skewed by -0.5, 0.5) */
4206  rast2 = rt_raster_new(3, 3);
4207  CU_ASSERT(rast2 != NULL);
4208  rt_raster_set_scale(rast2, 1, 1);
4209  rt_raster_set_skews(rast2, -0.5, 0.5);
4210 
4211  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4212  CU_ASSERT(band2 != NULL);
4213  rt_band_set_nodata(band2, 0, NULL);
4214  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4215  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
4216  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
4217  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4218  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
4219  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
4220  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4221  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
4222  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
4223 
4225  rast1, 0,
4226  rast2, 0,
4227  6.1,
4228  &result
4229  );
4230  CU_ASSERT_EQUAL(rtn, ES_NONE);
4231  CU_ASSERT_EQUAL(result, 1);
4232 
4233  /* rast2 (skewed by -1, 1) */
4234  rt_raster_set_skews(rast2, -1, 1);
4235 
4237  rast1, 0,
4238  rast2, 0,
4239  7.1,
4240  &result
4241  );
4242  CU_ASSERT_EQUAL(rtn, ES_NONE);
4243  CU_ASSERT_EQUAL(result, 1);
4244 
4245  /* rast2 (skewed by 1, -1) */
4246  rt_raster_set_skews(rast2, 1, -1);
4247 
4249  rast1, 0,
4250  rast2, 0,
4251  8,
4252  &result
4253  );
4254  CU_ASSERT_EQUAL(rtn, ES_NONE);
4255  CU_ASSERT_EQUAL(result, 1);
4256 
4257  cu_free_raster(rast2);
4258  cu_free_raster(rast1);
4259 }
4260 
4261 static void test_raster_intersects() {
4262  rt_raster rast1;
4263  rt_raster rast2;
4264  rt_band band1;
4265  rt_band band2;
4266  double nodata;
4267  int rtn;
4268  int result;
4269 
4270  /*
4271  rast1
4272 
4273  (-1, -1)
4274  +-+-+
4275  |1|1|
4276  +-+-+
4277  |1|1|
4278  +-+-+
4279  (1, 1)
4280  */
4281  rast1 = rt_raster_new(2, 2);
4282  CU_ASSERT(rast1 != NULL);
4283  rt_raster_set_scale(rast1, 1, 1);
4284  rt_raster_set_offsets(rast1, -1, -1);
4285 
4286  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
4287  CU_ASSERT(band1 != NULL);
4288  rt_band_set_nodata(band1, 0, NULL);
4289  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
4290  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
4291  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
4292  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
4293 
4294  rt_band_get_nodata(band1, &nodata);
4295  CU_ASSERT_EQUAL(nodata, 0);
4296 
4297  /*
4298  rast2
4299 
4300  (0, 0)
4301  +-+-+
4302  |1|1|
4303  +-+-+
4304  |1|1|
4305  +-+-+
4306  (2, 2)
4307  */
4308  rast2 = rt_raster_new(2, 2);
4309  CU_ASSERT(rast2 != NULL);
4310  rt_raster_set_scale(rast2, 1, 1);
4311 
4312  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4313  CU_ASSERT(band2 != NULL);
4314  rt_band_set_nodata(band2, 0, NULL);
4315  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4316  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4317  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4318  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4319 
4320  rt_band_get_nodata(band2, &nodata);
4321  CU_ASSERT_EQUAL(nodata, 0);
4322 
4323  rtn = rt_raster_intersects(
4324  rast1, 0,
4325  rast2, 0,
4326  &result
4327  );
4328  CU_ASSERT_EQUAL(rtn, ES_NONE);
4329  CU_ASSERT_EQUAL(result, 1);
4330 
4331  rtn = rt_raster_intersects(
4332  rast1, -1,
4333  rast2, -1,
4334  &result
4335  );
4336  CU_ASSERT_EQUAL(rtn, ES_NONE);
4337  CU_ASSERT_EQUAL(result, 1);
4338 
4339  /*
4340  rast2
4341 
4342  (0, 0)
4343  +-+-+
4344  |0|1|
4345  +-+-+
4346  |1|1|
4347  +-+-+
4348  (2, 2)
4349  */
4350  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4351 
4352  rtn = rt_raster_intersects(
4353  rast1, 0,
4354  rast2, 0,
4355  &result
4356  );
4357  CU_ASSERT_EQUAL(rtn, ES_NONE);
4358  CU_ASSERT_EQUAL(result, 1);
4359 
4360  /*
4361  rast2
4362 
4363  (0, 0)
4364  +-+-+
4365  |1|0|
4366  +-+-+
4367  |1|1|
4368  +-+-+
4369  (2, 2)
4370  */
4371  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4372  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
4373 
4374  rtn = rt_raster_intersects(
4375  rast1, 0,
4376  rast2, 0,
4377  &result
4378  );
4379  CU_ASSERT_EQUAL(rtn, ES_NONE);
4380  CU_ASSERT_EQUAL(result, 1);
4381 
4382  /*
4383  rast2
4384 
4385  (0, 0)
4386  +-+-+
4387  |0|0|
4388  +-+-+
4389  |0|1|
4390  +-+-+
4391  (2, 2)
4392  */
4393  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4394  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
4395  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
4396 
4397  rtn = rt_raster_intersects(
4398  rast1, 0,
4399  rast2, 0,
4400  &result
4401  );
4402  CU_ASSERT_EQUAL(rtn, ES_NONE);
4403  CU_ASSERT_EQUAL(result, 1);
4404 
4405  /*
4406  rast2
4407 
4408  (0, 0)
4409  +-+-+
4410  |0|0|
4411  +-+-+
4412  |0|0|
4413  +-+-+
4414  (2, 2)
4415  */
4416  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4417  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
4418  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
4419  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4420 
4421  rtn = rt_raster_intersects(
4422  rast1, 0,
4423  rast2, 0,
4424  &result
4425  );
4426  CU_ASSERT_EQUAL(rtn, ES_NONE);
4427  CU_ASSERT_NOT_EQUAL(result, 1);
4428 
4429  /*
4430  rast2
4431 
4432  (2, 0)
4433  +-+-+
4434  |1|1|
4435  +-+-+
4436  |1|1|
4437  +-+-+
4438  (4, 2)
4439  */
4440  rt_raster_set_offsets(rast2, 2, 0);
4441 
4442  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4443  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4444  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4445  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4446 
4447  rtn = rt_raster_intersects(
4448  rast1, 0,
4449  rast2, 0,
4450  &result
4451  );
4452  CU_ASSERT_EQUAL(rtn, ES_NONE);
4453  CU_ASSERT_NOT_EQUAL(result, 1);
4454 
4455  /*
4456  rast2
4457 
4458  (0.1, 0.1)
4459  +-+-+
4460  |1|1|
4461  +-+-+
4462  |1|1|
4463  +-+-+
4464  (0.9, 0.9)
4465  */
4466  rt_raster_set_offsets(rast2, 0.1, 0.1);
4467  rt_raster_set_scale(rast2, 0.4, 0.4);
4468 
4469  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4470  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4471  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4472  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4473 
4474  rtn = rt_raster_intersects(
4475  rast1, 0,
4476  rast2, 0,
4477  &result
4478  );
4479  CU_ASSERT_EQUAL(rtn, ES_NONE);
4480  CU_ASSERT_EQUAL(result, 1);
4481 
4482  /*
4483  rast2
4484 
4485  (-0.1, 0.1)
4486  +-+-+
4487  |1|1|
4488  +-+-+
4489  |1|1|
4490  +-+-+
4491  (0.9, 0.9)
4492  */
4493  rt_raster_set_offsets(rast2, -0.1, 0.1);
4494 
4495  rtn = rt_raster_intersects(
4496  rast1, 0,
4497  rast2, 0,
4498  &result
4499  );
4500  CU_ASSERT_EQUAL(rtn, ES_NONE);
4501  CU_ASSERT_EQUAL(result, 1);
4502 
4503  cu_free_raster(rast2);
4504 
4505  /*
4506  rast2
4507 
4508  (0, 0)
4509  +-+-+-+
4510  |1|1|1|
4511  +-+-+-+
4512  |1|1|1|
4513  +-+-+-+
4514  |1|1|1|
4515  +-+-+-+
4516  (3, 3)
4517  */
4518  rast2 = rt_raster_new(3, 3);
4519  CU_ASSERT(rast2 != NULL);
4520  rt_raster_set_scale(rast2, 1, 1);
4521 
4522  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4523  CU_ASSERT(band2 != NULL);
4524  rt_band_set_nodata(band2, 0, NULL);
4525  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4526  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4527  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4528  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4529  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4530  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4531  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4532  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4533  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4534 
4535  rt_band_get_nodata(band2, &nodata);
4536  CU_ASSERT_EQUAL(nodata, 0);
4537 
4538  rtn = rt_raster_intersects(
4539  rast1, 0,
4540  rast2, 0,
4541  &result
4542  );
4543  CU_ASSERT_EQUAL(rtn, ES_NONE);
4544  CU_ASSERT_EQUAL(result, 1);
4545 
4546  /*
4547  rast2
4548 
4549  (-2, -2)
4550  +-+-+-+
4551  |1|1|1|
4552  +-+-+-+
4553  |1|1|1|
4554  +-+-+-+
4555  |1|1|1|
4556  +-+-+-+
4557  (1, 1)
4558  */
4559  rt_raster_set_offsets(rast2, -2, -2);
4560 
4561  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4562  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4563  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4564  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4565  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4566  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4567  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4568  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4569  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4570 
4571  rtn = rt_raster_intersects(
4572  rast1, 0,
4573  rast2, 0,
4574  &result
4575  );
4576  CU_ASSERT_EQUAL(rtn, ES_NONE);
4577  CU_ASSERT_EQUAL(result, 1);
4578 
4579  /*
4580  rast2
4581 
4582  (-2, -2)
4583  +-+-+-+
4584  |0|1|1|
4585  +-+-+-+
4586  |1|0|1|
4587  +-+-+-+
4588  |1|1|0|
4589  +-+-+-+
4590  (1, 1)
4591  */
4592  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4593  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4594  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4595  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4596  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4597  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4598  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4599  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4600  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4601 
4602  rtn = rt_raster_intersects(
4603  rast1, 0,
4604  rast2, 0,
4605  &result
4606  );
4607  CU_ASSERT_EQUAL(rtn, ES_NONE);
4608  CU_ASSERT_EQUAL(result, 1);
4609 
4610  /*
4611  rast2
4612 
4613  (-2, -2)
4614  +-+-+-+
4615  |0|1|1|
4616  +-+-+-+
4617  |1|0|0|
4618  +-+-+-+
4619  |1|0|0|
4620  +-+-+-+
4621  (1, 1)
4622  */
4623  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4624  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4625  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4626  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4627  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4628  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
4629  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4630  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
4631  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4632 
4633  rtn = rt_raster_intersects(
4634  rast1, 0,
4635  rast2, 0,
4636  &result
4637  );
4638  CU_ASSERT_EQUAL(rtn, ES_NONE);
4639  CU_ASSERT_EQUAL(result, 1);
4640 
4641  /*
4642  rast2
4643 
4644  (-2, -2)
4645  +-+-+-+
4646  |0|1|0|
4647  +-+-+-+
4648  |1|0|0|
4649  +-+-+-+
4650  |0|0|0|
4651  +-+-+-+
4652  (1, 1)
4653  */
4654  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4655  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4656  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
4657  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4658  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4659  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
4660  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
4661  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
4662  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4663 
4664  rtn = rt_raster_intersects(
4665  rast1, 0,
4666  rast2, 0,
4667  &result
4668  );
4669  CU_ASSERT_EQUAL(rtn, ES_NONE);
4670  CU_ASSERT_EQUAL(result, 1);
4671 
4672  cu_free_raster(rast2);
4673 
4674  /* skew tests */
4675  /* rast2 (skewed by -0.5, 0.5) */
4676  rast2 = rt_raster_new(3, 3);
4677  CU_ASSERT(rast2 != NULL);
4678  rt_raster_set_scale(rast2, 1, 1);
4679  rt_raster_set_skews(rast2, -0.5, 0.5);
4680 
4681  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4682  CU_ASSERT(band2 != NULL);
4683  rt_band_set_nodata(band2, 0, NULL);
4684  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4685  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
4686  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
4687  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4688  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
4689  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
4690  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4691  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
4692  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
4693 
4694  rtn = rt_raster_intersects(
4695  rast1, 0,
4696  rast2, 0,
4697  &result
4698  );
4699  CU_ASSERT_EQUAL(rtn, ES_NONE);
4700  CU_ASSERT_EQUAL(result, 1);
4701 
4702  /* rast2 (skewed by -1, 1) */
4703  rt_raster_set_skews(rast2, -1, 1);
4704 
4705  rtn = rt_raster_intersects(
4706  rast1, 0,
4707  rast2, 0,
4708  &result
4709  );
4710  CU_ASSERT_EQUAL(rtn, ES_NONE);
4711  CU_ASSERT_EQUAL(result, 1);
4712 
4713  /* rast2 (skewed by 1, -1) */
4714  rt_raster_set_skews(rast2, 1, -1);
4715 
4716  rtn = rt_raster_intersects(
4717  rast1, 0,
4718  rast2, 0,
4719  &result
4720  );
4721  CU_ASSERT_EQUAL(rtn, ES_NONE);
4722  CU_ASSERT_EQUAL(result, 1);
4723 
4724  cu_free_raster(rast2);
4725  cu_free_raster(rast1);
4726 }
4727 
4729  rt_raster rast1;
4730  rt_raster rast2;
4731  int rtn;
4732  int aligned;
4733  char *reason;
4734 
4735  rast1 = rt_raster_new(2, 2);
4736  CU_ASSERT(rast1 != NULL);
4737  rt_raster_set_scale(rast1, 1, 1);
4738 
4739  rast2 = rt_raster_new(10, 10);
4740  CU_ASSERT(rast2 != NULL);
4741  rt_raster_set_scale(rast2, 1, 1);
4742 
4743  rtn = rt_raster_same_alignment(rast1, rast2, &aligned, NULL);
4744  CU_ASSERT_EQUAL(rtn, ES_NONE);
4745  CU_ASSERT_NOT_EQUAL(aligned, 0);
4746 
4747  rt_raster_set_scale(rast2, 0.1, 0.1);
4748  rtn = rt_raster_same_alignment(rast1, rast2, &aligned, &reason);
4749  CU_ASSERT_EQUAL(rtn, ES_NONE);
4750  CU_ASSERT_EQUAL(aligned, 0);
4751  CU_ASSERT_STRING_EQUAL(reason, "The rasters have different scales on the X axis");
4752  rt_raster_set_scale(rast2, 1, 1);
4753 
4754  rt_raster_set_skews(rast2, -0.5, 0.5);
4755  rtn = rt_raster_same_alignment(rast1, rast2, &aligned, &reason);
4756  CU_ASSERT_EQUAL(rtn, ES_NONE);
4757  CU_ASSERT_EQUAL(aligned, 0);
4758  CU_ASSERT_STRING_EQUAL(reason, "The rasters have different skews on the X axis");
4759  rt_raster_set_skews(rast2, 0, 0);
4760 
4761  rt_raster_set_offsets(rast2, 1, 1);
4762  rtn = rt_raster_same_alignment(rast1, rast2, &aligned, NULL);
4763  CU_ASSERT_EQUAL(rtn, ES_NONE);
4764  CU_ASSERT_NOT_EQUAL(aligned, 0);
4765 
4766  rt_raster_set_offsets(rast2, 2, 3);
4767  rtn = rt_raster_same_alignment(rast1, rast2, &aligned, NULL);
4768  CU_ASSERT_EQUAL(rtn, ES_NONE);
4769  CU_ASSERT_NOT_EQUAL(aligned, 0);
4770 
4771  rt_raster_set_offsets(rast2, 0.1, 0.1);
4772  rtn = rt_raster_same_alignment(rast1, rast2, &aligned, &reason);
4773  CU_ASSERT_EQUAL(rtn, ES_NONE);
4774  CU_ASSERT_EQUAL(aligned, 0);
4775  CU_ASSERT_STRING_EQUAL(reason, "The rasters (pixel corner coordinates) are not aligned");
4776 
4777  cu_free_raster(rast2);
4778  cu_free_raster(rast1);
4779 }
4780 
4781 /* register tests */
4784 {
4785  CU_pSuite suite = CU_add_suite("spatial_relationship", NULL, NULL);
4796 }
4797 
void spatial_relationship_suite_setup(void)
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
static void test_raster_geos_overlaps()
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_raster.c:168
static void test_raster_geos_covers()
rt_errorstate rt_raster_covers(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *covers)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_raster_contains(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:733
static void test_raster_same_alignment()
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
rt_errorstate rt_raster_intersects(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *intersects)
Return ES_ERROR if error occurred in function.
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
#define PG_ADD_TEST(suite, testfunc)
static void test_raster_within_distance()
static void test_raster_geos_contains()
static void test_raster_geos_contains_properly()
static void test_raster_intersects()
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
static void test_raster_geos_covered_by()
static void test_raster_geos_touches()
rt_errorstate rt_raster_touches(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *touches)
Return ES_ERROR if error occurred in function.
static void test_raster_fully_within_distance()
rt_errorstate rt_raster_fully_within_distance(rt_raster rast1, int nband1, rt_raster rast2, int nband2, double distance, int *dfwithin)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:974
rt_errorstate rt_raster_coveredby(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *coveredby)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_raster_within_distance(rt_raster rast1, int nband1, rt_raster rast2, int nband2, double distance, int *dwithin)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_raster_contains_properly(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_raster_overlaps(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *overlaps)
Return ES_ERROR if error occurred in function.