partial-coverage.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * Copyright 2010 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * Author: Chris Wilson <chris@chris-wilson.co.uk>
  25. */
  26. #include "cairo-test.h"
  27. /* Test the sampling stratagems of the rasterisers by creating pixels
  28. * containing minute holes and seeing how close to the expected
  29. * coverage each rasteriser approaches.
  30. */
  31. #define SIZE 64
  32. #include "../src/cairo-fixed-type-private.h"
  33. #define SAMPLE (1 << CAIRO_FIXED_FRAC_BITS)
  34. static uint32_t state;
  35. static uint32_t
  36. hars_petruska_f54_1_random (void)
  37. {
  38. #define rol(x,k) ((x << k) | (x >> (32-k)))
  39. return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
  40. #undef rol
  41. }
  42. static double
  43. uniform_random (void)
  44. {
  45. return hars_petruska_f54_1_random() / (double) UINT32_MAX;
  46. }
  47. /* coverage is given in [0,sample] */
  48. static void
  49. compute_occupancy (uint8_t *occupancy, int coverage, int sample)
  50. {
  51. int i, c;
  52. if (coverage < sample/2) {
  53. memset (occupancy, 0, sample);
  54. if (coverage == 0)
  55. return;
  56. for (i = c = 0; i < sample; i++) {
  57. if ((sample - i) * uniform_random() < coverage - c) {
  58. occupancy[i] = 0xff;
  59. if (++c == coverage)
  60. return;
  61. }
  62. }
  63. } else {
  64. coverage = sample - coverage;
  65. memset (occupancy, 0xff, sample);
  66. if (coverage == 0)
  67. return;
  68. for (i = c = 0; i < sample; i++) {
  69. if ((sample - i) * uniform_random() < coverage - c) {
  70. occupancy[i] = 0;
  71. if (++c == coverage)
  72. return;
  73. }
  74. }
  75. }
  76. }
  77. static cairo_test_status_t
  78. reference (cairo_t *cr, int width, int height)
  79. {
  80. int i;
  81. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  82. cairo_paint (cr);
  83. for (i = 0; i < SIZE*SIZE; i++) {
  84. cairo_set_source_rgba (cr, 1., 1., 1.,
  85. i / (double) (SIZE * SIZE));
  86. cairo_rectangle (cr, i % SIZE, i / SIZE, 1, 1);
  87. cairo_fill (cr);
  88. }
  89. return CAIRO_STATUS_SUCCESS;
  90. }
  91. static cairo_test_status_t
  92. three_quarter_reference (cairo_t *cr, int width, int height)
  93. {
  94. int i;
  95. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  96. cairo_paint (cr);
  97. for (i = 0; i < SIZE*SIZE; i++) {
  98. cairo_set_source_rgba (cr, 1., 1., 1.,
  99. .75 * i / (double) (SIZE * SIZE));
  100. cairo_rectangle (cr, i % SIZE, i / SIZE, 1, 1);
  101. cairo_fill (cr);
  102. }
  103. return CAIRO_STATUS_SUCCESS;
  104. }
  105. static cairo_test_status_t
  106. half_reference (cairo_t *cr, int width, int height)
  107. {
  108. int i;
  109. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  110. cairo_paint (cr);
  111. for (i = 0; i < SIZE*SIZE; i++) {
  112. cairo_set_source_rgba (cr, 1., 1., 1.,
  113. .5 * i / (double) (SIZE * SIZE));
  114. cairo_rectangle (cr, i % SIZE, i / SIZE, 1, 1);
  115. cairo_fill (cr);
  116. }
  117. return CAIRO_STATUS_SUCCESS;
  118. }
  119. static cairo_test_status_t
  120. rectangles (cairo_t *cr, int width, int height)
  121. {
  122. uint8_t *occupancy;
  123. int i, j, channel;
  124. state = 0x12345678;
  125. occupancy = xmalloc (SAMPLE*SAMPLE);
  126. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  127. cairo_paint (cr);
  128. cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  129. for (channel = 0; channel < 3; channel++) {
  130. switch (channel) {
  131. default:
  132. case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
  133. case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
  134. case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
  135. }
  136. for (i = 0; i < SIZE*SIZE; i++) {
  137. int xs, ys;
  138. compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE);
  139. xs = i % SIZE * SAMPLE;
  140. ys = i / SIZE * SAMPLE;
  141. for (j = 0; j < SAMPLE*SAMPLE; j++) {
  142. if (occupancy[j]) {
  143. cairo_rectangle (cr,
  144. (j % SAMPLE + xs) / (double) SAMPLE,
  145. (j / SAMPLE + ys) / (double) SAMPLE,
  146. 1 / (double) SAMPLE,
  147. 1 / (double) SAMPLE);
  148. }
  149. }
  150. cairo_fill (cr);
  151. }
  152. }
  153. free (occupancy);
  154. return CAIRO_TEST_SUCCESS;
  155. }
  156. static cairo_test_status_t
  157. intersecting_quads (cairo_t *cr, int width, int height)
  158. {
  159. uint8_t *occupancy;
  160. int i, j, channel;
  161. state = 0x12345678;
  162. occupancy = xmalloc (SAMPLE*SAMPLE);
  163. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  164. cairo_paint (cr);
  165. cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  166. for (channel = 0; channel < 3; channel++) {
  167. switch (channel) {
  168. default:
  169. case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
  170. case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
  171. case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
  172. }
  173. for (i = 0; i < SIZE*SIZE; i++) {
  174. int xs, ys;
  175. compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE);
  176. xs = i % SIZE * SAMPLE;
  177. ys = i / SIZE * SAMPLE;
  178. for (j = 0; j < SAMPLE*SAMPLE; j++) {
  179. if (occupancy[j]) {
  180. cairo_move_to (cr,
  181. (j % SAMPLE + xs) / (double) SAMPLE,
  182. (j / SAMPLE + ys) / (double) SAMPLE);
  183. cairo_rel_line_to (cr, 1 / (double) SAMPLE, 1 / (double) SAMPLE);
  184. cairo_rel_line_to (cr, 0, -1 / (double) SAMPLE);
  185. cairo_rel_line_to (cr, -1 / (double) SAMPLE, 1 / (double) SAMPLE);
  186. cairo_close_path (cr);
  187. }
  188. }
  189. cairo_fill (cr);
  190. }
  191. }
  192. free (occupancy);
  193. return CAIRO_TEST_SUCCESS;
  194. }
  195. static cairo_test_status_t
  196. half_triangles (cairo_t *cr, int width, int height)
  197. {
  198. uint8_t *occupancy;
  199. int i, j, channel;
  200. state = 0x12345678;
  201. occupancy = xmalloc (SAMPLE*SAMPLE);
  202. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  203. cairo_paint (cr);
  204. cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  205. for (channel = 0; channel < 3; channel++) {
  206. switch (channel) {
  207. default:
  208. case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
  209. case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
  210. case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
  211. }
  212. for (i = 0; i < SIZE*SIZE; i++) {
  213. int xs, ys;
  214. compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE);
  215. xs = i % SIZE * SAMPLE;
  216. ys = i / SIZE * SAMPLE;
  217. for (j = 0; j < SAMPLE*SAMPLE; j++) {
  218. if (occupancy[j]) {
  219. int x = j % SAMPLE + xs;
  220. int y = j / SAMPLE + ys;
  221. cairo_move_to (cr, x / (double) SAMPLE, y / (double) SAMPLE);
  222. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  223. cairo_line_to (cr, (x+1) / (double) SAMPLE, y / (double) SAMPLE);
  224. cairo_close_path (cr);
  225. }
  226. }
  227. cairo_fill (cr);
  228. }
  229. }
  230. free (occupancy);
  231. return CAIRO_TEST_SUCCESS;
  232. }
  233. static cairo_test_status_t
  234. overlap_half_triangles (cairo_t *cr, int width, int height)
  235. {
  236. uint8_t *occupancy;
  237. int i, j, channel;
  238. state = 0x12345678;
  239. occupancy = xmalloc (SAMPLE*SAMPLE);
  240. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  241. cairo_paint (cr);
  242. cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  243. for (channel = 0; channel < 3; channel++) {
  244. switch (channel) {
  245. default:
  246. case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
  247. case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
  248. case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
  249. }
  250. for (i = 0; i < SIZE*SIZE; i++) {
  251. int xs, ys;
  252. compute_occupancy (occupancy, SAMPLE/2*SAMPLE/2 * i / (SIZE * SIZE), SAMPLE/2*SAMPLE/2);
  253. xs = i % SIZE * SAMPLE;
  254. ys = i / SIZE * SAMPLE;
  255. for (j = 0; j < SAMPLE/2*SAMPLE/2; j++) {
  256. if (occupancy[j]) {
  257. int x = 2 * (j % (SAMPLE/2)) + xs;
  258. int y = 2 * (j / (SAMPLE/2)) + ys;
  259. /* Add a 4-tile composed of two overlapping triangles.
  260. * .__.__.
  261. * |\ /|
  262. * | \ / |
  263. * . x |
  264. * | / \ |
  265. * |/ \|
  266. * . .
  267. *
  268. * Coverage should be computable as 50% (due to counter-winding).
  269. */
  270. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  271. cairo_line_to (cr, (x) / (double) SAMPLE, (y+2) / (double) SAMPLE);
  272. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE);
  273. cairo_close_path (cr);
  274. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  275. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE);
  276. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y+2) / (double) SAMPLE);
  277. cairo_close_path (cr);
  278. }
  279. }
  280. cairo_fill (cr);
  281. }
  282. }
  283. free (occupancy);
  284. return CAIRO_TEST_SUCCESS;
  285. }
  286. static cairo_test_status_t
  287. overlap_half_triangles_eo (cairo_t *cr, int width, int height)
  288. {
  289. uint8_t *occupancy;
  290. int i, j, channel;
  291. state = 0x12345678;
  292. occupancy = xmalloc (SAMPLE*SAMPLE);
  293. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  294. cairo_paint (cr);
  295. cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
  296. cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  297. for (channel = 0; channel < 3; channel++) {
  298. switch (channel) {
  299. default:
  300. case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
  301. case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
  302. case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
  303. }
  304. for (i = 0; i < SIZE*SIZE; i++) {
  305. int xs, ys;
  306. compute_occupancy (occupancy, SAMPLE/2*SAMPLE/2 * i / (SIZE * SIZE), SAMPLE/2*SAMPLE/2);
  307. xs = i % SIZE * SAMPLE;
  308. ys = i / SIZE * SAMPLE;
  309. for (j = 0; j < SAMPLE/2*SAMPLE/2; j++) {
  310. if (occupancy[j]) {
  311. int x = 2 * (j % (SAMPLE/2)) + xs;
  312. int y = 2 * (j / (SAMPLE/2)) + ys;
  313. /* Add a 4-tile composed of two overlapping triangles.
  314. * .__.__.
  315. * |\ /|
  316. * | \ / |
  317. * . x |
  318. * | / \ |
  319. * |/ \|
  320. * . .
  321. *
  322. * Coverage should be computable as 50%, due to even-odd fill rule.
  323. */
  324. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  325. cairo_line_to (cr, (x) / (double) SAMPLE, (y+2) / (double) SAMPLE);
  326. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE);
  327. cairo_close_path (cr);
  328. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  329. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y+2) / (double) SAMPLE);
  330. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE);
  331. cairo_close_path (cr);
  332. }
  333. }
  334. cairo_fill (cr);
  335. }
  336. }
  337. free (occupancy);
  338. return CAIRO_TEST_SUCCESS;
  339. }
  340. static cairo_test_status_t
  341. overlap_three_quarter_triangles (cairo_t *cr, int width, int height)
  342. {
  343. uint8_t *occupancy;
  344. int i, j, channel;
  345. state = 0x12345678;
  346. occupancy = xmalloc (SAMPLE*SAMPLE);
  347. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  348. cairo_paint (cr);
  349. cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  350. for (channel = 0; channel < 3; channel++) {
  351. switch (channel) {
  352. default:
  353. case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
  354. case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
  355. case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
  356. }
  357. for (i = 0; i < SIZE*SIZE; i++) {
  358. int xs, ys;
  359. compute_occupancy (occupancy, SAMPLE/2*SAMPLE/2 * i / (SIZE * SIZE), SAMPLE/2*SAMPLE/2);
  360. xs = i % SIZE * SAMPLE;
  361. ys = i / SIZE * SAMPLE;
  362. for (j = 0; j < SAMPLE/2*SAMPLE/2; j++) {
  363. if (occupancy[j]) {
  364. int x = 2 * (j % (SAMPLE/2)) + xs;
  365. int y = 2 * (j / (SAMPLE/2)) + ys;
  366. /* Add a 4-tile composed of two overlapping triangles.
  367. * .__.__.
  368. * |\ /|
  369. * | \ / |
  370. * . x |
  371. * | / \ |
  372. * |/ \|
  373. * . .
  374. *
  375. * Coverage should be computable as 75%.
  376. */
  377. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  378. cairo_line_to (cr, (x) / (double) SAMPLE, (y+2) / (double) SAMPLE);
  379. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE);
  380. cairo_close_path (cr);
  381. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  382. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y+2) / (double) SAMPLE);
  383. cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE);
  384. cairo_close_path (cr);
  385. }
  386. }
  387. cairo_fill (cr);
  388. }
  389. }
  390. free (occupancy);
  391. return CAIRO_TEST_SUCCESS;
  392. }
  393. static cairo_test_status_t
  394. triangles (cairo_t *cr, int width, int height)
  395. {
  396. uint8_t *occupancy;
  397. int i, j, channel;
  398. state = 0x12345678;
  399. occupancy = xmalloc (SAMPLE*SAMPLE);
  400. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  401. cairo_paint (cr);
  402. cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  403. for (channel = 0; channel < 3; channel++) {
  404. switch (channel) {
  405. default:
  406. case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
  407. case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
  408. case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
  409. }
  410. for (i = 0; i < SIZE*SIZE; i++) {
  411. int xs, ys;
  412. compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE);
  413. xs = i % SIZE * SAMPLE;
  414. ys = i / SIZE * SAMPLE;
  415. for (j = 0; j < SAMPLE*SAMPLE; j++) {
  416. if (occupancy[j]) {
  417. /* Add a tile composed of two non-overlapping triangles.
  418. * .__.
  419. * | /|
  420. * |/ |
  421. * .--.
  422. */
  423. int x = j % SAMPLE + xs;
  424. int y = j / SAMPLE + ys;
  425. /* top-left triangle */
  426. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  427. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE);
  428. cairo_line_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  429. cairo_close_path (cr);
  430. /* bottom-right triangle */
  431. cairo_move_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  432. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  433. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE);
  434. cairo_close_path (cr);
  435. }
  436. }
  437. cairo_fill (cr);
  438. }
  439. }
  440. free (occupancy);
  441. return CAIRO_TEST_SUCCESS;
  442. }
  443. static cairo_test_status_t
  444. intersecting_triangles (cairo_t *cr, int width, int height)
  445. {
  446. uint8_t *occupancy;
  447. int i, j, channel;
  448. state = 0x12345678;
  449. occupancy = xmalloc (SAMPLE*SAMPLE);
  450. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  451. cairo_paint (cr);
  452. cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  453. for (channel = 0; channel < 3; channel++) {
  454. switch (channel) {
  455. default:
  456. case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
  457. case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
  458. case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
  459. }
  460. for (i = 0; i < SIZE*SIZE; i++) {
  461. int xs, ys;
  462. compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE);
  463. xs = i % SIZE * SAMPLE;
  464. ys = i / SIZE * SAMPLE;
  465. for (j = 0; j < SAMPLE*SAMPLE; j++) {
  466. if (occupancy[j]) {
  467. /* Add 2 overlapping tiles in a single cell, each composed
  468. * of two non-overlapping triangles.
  469. * .--. .--.
  470. * | /| |\ |
  471. * |/ | + | \|
  472. * .--. .--.
  473. */
  474. int x = j % SAMPLE + xs;
  475. int y = j / SAMPLE + ys;
  476. /* first pair of triangles, diagonal bottom-left to top-right */
  477. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  478. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE);
  479. cairo_line_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  480. cairo_close_path (cr);
  481. cairo_move_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  482. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  483. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE);
  484. cairo_close_path (cr);
  485. /* second pair of triangles, diagonal top-left to bottom-right */
  486. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  487. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  488. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE);
  489. cairo_close_path (cr);
  490. cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE);
  491. cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  492. cairo_line_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE);
  493. cairo_close_path (cr);
  494. }
  495. }
  496. cairo_fill (cr);
  497. }
  498. }
  499. free (occupancy);
  500. return CAIRO_TEST_SUCCESS;
  501. }
  502. CAIRO_TEST (partial_coverage_rectangles,
  503. "Check the fidelity of the rasterisation.",
  504. "coverage, raster", /* keywords */
  505. "target=raster slow", /* requirements */
  506. SIZE, SIZE,
  507. NULL, rectangles)
  508. CAIRO_TEST (partial_coverage_intersecting_quads,
  509. "Check the fidelity of the rasterisation.",
  510. "coverage, raster", /* keywords */
  511. "target=raster slow", /* requirements */
  512. SIZE, SIZE,
  513. NULL, intersecting_quads)
  514. CAIRO_TEST (partial_coverage_intersecting_triangles,
  515. "Check the fidelity of the rasterisation.",
  516. "coverage, raster", /* keywords */
  517. "target=raster slow", /* requirements */
  518. SIZE, SIZE,
  519. NULL, intersecting_triangles)
  520. CAIRO_TEST (partial_coverage_triangles,
  521. "Check the fidelity of the rasterisation.",
  522. "coverage, raster", /* keywords */
  523. "target=raster slow", /* requirements */
  524. SIZE, SIZE,
  525. NULL, triangles)
  526. CAIRO_TEST (partial_coverage_overlap_three_quarter_triangles,
  527. "Check the fidelity of the rasterisation.",
  528. "coverage, raster", /* keywords */
  529. "target=raster slow", /* requirements */
  530. SIZE, SIZE,
  531. NULL, overlap_three_quarter_triangles)
  532. CAIRO_TEST (partial_coverage_overlap_half_triangles_eo,
  533. "Check the fidelity of the rasterisation.",
  534. "coverage, raster", /* keywords */
  535. "target=raster slow", /* requirements */
  536. SIZE, SIZE,
  537. NULL, overlap_half_triangles_eo)
  538. CAIRO_TEST (partial_coverage_overlap_half_triangles,
  539. "Check the fidelity of the rasterisation.",
  540. "coverage, raster", /* keywords */
  541. "target=raster slow", /* requirements */
  542. SIZE, SIZE,
  543. NULL, overlap_half_triangles)
  544. CAIRO_TEST (partial_coverage_half_triangles,
  545. "Check the fidelity of the rasterisation.",
  546. "coverage, raster", /* keywords */
  547. "target=raster slow", /* requirements */
  548. SIZE, SIZE,
  549. NULL, half_triangles)
  550. CAIRO_TEST (partial_coverage_reference,
  551. "Check the fidelity of this test.",
  552. "coverage, raster", /* keywords */
  553. "target=raster", /* requirements */
  554. SIZE, SIZE,
  555. NULL, reference)
  556. CAIRO_TEST (partial_coverage_three_quarter_reference,
  557. "Check the fidelity of this test.",
  558. "coverage, raster", /* keywords */
  559. "target=raster", /* requirements */
  560. SIZE, SIZE,
  561. NULL, three_quarter_reference)
  562. CAIRO_TEST (partial_coverage_half_reference,
  563. "Check the fidelity of this test.",
  564. "coverage, raster", /* keywords */
  565. "target=raster", /* requirements */
  566. SIZE, SIZE,
  567. NULL, half_reference)