MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin_Range.h
Go to the documentation of this file.
1// ========================================================================================================
2// _______ _______ ______ ___ ___ _______ _______
3// | | | _ | __ \ | |_ _| | |
4// | | | < | |_| |_| |
5// |__|_|__|___|___|___|__|\_____/|_______|__|____|
6//
7// This file is part of the Marvin open source library and is licensed under the terms of the MIT License.
8//
9// ========================================================================================================
10
11#ifndef MARVIN_RANGE_H
12#define MARVIN_RANGE_H
14namespace marvin::utils {
20 template <NumericType T>
21 struct Range {
22 T min;
23 T max;
24
29 [[nodiscard]] T midpoint() const noexcept {
30 const auto midPoint = ((max - min) / static_cast<T>(2.0)) + min;
31 return midPoint;
32 }
33 };
34
41 template <NumericType T>
42 bool operator==(const Range<T>& lhs, const Range<T>& rhs) {
43 return (lhs.min == rhs.min) && (lhs.max == rhs.max);
44 }
45
52 template <NumericType T>
53 bool operator!=(const Range<T>& lhs, const Range<T>& rhs) {
54 return !(lhs == rhs);
55 }
56
57 template <NumericType T>
58 Range<T> operator+(const Range<T>& other, T constant) {
59 return {
60 .min = other.min + constant,
61 .max = other.max + constant
62 };
63 }
64
65 template <NumericType T>
66 Range<T> operator-(const Range<T>& other, T constant) {
67 return {
68 .min = other.min - constant,
69 .max = other.max - constant
70 };
71 }
72
73 template <NumericType T>
74 Range<T> operator*(const Range<T>& other, T constant) {
75 return {
76 .min = other.min * constant,
77 .max = other.max * constant
78 };
79 }
80
81 template <NumericType T>
82 Range<T> operator/(const Range<T>& other, T constant) {
83 return {
84 .min = other.min / constant,
85 .max = other.max / constant
86 };
87 }
88} // namespace marvin::utils
89#endif
Utility helper functions and classes.
Definition marvin_Utils.h:21
Range< T > operator/(const Range< T > &other, T constant)
Definition marvin_Range.h:82
bool operator!=(const Range< T > &lhs, const Range< T > &rhs)
Definition marvin_Range.h:53
Range< T > operator*(const Range< T > &other, T constant)
Definition marvin_Range.h:74
Range< T > operator-(const Range< T > &other, T constant)
Definition marvin_Range.h:66
Range< T > operator+(const Range< T > &other, T constant)
Definition marvin_Range.h:58
bool operator==(const Range< T > &lhs, const Range< T > &rhs)
Definition marvin_Range.h:42
POD type that represents a range of values, for classes requiring a min and a max.
Definition marvin_Range.h:21
T max
Definition marvin_Range.h:23
T midpoint() const noexcept
Definition marvin_Range.h:29
T min
Definition marvin_Range.h:22