| 1 | /*
|
|---|
| 2 | * Copyright (c) 2019 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | #include <gfx/coord.h>
|
|---|
| 30 | #include <pcut/pcut.h>
|
|---|
| 31 |
|
|---|
| 32 | PCUT_INIT;
|
|---|
| 33 |
|
|---|
| 34 | PCUT_TEST_SUITE(coord);
|
|---|
| 35 |
|
|---|
| 36 | /** gfx_coord2_add should add two coordinate vectors */
|
|---|
| 37 | PCUT_TEST(coord2_add)
|
|---|
| 38 | {
|
|---|
| 39 | gfx_coord2_t a, b;
|
|---|
| 40 | gfx_coord2_t d;
|
|---|
| 41 |
|
|---|
| 42 | a.x = 10;
|
|---|
| 43 | a.y = 11;
|
|---|
| 44 | b.x = 20;
|
|---|
| 45 | b.y = 22;
|
|---|
| 46 |
|
|---|
| 47 | gfx_coord2_add(&a, &b, &d);
|
|---|
| 48 |
|
|---|
| 49 | PCUT_ASSERT_INT_EQUALS(a.x + b.x, d.x);
|
|---|
| 50 | PCUT_ASSERT_INT_EQUALS(a.y + b.y, d.y);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | /** gfx_coord2_subtract should subtract two coordinate vectors */
|
|---|
| 54 | PCUT_TEST(coord2_subtract)
|
|---|
| 55 | {
|
|---|
| 56 | gfx_coord2_t a, b;
|
|---|
| 57 | gfx_coord2_t d;
|
|---|
| 58 |
|
|---|
| 59 | a.x = 10;
|
|---|
| 60 | a.y = 11;
|
|---|
| 61 | b.x = 20;
|
|---|
| 62 | b.y = 22;
|
|---|
| 63 |
|
|---|
| 64 | gfx_coord2_subtract(&a, &b, &d);
|
|---|
| 65 |
|
|---|
| 66 | PCUT_ASSERT_INT_EQUALS(a.x - b.x, d.x);
|
|---|
| 67 | PCUT_ASSERT_INT_EQUALS(a.y - b.y, d.y);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /** gfx_coord2_clip with point to lower-left of clipping rectangle */
|
|---|
| 71 | PCUT_TEST(coord2_clip_ll)
|
|---|
| 72 | {
|
|---|
| 73 | gfx_coord2_t p;
|
|---|
| 74 | gfx_coord2_t cp;
|
|---|
| 75 | gfx_rect_t rect;
|
|---|
| 76 |
|
|---|
| 77 | p.x = 1;
|
|---|
| 78 | p.y = 2;
|
|---|
| 79 |
|
|---|
| 80 | rect.p0.x = 3;
|
|---|
| 81 | rect.p0.y = 4;
|
|---|
| 82 | rect.p1.x = 5;
|
|---|
| 83 | rect.p1.y = 6;
|
|---|
| 84 |
|
|---|
| 85 | gfx_coord2_clip(&p, &rect, &cp);
|
|---|
| 86 |
|
|---|
| 87 | PCUT_ASSERT_INT_EQUALS(3, cp.x);
|
|---|
| 88 | PCUT_ASSERT_INT_EQUALS(4, cp.y);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | /** gfx_coord2_clip with point inside the clipping rectangle */
|
|---|
| 92 | PCUT_TEST(coord2_clip_mm)
|
|---|
| 93 | {
|
|---|
| 94 | gfx_coord2_t p;
|
|---|
| 95 | gfx_coord2_t cp;
|
|---|
| 96 | gfx_rect_t rect;
|
|---|
| 97 |
|
|---|
| 98 | p.x = 2;
|
|---|
| 99 | p.y = 3;
|
|---|
| 100 |
|
|---|
| 101 | rect.p0.x = 1;
|
|---|
| 102 | rect.p0.y = 2;
|
|---|
| 103 | rect.p1.x = 3;
|
|---|
| 104 | rect.p1.y = 4;
|
|---|
| 105 |
|
|---|
| 106 | gfx_coord2_clip(&p, &rect, &cp);
|
|---|
| 107 |
|
|---|
| 108 | PCUT_ASSERT_INT_EQUALS(2, cp.x);
|
|---|
| 109 | PCUT_ASSERT_INT_EQUALS(3, cp.y);
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /** gfx_coord2_clip with point to upper-right of clipping rectangle */
|
|---|
| 113 | PCUT_TEST(coord2_clip_hh)
|
|---|
| 114 | {
|
|---|
| 115 | gfx_coord2_t p;
|
|---|
| 116 | gfx_coord2_t cp;
|
|---|
| 117 | gfx_rect_t rect;
|
|---|
| 118 |
|
|---|
| 119 | p.x = 5;
|
|---|
| 120 | p.y = 6;
|
|---|
| 121 |
|
|---|
| 122 | rect.p0.x = 1;
|
|---|
| 123 | rect.p0.y = 2;
|
|---|
| 124 | rect.p1.x = 3;
|
|---|
| 125 | rect.p1.y = 4;
|
|---|
| 126 |
|
|---|
| 127 | gfx_coord2_clip(&p, &rect, &cp);
|
|---|
| 128 |
|
|---|
| 129 | PCUT_ASSERT_INT_EQUALS(2, cp.x);
|
|---|
| 130 | PCUT_ASSERT_INT_EQUALS(3, cp.y);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | /** gfx_coord2_project projects pixel from one rectangle to another */
|
|---|
| 134 | PCUT_TEST(coord2_project)
|
|---|
| 135 | {
|
|---|
| 136 | gfx_coord2_t a, d;
|
|---|
| 137 | gfx_rect_t srect, drect;
|
|---|
| 138 |
|
|---|
| 139 | srect.p0.x = 10;
|
|---|
| 140 | srect.p0.y = 10;
|
|---|
| 141 | srect.p1.x = 20 + 1;
|
|---|
| 142 | srect.p1.y = 20 + 1;
|
|---|
| 143 |
|
|---|
| 144 | drect.p0.x = 100;
|
|---|
| 145 | drect.p0.y = 100;
|
|---|
| 146 | drect.p1.x = 200 + 1;
|
|---|
| 147 | drect.p1.y = 200 + 1;
|
|---|
| 148 |
|
|---|
| 149 | a.x = 10;
|
|---|
| 150 | a.y = 10;
|
|---|
| 151 | gfx_coord2_project(&a, &srect, &drect, &d);
|
|---|
| 152 | PCUT_ASSERT_INT_EQUALS(100, d.x);
|
|---|
| 153 | PCUT_ASSERT_INT_EQUALS(100, d.y);
|
|---|
| 154 |
|
|---|
| 155 | a.x = 15;
|
|---|
| 156 | a.y = 15;
|
|---|
| 157 | gfx_coord2_project(&a, &srect, &drect, &d);
|
|---|
| 158 | PCUT_ASSERT_INT_EQUALS(150, d.x);
|
|---|
| 159 | PCUT_ASSERT_INT_EQUALS(150, d.y);
|
|---|
| 160 |
|
|---|
| 161 | a.x = 12;
|
|---|
| 162 | a.y = 16;
|
|---|
| 163 | gfx_coord2_project(&a, &srect, &drect, &d);
|
|---|
| 164 | PCUT_ASSERT_INT_EQUALS(120, d.x);
|
|---|
| 165 | PCUT_ASSERT_INT_EQUALS(160, d.y);
|
|---|
| 166 |
|
|---|
| 167 | a.x = 20;
|
|---|
| 168 | a.y = 20;
|
|---|
| 169 | gfx_coord2_project(&a, &srect, &drect, &d);
|
|---|
| 170 | PCUT_ASSERT_INT_EQUALS(200, d.x);
|
|---|
| 171 | PCUT_ASSERT_INT_EQUALS(200, d.y);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | /** gfx_rect_translate should translate rectangle */
|
|---|
| 175 | PCUT_TEST(rect_translate)
|
|---|
| 176 | {
|
|---|
| 177 | gfx_coord2_t offs;
|
|---|
| 178 | gfx_rect_t srect;
|
|---|
| 179 | gfx_rect_t drect;
|
|---|
| 180 |
|
|---|
| 181 | offs.x = 5;
|
|---|
| 182 | offs.y = 6;
|
|---|
| 183 |
|
|---|
| 184 | srect.p0.x = 10;
|
|---|
| 185 | srect.p0.y = 11;
|
|---|
| 186 | srect.p1.x = 20;
|
|---|
| 187 | srect.p1.y = 22;
|
|---|
| 188 |
|
|---|
| 189 | gfx_rect_translate(&offs, &srect, &drect);
|
|---|
| 190 |
|
|---|
| 191 | PCUT_ASSERT_INT_EQUALS(offs.x + srect.p0.x, drect.p0.x);
|
|---|
| 192 | PCUT_ASSERT_INT_EQUALS(offs.y + srect.p0.y, drect.p0.y);
|
|---|
| 193 | PCUT_ASSERT_INT_EQUALS(offs.x + srect.p1.x, drect.p1.x);
|
|---|
| 194 | PCUT_ASSERT_INT_EQUALS(offs.y + srect.p1.y, drect.p1.y);
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | /** gfx_rect_rtranslate should reverse-translate rectangle */
|
|---|
| 198 | PCUT_TEST(rect_rtranslate)
|
|---|
| 199 | {
|
|---|
| 200 | gfx_coord2_t offs;
|
|---|
| 201 | gfx_rect_t srect;
|
|---|
| 202 | gfx_rect_t drect;
|
|---|
| 203 |
|
|---|
| 204 | offs.x = 5;
|
|---|
| 205 | offs.y = 6;
|
|---|
| 206 |
|
|---|
| 207 | srect.p0.x = 10;
|
|---|
| 208 | srect.p0.y = 11;
|
|---|
| 209 | srect.p1.x = 20;
|
|---|
| 210 | srect.p1.y = 22;
|
|---|
| 211 |
|
|---|
| 212 | gfx_rect_rtranslate(&offs, &srect, &drect);
|
|---|
| 213 |
|
|---|
| 214 | PCUT_ASSERT_INT_EQUALS(srect.p0.x - offs.x, drect.p0.x);
|
|---|
| 215 | PCUT_ASSERT_INT_EQUALS(srect.p0.y - offs.y, drect.p0.y);
|
|---|
| 216 | PCUT_ASSERT_INT_EQUALS(srect.p1.x - offs.x, drect.p1.x);
|
|---|
| 217 | PCUT_ASSERT_INT_EQUALS(srect.p1.y - offs.y, drect.p1.y);
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | /** Sorting span with lower start and higher end point results in the same span. */
|
|---|
| 221 | PCUT_TEST(span_points_sort_asc)
|
|---|
| 222 | {
|
|---|
| 223 | gfx_coord_t a, b;
|
|---|
| 224 |
|
|---|
| 225 | gfx_span_points_sort(1, 2, &a, &b);
|
|---|
| 226 | PCUT_ASSERT_INT_EQUALS(1, a);
|
|---|
| 227 | PCUT_ASSERT_INT_EQUALS(2, b);
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | /** Sorting span with same start and end point results in the same span. */
|
|---|
| 231 | PCUT_TEST(span_points_sort_equal)
|
|---|
| 232 | {
|
|---|
| 233 | gfx_coord_t a, b;
|
|---|
| 234 |
|
|---|
| 235 | gfx_span_points_sort(1, 1, &a, &b);
|
|---|
| 236 | PCUT_ASSERT_INT_EQUALS(1, a);
|
|---|
| 237 | PCUT_ASSERT_INT_EQUALS(1, b);
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | /** Sorting span with hight start and lower end point results in transposed span. */
|
|---|
| 241 | PCUT_TEST(span_points_sort_decs)
|
|---|
| 242 | {
|
|---|
| 243 | gfx_coord_t a, b;
|
|---|
| 244 |
|
|---|
| 245 | gfx_span_points_sort(1, 0, &a, &b);
|
|---|
| 246 | PCUT_ASSERT_INT_EQUALS(1, a);
|
|---|
| 247 | PCUT_ASSERT_INT_EQUALS(2, b);
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | /** Rectangle envelope with first rectangle empty should return the second rectangle. */
|
|---|
| 251 | PCUT_TEST(rect_envelope_a_empty)
|
|---|
| 252 | {
|
|---|
| 253 | gfx_rect_t a;
|
|---|
| 254 | gfx_rect_t b;
|
|---|
| 255 | gfx_rect_t e;
|
|---|
| 256 |
|
|---|
| 257 | a.p0.x = 0;
|
|---|
| 258 | a.p0.y = 0;
|
|---|
| 259 | a.p1.x = 0;
|
|---|
| 260 | a.p1.y = 0;
|
|---|
| 261 |
|
|---|
| 262 | b.p0.x = 1;
|
|---|
| 263 | b.p0.y = 2;
|
|---|
| 264 | b.p1.x = 3;
|
|---|
| 265 | b.p1.y = 4;
|
|---|
| 266 |
|
|---|
| 267 | gfx_rect_envelope(&a, &b, &e);
|
|---|
| 268 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
|---|
| 269 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
|---|
| 270 | PCUT_ASSERT_INT_EQUALS(3, e.p1.x);
|
|---|
| 271 | PCUT_ASSERT_INT_EQUALS(4, e.p1.y);
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | /** Rectangle envelope with second rectangle empty should return the first rectangle. */
|
|---|
| 275 | PCUT_TEST(rect_envelope_b_empty)
|
|---|
| 276 | {
|
|---|
| 277 | gfx_rect_t a;
|
|---|
| 278 | gfx_rect_t b;
|
|---|
| 279 | gfx_rect_t e;
|
|---|
| 280 |
|
|---|
| 281 | a.p0.x = 1;
|
|---|
| 282 | a.p0.y = 2;
|
|---|
| 283 | a.p1.x = 3;
|
|---|
| 284 | a.p1.y = 4;
|
|---|
| 285 |
|
|---|
| 286 | b.p0.x = 0;
|
|---|
| 287 | b.p0.y = 0;
|
|---|
| 288 | b.p1.x = 0;
|
|---|
| 289 | b.p1.y = 0;
|
|---|
| 290 |
|
|---|
| 291 | gfx_rect_envelope(&a, &b, &e);
|
|---|
| 292 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
|---|
| 293 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
|---|
| 294 | PCUT_ASSERT_INT_EQUALS(3, e.p1.x);
|
|---|
| 295 | PCUT_ASSERT_INT_EQUALS(4, e.p1.y);
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 | /** Rectangle envelope, a has both coordinates lower than b */
|
|---|
| 299 | PCUT_TEST(rect_envelope_nonempty_a_lt_b)
|
|---|
| 300 | {
|
|---|
| 301 | gfx_rect_t a;
|
|---|
| 302 | gfx_rect_t b;
|
|---|
| 303 | gfx_rect_t e;
|
|---|
| 304 |
|
|---|
| 305 | a.p0.x = 1;
|
|---|
| 306 | a.p0.y = 2;
|
|---|
| 307 | a.p1.x = 3;
|
|---|
| 308 | a.p1.y = 4;
|
|---|
| 309 |
|
|---|
| 310 | b.p0.x = 5;
|
|---|
| 311 | b.p0.y = 6;
|
|---|
| 312 | b.p1.x = 7;
|
|---|
| 313 | b.p1.y = 8;
|
|---|
| 314 |
|
|---|
| 315 | gfx_rect_envelope(&a, &b, &e);
|
|---|
| 316 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
|---|
| 317 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
|---|
| 318 | PCUT_ASSERT_INT_EQUALS(7, e.p1.x);
|
|---|
| 319 | PCUT_ASSERT_INT_EQUALS(8, e.p1.y);
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | /** Rectangle envelope, a has both coordinates higher than b */
|
|---|
| 323 | PCUT_TEST(rect_envelope_nonempty_a_gt_b)
|
|---|
| 324 | {
|
|---|
| 325 | gfx_rect_t a;
|
|---|
| 326 | gfx_rect_t b;
|
|---|
| 327 | gfx_rect_t e;
|
|---|
| 328 |
|
|---|
| 329 | a.p0.x = 5;
|
|---|
| 330 | a.p0.y = 6;
|
|---|
| 331 | a.p1.x = 7;
|
|---|
| 332 | a.p1.y = 8;
|
|---|
| 333 |
|
|---|
| 334 | b.p0.x = 1;
|
|---|
| 335 | b.p0.y = 2;
|
|---|
| 336 | b.p1.x = 3;
|
|---|
| 337 | b.p1.y = 4;
|
|---|
| 338 |
|
|---|
| 339 | gfx_rect_envelope(&a, &b, &e);
|
|---|
| 340 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
|---|
| 341 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
|---|
| 342 | PCUT_ASSERT_INT_EQUALS(7, e.p1.x);
|
|---|
| 343 | PCUT_ASSERT_INT_EQUALS(8, e.p1.y);
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | /** Rectangle envelope, a is inside b */
|
|---|
| 347 | PCUT_TEST(rect_envelope_nonempty_a_inside_b)
|
|---|
| 348 | {
|
|---|
| 349 | gfx_rect_t a;
|
|---|
| 350 | gfx_rect_t b;
|
|---|
| 351 | gfx_rect_t e;
|
|---|
| 352 |
|
|---|
| 353 | a.p0.x = 1;
|
|---|
| 354 | a.p0.y = 2;
|
|---|
| 355 | a.p1.x = 7;
|
|---|
| 356 | a.p1.y = 8;
|
|---|
| 357 |
|
|---|
| 358 | b.p0.x = 3;
|
|---|
| 359 | b.p0.y = 4;
|
|---|
| 360 | b.p1.x = 5;
|
|---|
| 361 | b.p1.y = 6;
|
|---|
| 362 |
|
|---|
| 363 | gfx_rect_envelope(&a, &b, &e);
|
|---|
| 364 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
|---|
| 365 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
|---|
| 366 | PCUT_ASSERT_INT_EQUALS(7, e.p1.x);
|
|---|
| 367 | PCUT_ASSERT_INT_EQUALS(8, e.p1.y);
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | /** Rectangle envelope, b is inside a*/
|
|---|
| 371 | PCUT_TEST(rect_envelope_nonempty_b_inside_a)
|
|---|
| 372 | {
|
|---|
| 373 | gfx_rect_t a;
|
|---|
| 374 | gfx_rect_t b;
|
|---|
| 375 | gfx_rect_t e;
|
|---|
| 376 |
|
|---|
| 377 | a.p0.x = 3;
|
|---|
| 378 | a.p0.y = 4;
|
|---|
| 379 | a.p1.x = 5;
|
|---|
| 380 | a.p1.y = 6;
|
|---|
| 381 |
|
|---|
| 382 | b.p0.x = 1;
|
|---|
| 383 | b.p0.y = 2;
|
|---|
| 384 | b.p1.x = 7;
|
|---|
| 385 | b.p1.y = 8;
|
|---|
| 386 |
|
|---|
| 387 | gfx_rect_envelope(&a, &b, &e);
|
|---|
| 388 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
|---|
| 389 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
|---|
| 390 | PCUT_ASSERT_INT_EQUALS(7, e.p1.x);
|
|---|
| 391 | PCUT_ASSERT_INT_EQUALS(8, e.p1.y);
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | /** Rectangle envelope, a and b cross */
|
|---|
| 395 | PCUT_TEST(rect_envelope_nonempty_a_crosses_b)
|
|---|
| 396 | {
|
|---|
| 397 | gfx_rect_t a;
|
|---|
| 398 | gfx_rect_t b;
|
|---|
| 399 | gfx_rect_t e;
|
|---|
| 400 |
|
|---|
| 401 | a.p0.x = 1;
|
|---|
| 402 | a.p0.y = 2;
|
|---|
| 403 | a.p1.x = 4;
|
|---|
| 404 | a.p1.y = 3;
|
|---|
| 405 |
|
|---|
| 406 | b.p0.x = 2;
|
|---|
| 407 | b.p0.y = 1;
|
|---|
| 408 | b.p1.x = 3;
|
|---|
| 409 | b.p1.y = 4;
|
|---|
| 410 |
|
|---|
| 411 | gfx_rect_envelope(&a, &b, &e);
|
|---|
| 412 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
|---|
| 413 | PCUT_ASSERT_INT_EQUALS(1, e.p0.y);
|
|---|
| 414 | PCUT_ASSERT_INT_EQUALS(4, e.p1.x);
|
|---|
| 415 | PCUT_ASSERT_INT_EQUALS(4, e.p1.y);
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | /** Clip rectangle with rect completely inside the clipping rectangle */
|
|---|
| 419 | PCUT_TEST(rect_clip_rect_inside)
|
|---|
| 420 | {
|
|---|
| 421 | gfx_rect_t rect;
|
|---|
| 422 | gfx_rect_t clip;
|
|---|
| 423 | gfx_rect_t dest;
|
|---|
| 424 |
|
|---|
| 425 | rect.p0.x = 3;
|
|---|
| 426 | rect.p0.y = 4;
|
|---|
| 427 | rect.p1.x = 5;
|
|---|
| 428 | rect.p1.y = 6;
|
|---|
| 429 |
|
|---|
| 430 | clip.p0.x = 1;
|
|---|
| 431 | clip.p0.y = 2;
|
|---|
| 432 | clip.p1.x = 7;
|
|---|
| 433 | clip.p1.y = 8;
|
|---|
| 434 |
|
|---|
| 435 | gfx_rect_clip(&rect, &clip, &dest);
|
|---|
| 436 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
|---|
| 437 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
|---|
| 438 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
|---|
| 439 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | /** Clip rectangle with rect covering the clipping rectangle */
|
|---|
| 443 | PCUT_TEST(rect_clip_rect_covering)
|
|---|
| 444 | {
|
|---|
| 445 | gfx_rect_t rect;
|
|---|
| 446 | gfx_rect_t clip;
|
|---|
| 447 | gfx_rect_t dest;
|
|---|
| 448 |
|
|---|
| 449 | rect.p0.x = 1;
|
|---|
| 450 | rect.p0.y = 2;
|
|---|
| 451 | rect.p1.x = 7;
|
|---|
| 452 | rect.p1.y = 8;
|
|---|
| 453 |
|
|---|
| 454 | clip.p0.x = 3;
|
|---|
| 455 | clip.p0.y = 4;
|
|---|
| 456 | clip.p1.x = 5;
|
|---|
| 457 | clip.p1.y = 6;
|
|---|
| 458 |
|
|---|
| 459 | gfx_rect_clip(&rect, &clip, &dest);
|
|---|
| 460 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
|---|
| 461 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
|---|
| 462 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
|---|
| 463 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | /** Clip rectangle with rect outside, having lower coordinates */
|
|---|
| 467 | PCUT_TEST(rect_clip_rect_out_ll)
|
|---|
| 468 | {
|
|---|
| 469 | gfx_rect_t rect;
|
|---|
| 470 | gfx_rect_t clip;
|
|---|
| 471 | gfx_rect_t dest;
|
|---|
| 472 |
|
|---|
| 473 | rect.p0.x = 1;
|
|---|
| 474 | rect.p0.y = 2;
|
|---|
| 475 | rect.p1.x = 3;
|
|---|
| 476 | rect.p1.y = 4;
|
|---|
| 477 |
|
|---|
| 478 | clip.p0.x = 5;
|
|---|
| 479 | clip.p0.y = 6;
|
|---|
| 480 | clip.p1.x = 7;
|
|---|
| 481 | clip.p1.y = 8;
|
|---|
| 482 |
|
|---|
| 483 | gfx_rect_clip(&rect, &clip, &dest);
|
|---|
| 484 | PCUT_ASSERT_INT_EQUALS(5, dest.p0.x);
|
|---|
| 485 | PCUT_ASSERT_INT_EQUALS(6, dest.p0.y);
|
|---|
| 486 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
|---|
| 487 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | /** Clip rectangle with rect outside, having higher coordinates */
|
|---|
| 491 | PCUT_TEST(rect_clip_rect_out_hh)
|
|---|
| 492 | {
|
|---|
| 493 | gfx_rect_t rect;
|
|---|
| 494 | gfx_rect_t clip;
|
|---|
| 495 | gfx_rect_t dest;
|
|---|
| 496 |
|
|---|
| 497 | rect.p0.x = 5;
|
|---|
| 498 | rect.p0.y = 6;
|
|---|
| 499 | rect.p1.x = 7;
|
|---|
| 500 | rect.p1.y = 8;
|
|---|
| 501 |
|
|---|
| 502 | clip.p0.x = 1;
|
|---|
| 503 | clip.p0.y = 2;
|
|---|
| 504 | clip.p1.x = 3;
|
|---|
| 505 | clip.p1.y = 4;
|
|---|
| 506 |
|
|---|
| 507 | gfx_rect_clip(&rect, &clip, &dest);
|
|---|
| 508 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
|---|
| 509 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
|---|
| 510 | PCUT_ASSERT_INT_EQUALS(3, dest.p1.x);
|
|---|
| 511 | PCUT_ASSERT_INT_EQUALS(4, dest.p1.y);
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | /** Clip rectangle with rect partially outside, having lower coordinates */
|
|---|
| 515 | PCUT_TEST(rect_clip_rect_ll)
|
|---|
| 516 | {
|
|---|
| 517 | gfx_rect_t rect;
|
|---|
| 518 | gfx_rect_t clip;
|
|---|
| 519 | gfx_rect_t dest;
|
|---|
| 520 |
|
|---|
| 521 | rect.p0.x = 1;
|
|---|
| 522 | rect.p0.y = 2;
|
|---|
| 523 | rect.p1.x = 5;
|
|---|
| 524 | rect.p1.y = 6;
|
|---|
| 525 |
|
|---|
| 526 | clip.p0.x = 3;
|
|---|
| 527 | clip.p0.y = 4;
|
|---|
| 528 | clip.p1.x = 7;
|
|---|
| 529 | clip.p1.y = 8;
|
|---|
| 530 |
|
|---|
| 531 | gfx_rect_clip(&rect, &clip, &dest);
|
|---|
| 532 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
|---|
| 533 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
|---|
| 534 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
|---|
| 535 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | /** Clip rectangle with rect partially outside, having higher coordinates */
|
|---|
| 539 | PCUT_TEST(rect_clip_rect_hh)
|
|---|
| 540 | {
|
|---|
| 541 | gfx_rect_t rect;
|
|---|
| 542 | gfx_rect_t clip;
|
|---|
| 543 | gfx_rect_t dest;
|
|---|
| 544 |
|
|---|
| 545 | rect.p0.x = 3;
|
|---|
| 546 | rect.p0.y = 4;
|
|---|
| 547 | rect.p1.x = 7;
|
|---|
| 548 | rect.p1.y = 8;
|
|---|
| 549 |
|
|---|
| 550 | clip.p0.x = 1;
|
|---|
| 551 | clip.p0.y = 2;
|
|---|
| 552 | clip.p1.x = 5;
|
|---|
| 553 | clip.p1.y = 6;
|
|---|
| 554 |
|
|---|
| 555 | gfx_rect_clip(&rect, &clip, &dest);
|
|---|
| 556 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
|---|
| 557 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
|---|
| 558 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
|---|
| 559 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | /** Sort span points that are already sorted should produde indentical points */
|
|---|
| 563 | PCUT_TEST(rect_points_sort_sorted)
|
|---|
| 564 | {
|
|---|
| 565 | gfx_coord_t s0, s1;
|
|---|
| 566 |
|
|---|
| 567 | gfx_span_points_sort(1, 2, &s0, &s1);
|
|---|
| 568 | PCUT_ASSERT_INT_EQUALS(1, s0);
|
|---|
| 569 | PCUT_ASSERT_INT_EQUALS(2, s1);
|
|---|
| 570 | }
|
|---|
| 571 |
|
|---|
| 572 | /** Sort span points that are reversed should transpose them */
|
|---|
| 573 | PCUT_TEST(rect_points_sort_reversed)
|
|---|
| 574 | {
|
|---|
| 575 | gfx_coord_t s0, s1;
|
|---|
| 576 |
|
|---|
| 577 | gfx_span_points_sort(2, 1, &s0, &s1);
|
|---|
| 578 | PCUT_ASSERT_INT_EQUALS(2, s0);
|
|---|
| 579 | PCUT_ASSERT_INT_EQUALS(3, s1);
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | /** gfx_rect_is_empty for straight rectangle with zero columns returns true */
|
|---|
| 583 | PCUT_TEST(rect_is_empty_pos_x)
|
|---|
| 584 | {
|
|---|
| 585 | gfx_rect_t rect;
|
|---|
| 586 |
|
|---|
| 587 | rect.p0.x = 1;
|
|---|
| 588 | rect.p0.y = 2;
|
|---|
| 589 | rect.p1.x = 1;
|
|---|
| 590 | rect.p1.y = 3;
|
|---|
| 591 | PCUT_ASSERT_TRUE(gfx_rect_is_empty(&rect));
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | /** gfx_rect_is_empty for straight rectangle with zero rows returns true */
|
|---|
| 595 | PCUT_TEST(rect_is_empty_pos_y)
|
|---|
| 596 | {
|
|---|
| 597 | gfx_rect_t rect;
|
|---|
| 598 |
|
|---|
| 599 | rect.p0.x = 1;
|
|---|
| 600 | rect.p0.y = 2;
|
|---|
| 601 | rect.p1.x = 2;
|
|---|
| 602 | rect.p1.y = 2;
|
|---|
| 603 | PCUT_ASSERT_TRUE(gfx_rect_is_empty(&rect));
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | /** gfx_rect_is_empty for staright non-empty rectangle returns false */
|
|---|
| 607 | PCUT_TEST(rect_is_empty_neg)
|
|---|
| 608 | {
|
|---|
| 609 | gfx_rect_t rect;
|
|---|
| 610 |
|
|---|
| 611 | rect.p0.x = 1;
|
|---|
| 612 | rect.p0.y = 2;
|
|---|
| 613 | rect.p1.x = 2;
|
|---|
| 614 | rect.p1.y = 3;
|
|---|
| 615 | PCUT_ASSERT_FALSE(gfx_rect_is_empty(&rect));
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | /** gfx_rect_is_empty for reverse non-empty rectangle returns false */
|
|---|
| 619 | PCUT_TEST(rect_is_empty_reverse_neg)
|
|---|
| 620 | {
|
|---|
| 621 | gfx_rect_t rect;
|
|---|
| 622 |
|
|---|
| 623 | rect.p0.x = 1;
|
|---|
| 624 | rect.p0.y = 2;
|
|---|
| 625 | rect.p1.x = 0;
|
|---|
| 626 | rect.p1.y = 1;
|
|---|
| 627 | PCUT_ASSERT_FALSE(gfx_rect_is_empty(&rect));
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | /** gfx_pix_inside_rect for */
|
|---|
| 631 | PCUT_TEST(pix_inside_rect)
|
|---|
| 632 | {
|
|---|
| 633 | gfx_coord2_t coord;
|
|---|
| 634 | gfx_rect_t rect;
|
|---|
| 635 |
|
|---|
| 636 | rect.p0.x = 1;
|
|---|
| 637 | rect.p0.y = 2;
|
|---|
| 638 | rect.p1.x = 3;
|
|---|
| 639 | rect.p1.y = 4;
|
|---|
| 640 |
|
|---|
| 641 | coord.x = 0;
|
|---|
| 642 | coord.y = 1;
|
|---|
| 643 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
|---|
| 644 |
|
|---|
| 645 | coord.x = 1;
|
|---|
| 646 | coord.y = 1;
|
|---|
| 647 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
|---|
| 648 |
|
|---|
| 649 | coord.x = 0;
|
|---|
| 650 | coord.y = 2;
|
|---|
| 651 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
|---|
| 652 |
|
|---|
| 653 | coord.x = 1;
|
|---|
| 654 | coord.y = 2;
|
|---|
| 655 | PCUT_ASSERT_TRUE(gfx_pix_inside_rect(&coord, &rect));
|
|---|
| 656 |
|
|---|
| 657 | coord.x = 2;
|
|---|
| 658 | coord.y = 3;
|
|---|
| 659 | PCUT_ASSERT_TRUE(gfx_pix_inside_rect(&coord, &rect));
|
|---|
| 660 |
|
|---|
| 661 | coord.x = 3;
|
|---|
| 662 | coord.y = 3;
|
|---|
| 663 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
|---|
| 664 |
|
|---|
| 665 | coord.x = 2;
|
|---|
| 666 | coord.y = 4;
|
|---|
| 667 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
|---|
| 668 |
|
|---|
| 669 | coord.x = 3;
|
|---|
| 670 | coord.y = 4;
|
|---|
| 671 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
|---|
| 672 | }
|
|---|
| 673 |
|
|---|
| 674 | PCUT_EXPORT(coord);
|
|---|