1 /*
2 * Copyright (c) 2014 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "kis_fill_interval_map_test.h"
20
21 #include <QTest>
22
23 #include <floodfill/kis_fill_interval_map.h>
24 #include <floodfill/kis_fill_interval_map_p.h>
25
test()26 void KisFillIntervalMapTest::test()
27 {
28 const int row = 1;
29
30 KisFillInterval i1( 0, 40, row);
31 KisFillInterval i2(11, 40, row);
32 KisFillInterval i3(11, 19, row);
33 KisFillInterval i4(11, 20, row);
34
35 KisFillIntervalMap map;
36
37 // 0..10, 20..30, 40..50, ...
38 for (int i = 0; i < 100; i += 20) {
39 map.insertInterval(KisFillInterval(i, i + 10, row));
40 }
41
42 KisFillIntervalMap::Private::IteratorRange range;
43
44 range = map.m_d->findFirstIntersectingInterval(i1);
45 QCOMPARE(range.beginIt->start, 0);
46 QCOMPARE(range.beginIt->end, 10);
47
48 range = map.m_d->findFirstIntersectingInterval(i2);
49 QCOMPARE(range.beginIt->start, 20);
50 QCOMPARE(range.beginIt->end, 30);
51
52 range = map.m_d->findFirstIntersectingInterval(i3);
53 QCOMPARE(range.beginIt, range.endIt);
54
55 range = map.m_d->findFirstIntersectingInterval(i4);
56 QCOMPARE(range.beginIt->start, 20);
57 QCOMPARE(range.beginIt->end, 30);
58 }
59
60 QTEST_MAIN(KisFillIntervalMapTest)
61