1 /************************************************************************
2 **
3 ** @file
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 16 8, 2016
6 **
7 ** @brief
8 ** @copyright
9 ** This source code is part of the Valentina project, a pattern making
10 ** program, whose allow create and modeling patterns of clothing.
11 ** Copyright (C) 2016 Valentina project
12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13 **
14 ** Valentina is free software: you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation, either version 3 of the License, or
17 ** (at your option) any later version.
18 **
19 ** Valentina is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
23 **
24 ** You should have received a copy of the GNU General Public License
25 ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
26 **
27 *************************************************************************/
28
29 #include "tst_vgobject.h"
30
31 #include <QtTest>
32
33 #include "../vgeometry/vgobject.h"
34 #include "../vmisc/def.h"
35
36 //---------------------------------------------------------------------------------------------------------------------
TST_VGObject(QObject * parent)37 TST_VGObject::TST_VGObject(QObject *parent)
38 :QObject(parent)
39 {}
40
41 //---------------------------------------------------------------------------------------------------------------------
TestIsPointOnLineviaPDP_data()42 void TST_VGObject::TestIsPointOnLineviaPDP_data()
43 {
44 QTest::addColumn<QPointF>("p1");
45 QTest::addColumn<QPointF>("p2");
46 QTest::addColumn<QPointF>("t");
47 QTest::addColumn<bool>("excpect");
48
49 {
50 const QPointF p1(483.54330708661416, 3819.527433070866);
51 const QPointF p2(483.54330708661416, 1929.763653543307);
52 const QPointF t(483.54330708661416, 1920.763653543307);
53 QTest::newRow("Point is on line, but not on segment.") << p1 << p2 << t << true;
54 }
55
56 {
57 const QPointF p1(483.54330708661416, 3819.527433070866);
58 const QPointF p2(483.54330708661416, 1929.763653543307);
59 const QPointF t(483.54330708661416, 2874.763653543307);
60 QTest::newRow("Point is on segment. On middle.") << p1 << p2 << t << true;
61 }
62
63 {
64 const QPointF p1(483.54330708661416, 3819.527433070866);
65 const QPointF p2(483.54330708661416, 1929.763653543307);
66 const QPointF t(483.54330708661416, 1929.763653543307);
67 QTest::newRow("Point is on segment. The end of segment.") << p1 << p2 << t << true;
68 }
69
70 {
71 const qreal gap = accuracyPointOnLine;
72 const QPointF p1(483.54330708661416, 3819.527433070866);
73 const QPointF p2(483.54330708661416, 1929.763653543307);
74 const QPointF t(483.54330708661416 + gap, 2874.763653543307);
75 QTest::newRow("Min accuracy gap. On middle.") << p1 << p2 << t << true;
76 }
77
78 {
79 const qreal gap = accuracyPointOnLine;
80 const QPointF p1(483.54330708661416, 3819.527433070866);
81 const QPointF p2(483.54330708661416, 1929.763653543307);
82 const QPointF t(483.54330708661416 + gap, 1929.763653543307);
83 QTest::newRow("Min accuracy gap. The end of segment.") << p1 << p2 << t << true;
84 }
85
86 {
87 const qreal gap = accuracyPointOnLine + accuracyPointOnLine*0.01;
88 const QPointF p1(483.54330708661416, 3819.527433070866);
89 const QPointF p2(483.54330708661416, 1929.763653543307);
90 const QPointF t(483.54330708661416 + gap, 2874.763653543307);
91 QTest::newRow("Min accuracy gap + 1%. On middle.") << p1 << p2 << t << false;
92 }
93
94 {
95 const qreal gap = accuracyPointOnLine + accuracyPointOnLine*0.01;
96 const QPointF p1(483.54330708661416, 3819.527433070866);
97 const QPointF p2(483.54330708661416, 1929.763653543307);
98 const QPointF t(483.54330708661416 + gap, 1929.763653543307);
99 QTest::newRow("Min accuracy gap + 1%. The end of segment.") << p1 << p2 << t << false;
100 }
101
102 {
103 const QPointF p1(483.54330708661416, 3819.527433070866);
104 const QPointF p2(483.54330708661416, 1929.763653543307);
105 const QPointF t(483.54330708661416 + accuracyPointOnLine/2., 2874.763653543307);
106 QTest::newRow("Less than min accuracy gap. On middle.") << p1 << p2 << t << true;
107 }
108
109 {
110 const QPointF p1(483.54330708661416, 3819.527433070866);
111 const QPointF p2(483.54330708661416, 1929.763653543307);
112 const QPointF t(483.54330708661416 + accuracyPointOnLine/2., 1929.763653543307);
113 QTest::newRow("Less than min accuracy gap. The end of segment.") << p1 << p2 << t << true;
114 }
115
116 {
117 const QPointF p1(483.54330708661416, 3819.527433070866);
118 const QPointF p2(483.54330708661416, 1929.763653543307);
119 const QPointF t(370.1574803149606, 2874.763653543307);
120 QTest::newRow("Issue 534 - 3 cm gap. On middle.") << p1 << p2 << t << false;
121 }
122
123 {
124 const QPointF p1(483.54330708661416, 3819.527433070866);
125 const QPointF p2(483.54330708661416, 1929.763653543307);
126 const QPointF t(370.1574803149606, 1929.763653543307);
127 QTest::newRow("Issue 534 - 3 cm gap. The end of segment.") << p1 << p2 << t << false;
128 }
129
130 {
131 const QPointF p1(483.54330708661416, 3819.527433070866);
132 const QPointF p2(483.54330708661416, 1929.763653543307);
133 const QPointF t(407.9527559055118, 2874.763653543307);
134 QTest::newRow("Issue 534 - 2 cm gap. On middle.") << p1 << p2 << t << false;
135 }
136
137 {
138 const QPointF p1(483.54330708661416, 3819.527433070866);
139 const QPointF p2(483.54330708661416, 1929.763653543307);
140 const QPointF t(407.9527559055118, 1929.763653543307);
141 QTest::newRow("Issue 534 - 2 cm gap. The end of segment.") << p1 << p2 << t << false;
142 }
143 }
144
145 //---------------------------------------------------------------------------------------------------------------------
TestIsPointOnLineviaPDP() const146 void TST_VGObject::TestIsPointOnLineviaPDP() const
147 {
148 QFETCH(QPointF, p1);
149 QFETCH(QPointF, p2);
150 QFETCH(QPointF, t);
151 QFETCH(bool, excpect);
152
153 const bool res = VGObject::IsPointOnLineviaPDP(t, p1, p2);
154 QCOMPARE(res, excpect);
155 }
156
157