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 slideio
10{
11 class Rect {
12 public:
13 Rect() : x(0), y(0), width(0), height(0){}
14 Rect(int32_t _x, int32_t _y, int32_t _width, int32_t _height) {
15 x = _x;
16 y = _y;
17 width = _width;
18 height = _height;
19 }
20 Rect(const Rect& r) = default;
21 Rect(Rect&& r) noexcept {
22 x = r.x;
23 y = r.y;
24 width = r.width;
25 height = r.height;
26 r.x = r.y = r.width = r.height = 0;
27 }
28 ~Rect() = default;
29 Rect& operator = (const Rect& r) = default;
30 Rect& operator = (Rect&& r) noexcept {
31 x = r.x;
32 y = r.y;
33 width = r.width;
34 height = r.height;
35 r.x = r.y = r.width = r.height = 0;
36 return *this;
37 }
38 Size size() const {
39 return { width, height };
40 }
41 int32_t area() const {
42 return width * height;
43 }
44 bool empty() const {
45 return width <= 0 || height <= 0;
46 }
47 friend std::ostream& operator<<(std::ostream& os, const Rect& rect) {
48 os << "Rect (x: " << rect.x << ", y: " << rect.y << ", width: " << rect.width << ", height: " << rect.height << ")";
49 return os;
50 }
51 bool valid() const {
52 return x >= 0 && y >= 0 && width > 0 && height > 0;
53 }
54 int32_t x;
55 int32_t y;
56 int32_t width;
57 int32_t height;
58 };
59
60}
Definition: exceptions.hpp:15