Add examples for different utilities

This commit is contained in:
2026-02-24 13:46:16 +01:00
parent bacba9e8c8
commit 04c7146e84
5 changed files with 213 additions and 8 deletions

View File

@@ -0,0 +1,40 @@
#include "math_lib.hpp"
#include <cmath>
namespace Math {
// --- Free functions ---
double sqrt(double x) {
return std::sqrt(x);
}
double square(double x) {
return x * x;
}
double cube(double x) {
return x * x * x;
}
// --- Vector2D ---
Vector2D::Vector2D(double x, double y) : x(x), y(y) {}
double Vector2D::length() const {
return std::sqrt(x * x + y * y);
}
Vector2D Vector2D::add(const Vector2D& other) const {
return Vector2D(x + other.x, y + other.y);
}
Vector2D Vector2D::scale(double factor) const {
return Vector2D(x * factor, y * factor);
}
double Vector2D::dot(const Vector2D& other) const {
return x * other.x + y * other.y;
}
} // namespace Math