/
ArtemNech
/
simpleOpenGL
Обзор
Документация
Войти
/
ArtemNech
/
simpleOpenGL
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
devOpt
backend/graphics-units/NPointF.cpp
144 строки
3 KB
Artem Nechitaylenko
All objects are works and draggable
20 май 2026, 09:40
20 май 2026, 09:40
bf16523
Код
Авторство
О чём код?
// // Created by artem on 5/18/25. // #include <cmath> #include "NPointF.h" #include "floats.h" namespace ngraph { //---------------------------------------------------------------------------------------------------------------------- //--- NPoint ----------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------- NPoint::NPoint() = default; NPoint::NPoint(const int &x, const int &y) { this->x_ = x; this->y_ = y; } NPoint::NPoint(const NPoint &rhs) { *this = rhs; } NPoint &NPoint::operator=(const NPoint &rhs) { if (this == &rhs) return *this; this->x_ = rhs.x_; this->y_ = rhs.y_; return *this; } bool operator==(const NPoint &lhs, const NPoint &rhs) { return (lhs.x_ == rhs.x_) && (lhs.y_ == rhs.y_); } int NPoint::x() const { return this->x_; } int NPoint::y() const { return this->y_; } void NPoint::set_x(const int &x) { this->x_ = x; } void NPoint::set_y(const int &y) { this->y_ = y; } bool operator!=(const NPoint &lhs, const NPoint &rhs) { return !(lhs == rhs); } NPointF NPoint::to_pointF() const { return {static_cast<float>(x_), static_cast<float>(y_)}; } //---------------------------------------------------------------------------------------------------------------------- //--- NPointF ---------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------- NPointF::NPointF() = default; NPointF::NPointF(const double &x, const double &y) : m_x(x), m_y(y) {} NPointF::NPointF(const NPointF &src) = default; NPointF &NPointF::operator=(const NPointF &rhs) { if (this == &rhs) return *this; m_x = rhs.m_x; m_y = rhs.m_y; return *this; } double NPointF::x() const { return m_x; } double NPointF::y() const { return m_y; } NPoint NPointF::to_point() const { return {static_cast<int>(std::round(m_x)), static_cast<int>(std::round(m_y))}; } void NPointF::set_x(const double &x) { m_x = x; } void NPointF::set_y(const double &y) { m_y = y; } bool NPointF::operator==(const NPointF &rhs) const { return floats::is_floats_equal(rhs.m_x, m_x) && floats::is_floats_equal(rhs.m_y, m_y); } bool NPointF::operator!=(const NPointF &rhs) const { return !(*this == rhs); } NPointF NPointF::operator+(const NPointF &other) const { return {this->m_x + other.m_x, this->m_y + other.m_y}; } NPointF NPointF::operator-(const NPointF &other) const { return {this->m_x - other.m_x, this->m_y - other.m_y}; } double NPointF::manhattanLength(const NPointF &pos) const { return std::abs(m_x - pos.m_x) + std::abs(m_y - pos.m_y); } } //namespace ngraph