| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: MIT | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <limits> | ||
| 8 | |||
| 9 | namespace imgdoc2 | ||
| 10 | { | ||
| 11 | /// This structure gathers a minimum and maximum value. If minimum is greater than maximum, this means | ||
| 12 | /// that the bounds is invalid. | ||
| 13 | struct DoubleInterval | ||
| 14 | { | ||
| 15 | double minimum_value{ std::numeric_limits<double>::max() }; ///< The minimum value. | ||
| 16 | double maximum_value{ std::numeric_limits<double>::lowest() }; ///< The maximum value. | ||
| 17 | |||
| 18 | /// <summary> Query if this object is valid. </summary> | ||
| 19 | /// <returns> True if valid, false if not. </returns> | ||
| 20 | 22 | [[nodiscard]] bool IsValid() const | |
| 21 | { | ||
| 22 | 22 | return this->minimum_value <= this->maximum_value; | |
| 23 | } | ||
| 24 | |||
| 25 | /// <summary> Equality operator. </summary> | ||
| 26 | /// <remarks> In case the both are 'not valid', then they are considered equal (irrespective of the actual values). </remarks> | ||
| 27 | /// <param name="rhs"> The right hand side. </param> | ||
| 28 | /// <returns> True if the parameters are considered equivalent. </returns> | ||
| 29 | 20 | [[nodiscard]] bool operator==(const DoubleInterval& rhs) const | |
| 30 | { | ||
| 31 |
3/4✓ Branch 0 taken 14 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
20 | if (this->minimum_value == rhs.minimum_value && this->maximum_value == rhs.maximum_value) |
| 32 | { | ||
| 33 | 14 | return true; | |
| 34 | } | ||
| 35 | |||
| 36 | // if both are invalid, then we consider them as equal - otherwise, they are unequal | ||
| 37 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
6 | return !this->IsValid() && !rhs.IsValid(); |
| 38 | } | ||
| 39 | |||
| 40 | /// <summary> Inequality operator. </summary> | ||
| 41 | /// <remarks> In case the both are 'not valid', then they are considered equal (irrespective of the actual values). </remarks> | ||
| 42 | /// <param name="rhs"> The right hand side. </param> | ||
| 43 | /// <returns> True if the parameters are not considered equivalent. </returns> | ||
| 44 | 4 | [[nodiscard]] bool operator!=(const DoubleInterval& rhs) const | |
| 45 | { | ||
| 46 | 4 | return !(*this == rhs); | |
| 47 | } | ||
| 48 | }; | ||
| 49 | |||
| 50 | /// This structure gathers a minimum and maximum value. If minimum is greater than maximum, this means | ||
| 51 | /// that the bounds is invalid. | ||
| 52 | struct Int32Interval | ||
| 53 | { | ||
| 54 | std::int32_t minimum_value{ std::numeric_limits<std::int32_t>::max() }; ///< The minimum value. | ||
| 55 | std::int32_t maximum_value{ std::numeric_limits<std::int32_t>::min() }; ///< The maximum value. | ||
| 56 | |||
| 57 | /// <summary> Query if this object is valid. </summary> | ||
| 58 | /// <returns> True if valid, false if not. </returns> | ||
| 59 | 20 | [[nodiscard]] bool IsValid() const | |
| 60 | { | ||
| 61 | 20 | return this->minimum_value <= this->maximum_value; | |
| 62 | } | ||
| 63 | |||
| 64 | /// <summary> Equality operator. </summary> | ||
| 65 | /// <remarks> In case the both are 'not valid', then they are considered equal (irrespective of the actual values). </remarks> | ||
| 66 | /// <param name="rhs"> The right hand side. </param> | ||
| 67 | /// <returns> True if the parameters are considered equivalent. </returns> | ||
| 68 | 10 | bool operator==(const Int32Interval& rhs) const | |
| 69 | { | ||
| 70 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
10 | if (this->minimum_value == rhs.minimum_value && this->maximum_value == rhs.maximum_value) |
| 71 | { | ||
| 72 | 4 | return true; | |
| 73 | } | ||
| 74 | |||
| 75 | // if both are invalid, then we consider them as equal - otherwise, they are unequal | ||
| 76 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
6 | return !this->IsValid() && !rhs.IsValid(); |
| 77 | } | ||
| 78 | |||
| 79 | /// <summary> Inequality operator. </summary> | ||
| 80 | /// <remarks> In case the both are 'not valid', then they are considered equal (irrespective of the actual values). </remarks> | ||
| 81 | /// <param name="rhs"> The right hand side. </param> | ||
| 82 | /// <returns> True if the parameters are not considered equivalent. </returns> | ||
| 83 | 4 | bool operator!=(const Int32Interval& rhs) const | |
| 84 | { | ||
| 85 | 4 | return !(*this == rhs); | |
| 86 | } | ||
| 87 | }; | ||
| 88 | } // namespace imgdoc2 | ||
| 89 |