1#ifndef IV_SRC_MATH_UTILS_HPP_
2#define IV_SRC_MATH_UTILS_HPP_
16bool isSameSign(
double value1,
double value2,
double precision);
18int64_t
mmToDp(int64_t sizeMm);
24template<
typename T1,
typename T2 =
double>
26 requires std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
41 requires std::is_arithmetic_v<T>
45 throw std::invalid_argument(
"min must be less than or equal to max");
48 return min <= value and value <= max;
56namespace geometry::utils
69 for (
const auto &point: points)
91 for (
const auto &point: points)
93 minY = std::min(minY, point.y);
94 maxY = std::max(maxY, point.y);
110 for (
const auto &point: points)
112 minX = std::min(minX, point.x);
113 maxX = std::max(maxX, point.x);
126 secondPoint.
y = firstPoint.
y;
130 secondPoint.
x = firstPoint.
x;
147 if (distH <= distV && distH <= distD)
149 secondPoint.
y = firstPoint.
y;
151 else if (distV <= distD)
153 secondPoint.
x = firstPoint.
x;
159 secondPoint.
x = firstPoint.
x + (dx > 0 ? absDy : -absDy);
160 secondPoint.
y = firstPoint.
y + (dy > 0 ? absDy : -absDy);
164 secondPoint.
x = firstPoint.
x + (dx > 0 ? absDx : -absDx);
165 secondPoint.
y = firstPoint.
y + (dy > 0 ? absDx : -absDx);
178 requires std::is_same_v<T, iv::math::geometry::Point2d> || std::is_same_v<T, iv::math::geometry::Point3d>
181 if (v.empty() || v.front() == v.back())
186 v.push_back(v.front());
190 requires std::is_same_v<T, iv::math::geometry::Point2d> || std::is_same_v<T, iv::math::geometry::Point3d>
198 return v.front() == v.back();
202 requires std::is_same_v<T, iv::math::geometry::Point2d>
207 for (uint64_t i = 0; i < v.size() - 1; i++)
212 sum += (point2.x - point1.x) * (point2.y + point1.y);
215 return std::abs(sum / 2.);
219 requires std::is_same_v<T, iv::math::geometry::Point2d>
222 auto *array =
static_cast<float *
>(calloc(points.size() * 2,
sizeof(
float)));
224 for (uint64_t itr = 0; itr < points.size(); itr++)
226 const uint64_t ind = itr * 2;
228 array[ind] =
static_cast<float>(points.at(itr).x);
229 array[ind + 1] =
static_cast<float>(points.at(itr).y);
236 requires std::is_same_v<T, iv::math::geometry::Point2d> || std::is_same_v<T, iv::math::geometry::Point3d>
242 array =
static_cast<float *
>(calloc(3 * v.size(),
sizeof(
float)));
244 for (uint64_t itr = 0; itr < v.size(); itr++)
246 const uint64_t ind = itr * 3;
248 array[ind] =
static_cast<float>(v.at(itr).x);
249 array[ind + 1] =
static_cast<float>(v.at(itr).y);
250 array[ind + 2] =
static_cast<float>(z);
265float *
getArrayRgbac_old(
const std::vector<iv::math::geometry::Point3d> &v,
float alpha);
constexpr double Precision
Definition defines.hpp:130
double calculateArea(const std::vector< T > &v)
Definition utils.hpp:203
iv::math::geometry::Point2d getCentroid(const std::vector< iv::math::geometry::Point2d > &points)
Definition utils.hpp:59
bool isClosed(const std::vector< T > &v)
Definition utils.hpp:191
void alignSecondPointWithDiagonal(const iv::math::geometry::Point2d &firstPoint, iv::math::geometry::Point2d &secondPoint)
Definition utils.hpp:134
float * getArrayRgbac_old(const std::vector< iv::math::geometry::Point3d > &v, float alpha)
Definition utils.cpp:105
float * getArrayFloatC3d(std::vector< iv::math::geometry::Point3d > points)
Definition utils.cpp:87
double module(Point2d begining, Point2d end)
Definition utils.cpp:205
iv::types::height getHeight(const std::vector< iv::math::geometry::Point2d > &points)
Definition utils.hpp:81
void alignSecondPoint(const iv::math::geometry::Point2d &firstPoint, iv::math::geometry::Point2d &secondPoint)
Definition utils.hpp:119
bool isSamePoint2D(const iv::math::geometry::Point2d &firstPoint, const iv::math::geometry::Point2d &secondPoint, iv::types::coord precision)
Definition utils.hpp:170
float * getArray3dc(const std::vector< T > &v, const double z)
Definition utils.hpp:237
iv::types::width getWidth(const std::vector< iv::math::geometry::Point2d > &points)
Definition utils.hpp:100
void close(std::vector< T > &v)
Definition utils.hpp:179
float * getArrayFloatC(const std::vector< iv::math::geometry::Point2d > &v)
Definition utils.cpp:138
float * getArrayFloatCAppendingZ(const std::vector< iv::math::geometry::Point2d > &v, float z)
Definition utils.cpp:171
iv::types::radian degreeToRadian(iv::types::degree degree)
Definition utils.cpp:44
bool isSameSign(const double value1, const double value2, const double precision)
Definition utils.cpp:14
bool isEqual(T1 d1, T2 d2, T3 tolerance=iv::constants::maths::Precision)
Definition utils.hpp:270
iv::math::geometry::Point2d pointOnCircle(iv::types::radius radius, iv::types::degree angle)
Definition utils.cpp:54
double valueInterpolation(double valueNormalized, double valueMin, double valueMax)
Definition utils.cpp:21
bool isInRange(T value, T min, T max)
Checks if a value is in a range [min, max] (inclusive).
Definition utils.hpp:40
double stepsIncrement(const iv::types::Range< double > range, const uint64_t steps)
Definition utils.cpp:64
bool isZero(T1 value, T2 tolerance=iv::constants::maths::Precision)
Definition utils.hpp:25
double roundToNearestStep(double value, const double step, iv::types::Range< double > range)
Definition utils.cpp:72
iv::types::degree radianToDegree(iv::types::radian radian)
Definition utils.cpp:49
int64_t mmToDp(int64_t sizeMm)
Definition utils.cpp:33
double radian
Definition types.hpp:19
double height
Definition types.hpp:14
double radius
Definition types.hpp:17
double degree
Definition types.hpp:18
double width
Definition types.hpp:23
double coord
Definition types.hpp:13
Definition structs.hpp:16
iv::types::coord y
Definition structs.hpp:52
iv::types::coord x
Definition structs.hpp:51