Add examples for different utilities
This commit is contained in:
40
cpplinker/10_debug_linker/math_lib.cpp
Normal file
40
cpplinker/10_debug_linker/math_lib.cpp
Normal 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
|
||||
Reference in New Issue
Block a user