/
polytech_kolomna
/
polygon2d
Обзор
Документация
Войти
/
polytech_kolomna
/
polygon2d
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
math
src/models/selectablepathitem.cpp
66 строк
2 KB
ecomaks2017
circle scaling implemented
14 янв 2026, 14:33
14 янв 2026, 14:33
7d43fb5
Код
Авторство
О чём код?
#include <..\models\selectablepathitem.h> #include <Circle2D.h> #include <BoundedCurve2D.h> #include <MathUtils.h> #include <QPainter> SelectablePathItem::SelectablePathItem(QGraphicsItem* parent) : QGraphicsPathItem(parent) , m_clickTolerance(20.0) { } void SelectablePathItem::Redraw() { if (m_model) { double step = 0, parts = 0, length = 0; double minT = 0, maxT = 0; if (dynamic_cast<const BoundedCurve2D*>(m_model)) { const BoundedCurve2D* bc = dynamic_cast<const BoundedCurve2D*>(m_model); minT = bc->getMinT(); maxT = bc->getMaxT(); length = bc->getMaxT() - bc->getMinT(); step = length / 50; } else if (dynamic_cast<const Circle2D*>(m_model)) { length = MathConstants::PI * 2; step = MathConstants::PI * 2 / 50.0; } QPolygonF poly; // Разбиение кривой на отрезки for (double i = minT; i <= length; i += step) { poly.push_back(QPointF(m_model->getPoint(i).x, m_model->getPoint(i).y)); } poly.push_back(QPointF(m_model->getPoint(maxT).x, m_model->getPoint(maxT).y)); QPainterPath path; path.addPolygon(poly); if (dynamic_cast<const Circle2D*>(m_model)) { path.closeSubpath(); // Если хранится окружность - замкнуть контур } setPath(path); } } QPainterPath SelectablePathItem::shape() const { QPainterPathStroker stroker; stroker.setWidth(m_clickTolerance); // Возвращает путь границы для определения столкновений return stroker.createStroke(path()); }