/
polytech_kolomna
/
aipackaging_math
Обзор
Документация
Войти
/
polytech_kolomna
/
aipackaging_math
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
intersections
src/geometry/vector2d.cpp
102 строки
1 KB
Olegh
lower case
28 окт 2025, 21:08
28 окт 2025, 21:08
037a99f
Код
Авторство
О чём код?
#include <stdexcept> #include <cmath> #include <mathutils.h> #include <vector2d.h> // double Vector2D::length() const { return std::sqrt(x * x + y * y); } // Vector2D Vector2D::normalized() const { double len = length(); if (len < MathConstants::TOLERANCE_DOUBLE) throw std::invalid_argument("Cannot normalize a zero vector"); return Vector2D{ x / len, y / len }; } // double Vector2D::pseudoCrossProduct(const Vector2D& other) const { return x * other.y - y * other.x; } // double Vector2D::dotProduct(const Vector2D& other) const { return x * other.x + y * other.y; } // Vector2D Vector2D::operator+(const Vector2D& other) const { return Vector2D{ x + other.x, y + other.y }; } // Vector2D& Vector2D::operator+=(const Vector2D& other) { x += other.x; y += other.y; return *this; } // Vector2D Vector2D::operator-(const Vector2D& other) const { return Vector2D{ x - other.x, y - other.y }; } // Vector2D& Vector2D::operator-=(const Vector2D& other) { x -= other.x; y -= other.y; return *this; } // Vector2D Vector2D::operator*(double scalar) const { return Vector2D{ x * scalar, y * scalar }; } // Vector2D& Vector2D::operator*=(double scalar) { x *= scalar; y *= scalar; return *this; } // bool Vector2D::operator==(const Vector2D& other) const { return (std::abs(x - other.x) < MathConstants::TOLERANCE_DOUBLE) && (std::abs(y - other.y) < MathConstants::TOLERANCE_DOUBLE); } // bool Vector2D::operator!=(const Vector2D& other) const { return !(*this == other); }