1 /*
2  *  Copyright (c) 2007 Boudewijn Rempt <boud@valdyas.org>
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_image_view_converter_test.h"
20 #include <QApplication>
21 
22 #include <kis_debug.h>
23 #include <QTest>
24 #include <KoColorSpace.h>
25 #include <KoColorSpaceRegistry.h>
26 
27 #include "kis_image_view_converter.h"
28 #include "kis_paint_device.h"
29 #include "kis_image.h"
30 #include "kis_types.h"
31 
testDocumentToView()32 void KisImageViewConverterTest::testDocumentToView()
33 {
34     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
35     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "test");
36     KisImageViewConverter viewConverter(image);
37 
38     image->setResolution(1.38888888, 1.38888888);
39 
40     QVERIFY(viewConverter.documentToView(QPointF(0.0, 0.0))
41             == QPointF(0.0, 0.0));
42 
43     QPointF f = viewConverter.documentToView(QPointF(3.2, 5.2));
44     QVERIFY(f.x() < 4.44445 && f.x() > 4.44443 && f.y() < 7.22223 && f.y() > 7.22221);
45 
46     QRectF r = viewConverter.documentToView(QRectF(0.0, 0.0, 10.0, 10.0));
47     QVERIFY(r.width() < 13.889 && r.width() > 13.8888
48             && r.height() < 13.889 && r.height() > 13.8888);
49 
50     QSizeF s = viewConverter.documentToView(QSizeF(1.0, 1.0));
51     QVERIFY(s.width() < 1.3888889 && s.width() > 1.388887
52             && s.height() < 1.3888889 && s.height() > 1.388887);
53 
54     double x = viewConverter.documentToViewX(1.0);
55     QVERIFY(x < 1.3888889 && x > 1.388887);
56 
57     double y = viewConverter.documentToViewY(1.0);
58     QVERIFY(y < 1.3888889 && y > 1.388887);
59 
60 }
61 
testViewToDocument()62 void KisImageViewConverterTest::testViewToDocument()
63 {
64     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
65     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "test");
66     KisImageViewConverter viewConverter(image);
67 
68     image->setResolution(1.38888888, 1.38888888);
69 
70     QVERIFY(viewConverter.viewToDocument(QPointF(0.0, 0.0))
71             == QPointF(0.0, 0.0));
72 
73     QPointF f = viewConverter.viewToDocument(QPointF(5, 5));
74     QVERIFY(f.x() < 3.7 && f.x() > 3.5 && f.y() < 3.7 && f.y() > 3.5);
75 
76     QRectF r = viewConverter.viewToDocument(QRectF(0.0, 0.0, 5, 5));
77     QVERIFY(r.width() < 3.7 && r.width() > 3.5
78             && r.height() < 3.7 && r.height() > 3.5);
79 
80     QSizeF s = viewConverter.viewToDocument(QSizeF(1.0, 1.0));
81     QVERIFY(s.width() < 0.721 && s.width() > 0.719
82             && s.height() < 0.721 && s.height() > 0.719);
83 
84     double x = viewConverter.viewToDocumentX(1.0);
85     QVERIFY(x < 0.721 && x > 0.719);
86 
87     double y = viewConverter.viewToDocumentY(1.0);
88     QVERIFY(y < 0.721 && y > 0.719);
89 
90 }
91 
testZoom()92 void KisImageViewConverterTest::testZoom()
93 {
94     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
95     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "test");
96     KisImageViewConverter viewConverter(image);
97 
98     image->setResolution(1.38888888, 5.38888888);
99 
100     qreal zoomX, zoomY;
101 
102     viewConverter.zoom(&zoomX, &zoomY);
103     QVERIFY(zoomX < 1.388889 && zoomX > 1.3888887);
104     QVERIFY(zoomY < 5.388889 && zoomY > 5.3888887);
105 }
106 
107 QTEST_MAIN(KisImageViewConverterTest)
108