SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
rect.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#pragma once
5#include <cstdint>
6#include <ostream>
7#include "size.hpp"
8
9namespace cv {
10 template<typename _Tp> class Rect_;
11 typedef Rect_<int> Rect;
12}
13
14namespace slideio
15{
16 class Rect {
17 public:
18 Rect() : x(0), y(0), width(0), height(0){}
19 Rect(int32_t _x, int32_t _y, int32_t _width, int32_t _height) {
20 x = _x;
21 y = _y;
22 width = _width;
23 height = _height;
24 }
25 Rect(const Rect& r) = default;
26 Rect(Rect&& r) noexcept {
27 x = r.x;
28 y = r.y;
29 width = r.width;
30 height = r.height;
31 r.x = r.y = r.width = r.height = 0;
32 }
33 Rect(const cv::Rect& cvRect);
34 ~Rect() = default;
35 Rect& operator = (const Rect& r) = default;
36 Rect& operator = (Rect&& r) noexcept {
37 x = r.x;
38 y = r.y;
39 width = r.width;
40 height = r.height;
41 r.x = r.y = r.width = r.height = 0;
42 return *this;
43 }
44 Rect& operator = (const cv::Rect& cvRect);
45 operator cv::Rect() const;
46 Size size() const {
47 return { width, height };
48 }
49 int32_t area() const {
50 return width * height;
51 }
52 bool empty() const {
53 return width <= 0 || height <= 0;
54 }
55 friend std::ostream& operator<<(std::ostream& os, const Rect& rect) {
56 os << "Rect (x: " << rect.x << ", y: " << rect.y << ", width: " << rect.width << ", height: " << rect.height << ")";
57 return os;
58 }
59 friend bool operator==(const Rect& lhs, const Rect& rhs) {
60 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height;
61 }
62 bool valid() const {
63 return x >= 0 && y >= 0 && width > 0 && height > 0;
64 }
65 int32_t x;
66 int32_t y;
67 int32_t width;
68 int32_t height;
69 };
70
71}
72
73#if defined(SLIDEIO_INTERNAL_HEADER)
74#include "rect.inl"
75#endif
Definition: exceptions.hpp:15