Тест на перпендикулярность

This commit is contained in:
2025-12-15 20:44:23 +03:00
parent cc1f891d90
commit 68451b4261
2 changed files with 56 additions and 1 deletions

View File

@@ -136,6 +136,11 @@ bool Canvas::areAlreadyParallel(Line* l1, Line* l2)
return parallelPairs.count(makeOrderedPair<LinePair>(l1, l2));
}
bool Canvas::areAlreadyPerpendicular(Line* line1, Line* line2)
{
return perpendicularPairs.count(makeOrderedPair<LinePair>(line1, line2));
}
// ===================================================================
// Методы работы с ограничениями
// ===================================================================
@@ -443,6 +448,52 @@ void Canvas::mousePressEvent(QMouseEvent* event)
update();
return;
}
else if (mode == Mode::Perpendicular) {
Line* found = findAt(scene);
if (!found) {
current_line = nullptr;
update();
return;
}
// Первый клик: выбираем первую линию
if (!current_line) {
current_line = found;
update();
return;
}
// Повторный клик на ту же линию: сброс выбора
if (found == current_line) {
current_line = nullptr;
update();
return;
}
if (!areAlreadyPerpendicular(found, current_line)) {
auto pair = makeOrderedPair<LinePair>(found, current_line);
sys.addConstraintPerpendicular(*found, *current_line, constraints_count++);
perpendicularPairs.insert(pair);
current_line = nullptr;
mode = Mode::None;
after_constraint = true;
update();
}
else {
QMessageBox::warning(this,
QString("Wrong"),
QString("Perpendicular lines can not be more perpendicular!"),
QMessageBox::Ok
);
current_line = nullptr;
update();
return;
}
}
}
void Canvas::mouseMoveEvent(QMouseEvent* event)

View File

@@ -30,7 +30,8 @@ enum class Mode : int
Parallel = 2, ///< Режим задания параллельности
Coincedent = 3, ///< Режим задания совпадения точек
Horizontal = 4, ///< Режим задания горизонтальности
Vertical = 5 ///< Режим задания вертикальности
Vertical = 5, ///< Режим задания вертикальности
Perpendicular = 6
};
/// Удобный тип для хранения пары параллельных линий (порядок не важен)
@@ -94,6 +95,8 @@ private:
/// Проверить, являются ли две линии уже параллельными (дубликат ограничения)
bool areAlreadyParallel(Line* line1, Line* line2);
bool areAlreadyPerpendicular(Line* line1, Line* line2);
// ====================== Методы работы с ограничениями ======================
/// Удалить последние добавленные ограничения при ошибке солвера
@@ -115,6 +118,7 @@ private:
// ====================== Коллекции ограничений ======================
std::set<LinePair> parallelPairs; ///< Пары параллельных линий
std::set<LinePair> perpendicularPairs;
std::set<PointPair> P2Ppairs; ///< Пары совпадающих точек
std::set<PointPair> HORIZ_pairs; ///< Пары точек горизонтальных линий
std::set<PointPair> VERT_pairs; ///< Пары точек вертикальных линий