141 {
142 for (
const auto& hill :
manager_->GetHills()) {
143
145
146
147
148 QVector2D v1 = QVector2D(hill.GetVertices()[1].x - hill.GetVertices()[0].x,
149 hill.GetVertices()[1].y - hill.GetVertices()[0].y);
150 QVector2D v2 = QVector2D(hill.GetVertices()[2].x - hill.GetVertices()[1].x,
151 hill.GetVertices()[2].y - hill.GetVertices()[1].y);
152 short sign = (v1.x() * v2.y() - v1.y() * v2.x()) /
153 abs(v1.x() * v2.y() - v1.y() * v2.x());
154
155 size_t sz = hill.GetVertices().size();
156 for (size_t i = 1; i < sz; i++) {
157 QVector2D vec1 = QVector2D(
158 hill.GetVertices()[(i + 1) % sz].x - hill.GetVertices()[i % sz].x,
159 hill.GetVertices()[(i + 1) % sz].y - hill.GetVertices()[i % sz].y);
160 QVector2D vec2 = QVector2D(hill.GetVertices()[(i + 2) % sz].x -
161 hill.GetVertices()[(i + 1) % sz].x,
162 hill.GetVertices()[(i + 2) % sz].y -
163 hill.GetVertices()[(i + 1) % sz].y);
164
165 double product = vec1.x() * vec2.y() - vec1.y() * vec2.x();
166
167 if (product == 0 || product / abs(product) != sign) {
168 std::string text = "There is non-convex polygon! Id: ";
169 text += std::to_string(hill.GetData().GetId());
170 throw std::invalid_argument(text);
171 }
172 }
173
174
175 for (
const auto& target :
manager_->GetTargets())
177 std::string text = "There is Target in Hill! Id's: ";
178 text += std::to_string(target.GetData().GetId());
179 text += " and ";
180 text += std::to_string(hill.GetData().GetId());
181 throw std::invalid_argument(text);
182 }
183 }
184}