Creepy-simulation
 
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <random>
5
10struct Point {
11 double x;
12 double y;
18 bool operator==(const Point& p2) const { return std::abs(x - p2.x) < 1e-9 && std::abs(y - p2.y) < 1e-9; }
19};
46std::mt19937& getRandom();
51namespace DistanceFunc {
56enum class Type : std::uint8_t { Euclid, Polar, Manhattan };
63double euclideanSquared(const Point& p1, const Point& p2);
70double polarSquared(const Point& p1, const Point& p2);
77double manhattanSquared(const Point& p1, const Point& p2);
83std::function<double(Point p1, Point p2)> funcToType(Type funcType);
84} // namespace DistanceFunc
Namespace containing distance calculation functions and types.
Definition utils.cpp:13
double polarSquared(const Point &p1, const Point &p2)
Computes the squared polar distance between two points.
Definition utils.cpp:34
double manhattanSquared(const Point &p1, const Point &p2)
Computes the squared Manhattan distance between two points.
Definition utils.cpp:25
std::function< double(Point p1, Point p2)> funcToType(const Type funcType)
Maps a distance function type to its corresponding function.
Definition utils.cpp:41
Type
Enumerates supported distance calculation types.
Definition utils.hpp:56
double euclideanSquared(const Point &p1, const Point &p2)
Computes the squared Euclidean distance between two points.
Definition utils.cpp:19
Represents a 2D point with x and y coordinates.
Definition utils.hpp:10
bool operator==(const Point &p2) const
Equality operator for Point.
Definition utils.hpp:18
double x
Definition utils.hpp:11
double y
Definition utils.hpp:12
Represents a rectangle defined by two points: bottom-left and top-right.
Definition utils.hpp:24
Point leftDownBound
Definition utils.hpp:25
bool operator==(const Rectangle &r2) const
Equality operator for Rectangle.
Definition utils.hpp:38
Point rightUpBound
Definition utils.hpp:26
Rectangle(Point leftDownBound, Point rightUpBound)
Constructs a Rectangle object.
Definition utils.hpp:32
std::mt19937 & getRandom()
Retrieves a shared random number generator.
Definition utils.cpp:7