/
ArtemNech
/
simpleOpenGL
Обзор
Документация
Войти
/
ArtemNech
/
simpleOpenGL
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
backend/graphics-units/NLine.cpp
178 строк
3 KB
Artem Nechitaylenko
Qt GUI isolated from backend except QEvent. Need fix
18 май 2026, 13:41
18 май 2026, 13:41
f09d1f2
Код
Авторство
О чём код?
// // Created by artem on 20.10.25. // #include "NLine.h" #include <algorithm> ngraph::NLine::NLine() = default; ngraph::NLine::NLine(const ngraph::NPoint &p1, const ngraph::NPoint &p2) : m_p1(p1) , m_p2(p2) {} ngraph::NLine::NLine(const ngraph::NLine &other) : m_p1(other.m_p1) , m_p2(other.m_p2){} ngraph::NPoint ngraph::NLine::p1() const { return m_p1; } ngraph::NPoint ngraph::NLine::p2() const { return m_p2; } void ngraph::NLine::setP1(const ngraph::NPoint &p1) { m_p1 = p1; } void ngraph::NLine::setP2(const ngraph::NPoint &p2) { m_p2 = p2; } double ngraph::NLine::length() const { return m_p2.x() - m_p1.x(); } ngraph::NPoint ngraph::NLine::center() const { return NPoint( (m_p1.x() + m_p2.x()) / 2.0, (m_p1.y() + m_p2.y()) / 2.0 ); } bool ngraph::NLine::isVertical() const { return false; } bool ngraph::NLine::isHorizontal() const { return false; } int ngraph::NLine::x1() const { return m_p1.x(); } int ngraph::NLine::x2() const { return m_p2.x(); } int ngraph::NLine::y1() const { return m_p1.y(); } int ngraph::NLine::y2() const { return m_p2.y(); } //====================================================================================================================== //====================================================================================================================== //====================================================================================================================== namespace ngraph { NLineF::NLineF() : m_p1(NPointF(0, 0)) , m_p2(NPointF(0, 0)) { } NLineF::NLineF(const NPointF& p1, const NPointF& p2) : m_p1(p1) , m_p2(p2) { } NLineF::NLineF(const NLineF& other) : m_p1(other.m_p1) , m_p2(other.m_p2) { } NPointF NLineF::p1() const { return m_p1; } NPointF NLineF::p2() const { return m_p2; } void NLineF::setP1(const NPointF& p1) { m_p1 = p1; } void NLineF::setP2(const NPointF& p2) { m_p2 = p2; } double NLineF::length() const { double dx = m_p2.x() - m_p1.x(); double dy = m_p2.y() - m_p1.y(); return std::sqrt(dx * dx + dy * dy); } NPointF NLineF::center() const { return NPointF( (m_p1.x() + m_p2.x()) / 2.0, (m_p1.y() + m_p2.y()) / 2.0 ); } bool NLineF::isVertical() const { return std::fabs(m_p1.x() - m_p2.x()) < 1e-4; } bool NLineF::isHorizontal() const { return std::fabs(m_p1.y() - m_p2.y()) < 1e-4; } double NLineF::width() const { return std::abs(m_p2.x() - m_p1.x()); } void NLineF::setWidth(const double &width) { m_p2.set_x(m_p1.x() + width); m_width = width; } double NLineF::x1() const { return m_p1.x(); } double NLineF::x2() const { return m_p2.x(); } double NLineF::y1() const { return m_p1.y(); } double NLineF::y2() const { return m_p2.y(); } bool NLineF::operator==(const NLineF &other) const { return m_p1 == other.m_p1 && m_p2 == other.m_p2; } } // namespace ngraph