libimgdoc2
Loading...
Searching...
No Matches
Intervals.h
1// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <limits>
8
9namespace imgdoc2
10{
14 {
15 double minimum_value{ std::numeric_limits<double>::max() };
16 double maximum_value{ std::numeric_limits<double>::lowest() };
17
20 [[nodiscard]] bool IsValid() const
21 {
22 return this->minimum_value <= this->maximum_value;
23 }
24
29 [[nodiscard]] bool operator==(const DoubleInterval& rhs) const
30 {
31 if (this->minimum_value == rhs.minimum_value && this->maximum_value == rhs.maximum_value)
32 {
33 return true;
34 }
35
36 // if both are invalid, then we consider them as equal - otherwise, they are unequal
37 return !this->IsValid() && !rhs.IsValid();
38 }
39
44 [[nodiscard]] bool operator!=(const DoubleInterval& rhs) const
45 {
46 return !(*this == rhs);
47 }
48 };
49
53 {
54 std::int32_t minimum_value{ std::numeric_limits<std::int32_t>::max() };
55 std::int32_t maximum_value{ std::numeric_limits<std::int32_t>::min() };
56
59 [[nodiscard]] bool IsValid() const
60 {
61 return this->minimum_value <= this->maximum_value;
62 }
63
68 bool operator==(const Int32Interval& rhs) const
69 {
70 if (this->minimum_value == rhs.minimum_value && this->maximum_value == rhs.maximum_value)
71 {
72 return true;
73 }
74
75 // if both are invalid, then we consider them as equal - otherwise, they are unequal
76 return !this->IsValid() && !rhs.IsValid();
77 }
78
83 bool operator!=(const Int32Interval& rhs) const
84 {
85 return !(*this == rhs);
86 }
87 };
88} // namespace imgdoc2
Definition: Intervals.h:14
double maximum_value
The maximum value.
Definition: Intervals.h:16
bool operator!=(const DoubleInterval &rhs) const
Inequality operator.
Definition: Intervals.h:44
bool IsValid() const
Query if this object is valid.
Definition: Intervals.h:20
bool operator==(const DoubleInterval &rhs) const
Equality operator.
Definition: Intervals.h:29
double minimum_value
The minimum value.
Definition: Intervals.h:15
Definition: Intervals.h:53
bool IsValid() const
Query if this object is valid.
Definition: Intervals.h:59
std::int32_t minimum_value
The minimum value.
Definition: Intervals.h:54
bool operator!=(const Int32Interval &rhs) const
Inequality operator.
Definition: Intervals.h:83
std::int32_t maximum_value
The maximum value.
Definition: Intervals.h:55
bool operator==(const Int32Interval &rhs) const
Equality operator.
Definition: Intervals.h:68