QUGaR 0.0.4
Loading...
Searching...
No Matches
tolerance.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------
2//
3// Copyright (C) 2025-present by Pablo Antolin
4//
5// This file is part of the QUGaR library.
6//
7// SPDX-License-Identifier: MIT
8//
9// --------------------------------------------------------------------------
10
11#ifndef QUGAR_LIBRARY_TOLERANCE_HPP
12
13#define QUGAR_LIBRARY_TOLERANCE_HPP
14
21
22
23#include <qugar/point.hpp>
24#include <qugar/types.hpp>
25
26#include <cstdlib>
27#include <vector>
28
29namespace qugar {
30
33{
34public:
38 explicit Tolerance(const real value);
39
45 explicit Tolerance(const real tol_0, const real tol_1);
46
52 explicit Tolerance(const Tolerance &tol_0, const Tolerance &tol_1);
53
56 explicit Tolerance();
57
61 void update(const real tol);
62
66 void update(const Tolerance &tol);
67
70 [[nodiscard]] real value() const;
71
72
79 [[nodiscard]] bool is_zero(const real val) const;
80
87 [[nodiscard]] bool is_negative(const real val) const;
88
95 [[nodiscard]] bool is_positive(const real val) const;
96
104 [[nodiscard]] bool equal(const real lhs, const real rhs) const;
105
114 [[nodiscard]] bool equal_rel(const real lhs, const real rhs) const;
115
127 [[nodiscard]] bool equal_rel(const real lhs, const real rhs, const Tolerance &rel_tolerance) const;
128
136 [[nodiscard]] bool greater_than(const real lhs, const real rhs) const;
137
145 [[nodiscard]] bool greater_equal_than(const real lhs, const real rhs) const;
146
155 [[nodiscard]] bool greater_than_rel(const real lhs, const real rhs) const;
156
164 [[nodiscard]] bool smaller_than(const real lhs, const real rhs) const;
165
173 [[nodiscard]] bool smaller_equal_than(const real lhs, const real rhs) const;
174
183 [[nodiscard]] bool smaller_than_rel(const real lhs, const real rhs) const;
184
188 void unique(std::vector<real> &values) const;
189
200 template<int dim, typename T>
201 [[nodiscard]] bool coincident(const Point<dim, T> &pt_0, const Point<dim, T> &pt_1) const
202 {
203 for (int dir = 0; dir < dim; ++dir) {
204 if (!this->equal(pt_0(dir), pt_1(dir))) {
205 return false;
206 }
207 }
208 return true;
209 }
210
211
212private:
215};
216
217}// namespace qugar
218
219#endif// QUGAR_LIBRARY_TOLERANCE_HPP
Class for tolerance related computations.
Definition tolerance.hpp:33
Tolerance()
Default constructor. It initalizes the class instance with a near epsilon tolerance.
bool greater_than(const real lhs, const real rhs) const
Compares if a value is greater than other up to tolerance.
bool is_negative(const real val) const
Check if val is negative.
void unique(std::vector< real > &values) const
Makes the given values unique up to tolerance. values will be also sorted.
real tolerance_
Tolerance value.
Definition tolerance.hpp:214
Tolerance(const real tol_0, const real tol_1)
Constructor. Creates a new class instance using the largest of the two given tolerances.
bool coincident(const Point< dim, T > &pt_0, const Point< dim, T > &pt_1) const
Checks if two points are coincident.
Definition tolerance.hpp:201
bool is_positive(const real val) const
Check if val is positive.
bool smaller_than(const real lhs, const real rhs) const
Compares if a value is smaller than other up to tolerance.
bool equal(const real lhs, const real rhs) const
Compares if two values are equal up to tolerance.
bool smaller_than_rel(const real lhs, const real rhs) const
Compares if a value is smaller than other up to tolerance relative to the larger of the two argumetns...
Tolerance(const Tolerance &tol_0, const Tolerance &tol_1)
Constructor. Creates a new class instance using the largest of the two given tolerances.
bool equal_rel(const real lhs, const real rhs) const
Compares if two values are equal up to tolerance relative to the larger of the two arguments.
bool greater_equal_than(const real lhs, const real rhs) const
Compares if a value is greater or equal than other up to tolerance.
void update(const Tolerance &tol)
Resets the tolerance value as the maximum between the current tolerance_ and tol.
bool equal_rel(const real lhs, const real rhs, const Tolerance &rel_tolerance) const
Compares if two values are equal up to the different absolute and relative tolerances.
bool smaller_equal_than(const real lhs, const real rhs) const
Compares if a value is smaller or equal than other up to tolerance.
void update(const real tol)
Resets the tolerance value as the maximum between the current tolerance_ and tol.
bool greater_than_rel(const real lhs, const real rhs) const
Compares if a value is greater than other up to tolerance relative to the larger of the two argumetns...
real value() const
Returns the real tolerance value.
Tolerance(const real value)
Constructor.
bool is_zero(const real val) const
Check if val is zero up to tolerance.
QUGaR's main namespace.
Definition affine_transf.hpp:28
double real
Definition types.hpp:18
Vector< T, dim > Point
Class representing a dim-dimensional Point.
Definition point.hpp:34
Definition and implementation of Point class.
Declaration of types.