| Line | Branch | Exec | Source | 
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: MIT | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include <limits> | ||
| 7 | #include "utilities.h" | ||
| 8 | |||
| 9 | namespace imgdoc2 | ||
| 10 | { | ||
| 11 | /// This structure defines the "logical position" of a tile in the 2D-document model. | ||
| 12 | /// It is given by a (axis-aligned) rectangle (in the plane-pixel-coordinate-system) and | ||
| 13 | /// the pyramid-level. | ||
| 14 | struct LogicalPositionInfo | ||
| 15 | { | ||
| 16 | /// Default constructor, all properties are initialized to invalid values. | ||
| 17 | LogicalPositionInfo() = default; | ||
| 18 | |||
| 19 | /// Constructor initializing the rectangle and setting the pyramid-level to zero. | ||
| 20 | /// \param x The x coordinate of the top left point. | ||
| 21 | /// \param y The y coordinate of the top left point. | ||
| 22 | /// \param w The width. | ||
| 23 | /// \param h The height. | ||
| 24 | 2 | LogicalPositionInfo(double x, double y, double w, double h) : posX(x), posY(y), width(w), height(h), pyrLvl(0) | |
| 25 | 2 | {} | |
| 26 | |||
| 27 | /// Constructor. | ||
| 28 | /// \param x The x coordinate of the top left point. | ||
| 29 | /// \param y The y coordinate of the top left point. | ||
| 30 | /// \param w The width. | ||
| 31 | /// \param h The height. | ||
| 32 | /// \param pyrLvl The pyramid level. | ||
| 33 | 4 | LogicalPositionInfo(double x, double y, double w, double h, int pyrLvl) : posX(x), posY(y), width(w), height(h), pyrLvl(pyrLvl) | |
| 34 | 4 | {} | |
| 35 | |||
| 36 | double posX{ std::numeric_limits<double>::quiet_NaN() }; ///< The x coordinate of the top left point. | ||
| 37 | double posY{ std::numeric_limits<double>::quiet_NaN() }; ///< The y coordinate of the top left point. | ||
| 38 | double width{ std::numeric_limits<double>::quiet_NaN() }; ///< The width. | ||
| 39 | double height{ std::numeric_limits<double>::quiet_NaN() }; ///< The height. | ||
| 40 | int pyrLvl{ std::numeric_limits<int>::min() }; ///< The pyramid level. | ||
| 41 | |||
| 42 | /// Equality operator (where the coordinates are compared with an epsilon). | ||
| 43 | /// \param rhs The right hand side. | ||
| 44 | /// \returns True if the parameters are considered equivalent. | ||
| 45 | 10 | bool operator==(const LogicalPositionInfo& rhs) const | |
| 46 | { | ||
| 47 | 10 | constexpr double kDoubleEpsilon = 1e-8; | |
| 48 | 1/2✓ Branch 0 taken 6 times. ✗ Branch 1 not taken. | 6 | return this->pyrLvl == rhs.pyrLvl && | 
| 49 | 1/2✓ Branch 1 taken 6 times. ✗ Branch 2 not taken. | 12 | approximatelyEqual(this->posX, rhs.posX, kDoubleEpsilon) && | 
| 50 | 1/2✓ Branch 1 taken 6 times. ✗ Branch 2 not taken. | 12 | approximatelyEqual(this->posY, rhs.posY, kDoubleEpsilon) && | 
| 51 | 3/4✓ Branch 0 taken 6 times. ✓ Branch 1 taken 4 times. ✓ Branch 3 taken 6 times. ✗ Branch 4 not taken. | 22 | approximatelyEqual(this->width, rhs.width, kDoubleEpsilon) && | 
| 52 | 16 | approximatelyEqual(this->height, rhs.height, kDoubleEpsilon); | |
| 53 | } | ||
| 54 | |||
| 55 | /// Inequality operator (where the coordinates are compared with an epsilon). | ||
| 56 | /// \param rhs The right hand side. | ||
| 57 | /// \returns True if the parameters are not considered equivalent. | ||
| 58 | 4 | bool operator!=(const LogicalPositionInfo& rhs) const | |
| 59 | { | ||
| 60 | 4 | return !this->operator==(rhs); | |
| 61 | } | ||
| 62 | }; | ||
| 63 | |||
| 64 | /// This structure defines the "logical position" of a tile in the 3D-document model. | ||
| 65 | /// It is given by a (axis-aligned) cuboid (in the plane-pixel-coordinate-system) and | ||
| 66 | /// the pyramid-level. | ||
| 67 | struct LogicalPositionInfo3D | ||
| 68 | { | ||
| 69 | double posX{ std::numeric_limits<double>::quiet_NaN() }; ///< The x coordinate of the top left point. | ||
| 70 | double posY{ std::numeric_limits<double>::quiet_NaN() }; ///< The y coordinate of the top left point. | ||
| 71 | double posZ{ std::numeric_limits<double>::quiet_NaN() }; ///< The z coordinate of the top left point. | ||
| 72 | double width{ std::numeric_limits<double>::quiet_NaN() }; ///< The width. | ||
| 73 | double height{ std::numeric_limits<double>::quiet_NaN() }; ///< The height. | ||
| 74 | double depth{ std::numeric_limits<double>::quiet_NaN() }; ///< The depth. | ||
| 75 | int pyrLvl{ std::numeric_limits<int>::min() }; ///< The pyramid level. | ||
| 76 | |||
| 77 | /// Default constructor, all properties are initialized to invalid values. | ||
| 78 | LogicalPositionInfo3D() = default; | ||
| 79 | |||
| 80 | /// Constructor initializing the cuboid and setting the pyramid-level to invalid values. | ||
| 81 | /// \param x The x coordinate of the top left point. | ||
| 82 | /// \param y The y coordinate of the top left point. | ||
| 83 | /// \param z The z coordinate of the top left point. | ||
| 84 | /// \param w The width. | ||
| 85 | /// \param h The height. | ||
| 86 | /// \param d The depth. | ||
| 87 | 2 | LogicalPositionInfo3D(double x, double y, double z, double w, double h, double d) : posX(x), posY(y), posZ(z), width(w), height(h), depth(d), pyrLvl(0) | |
| 88 | 2 | {} | |
| 89 | |||
| 90 | /// Constructor. | ||
| 91 | /// \param x The x coordinate of the top left point. | ||
| 92 | /// \param y The y coordinate of the top left point. | ||
| 93 | /// \param z The z coordinate of the top left point. | ||
| 94 | /// \param w The width. | ||
| 95 | /// \param h The height. | ||
| 96 | /// \param d The depth. | ||
| 97 | /// \param pyrLvl The pyramid level. | ||
| 98 | 4 | LogicalPositionInfo3D(double x, double y, double z, double w, double h, double d, int pyrLvl) : posX(x), posY(y), posZ(z), width(w), height(h), depth(d), pyrLvl(pyrLvl) | |
| 99 | 4 | {} | |
| 100 | |||
| 101 | /// Equality operator (where the coordinates are compared with an epsilon). | ||
| 102 | /// \param rhs The right hand side. | ||
| 103 | /// \returns True if the parameters are considered equivalent. | ||
| 104 | 10 | bool operator==(const LogicalPositionInfo3D& rhs) const | |
| 105 | { | ||
| 106 | 10 | constexpr double kDoubleEpsilon = 1e-8; | |
| 107 | 1/2✓ Branch 0 taken 6 times. ✗ Branch 1 not taken. | 6 | return this->pyrLvl == rhs.pyrLvl && | 
| 108 | 1/2✓ Branch 1 taken 6 times. ✗ Branch 2 not taken. | 12 | imgdoc2::approximatelyEqual(this->posX, rhs.posX, kDoubleEpsilon) && | 
| 109 | 1/2✓ Branch 1 taken 6 times. ✗ Branch 2 not taken. | 12 | imgdoc2::approximatelyEqual(this->posY, rhs.posY, kDoubleEpsilon) && | 
| 110 | 1/2✓ Branch 1 taken 6 times. ✗ Branch 2 not taken. | 12 | imgdoc2::approximatelyEqual(this->posZ, rhs.posZ, kDoubleEpsilon) && | 
| 111 | 1/2✓ Branch 1 taken 6 times. ✗ Branch 2 not taken. | 12 | imgdoc2::approximatelyEqual(this->width, rhs.width, kDoubleEpsilon) && | 
| 112 | 3/4✓ Branch 0 taken 6 times. ✓ Branch 1 taken 4 times. ✓ Branch 3 taken 6 times. ✗ Branch 4 not taken. | 22 | imgdoc2::approximatelyEqual(this->height, rhs.height, kDoubleEpsilon) && | 
| 113 | 16 | imgdoc2::approximatelyEqual(this->depth, rhs.depth, kDoubleEpsilon); | |
| 114 | } | ||
| 115 | |||
| 116 | /// Inequality operator (where the coordinates are compared with an epsilon). | ||
| 117 | /// \param rhs The right hand side. | ||
| 118 | /// \returns True if the parameters are not considered equivalent. | ||
| 119 | 4 | bool operator!=(const LogicalPositionInfo3D& rhs) const | |
| 120 | { | ||
| 121 | 4 | return !this->operator==(rhs); | |
| 122 | } | ||
| 123 | }; | ||
| 124 | } | ||
| 125 |