1 // This file is part of OpenCV 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://opencv.org/license.html.
5 // Copyright (C) 2018-2019 Intel Corporation
8 #ifndef OPENCV_GAPI_TYPES_HPP
9 #define OPENCV_GAPI_TYPES_HPP
11 #include <algorithm> // std::max, std::min
25 Point(int _x, int _y) : x(_x), y(_y) {};
35 Rect(int _x, int _y, int _width, int _height) : x(_x), y(_y), width(_width), height(_height) {};
36 #if !defined(GAPI_STANDALONE)
37 Rect(const cv::Rect& other) : x(other.x), y(other.y), width(other.width), height(other.height) {};
38 inline Rect& operator=(const cv::Rect& other)
43 height = other.height;
46 #endif // !defined(GAPI_STANDALONE)
48 int x = 0; //!< x coordinate of the top-left corner
49 int y = 0; //!< y coordinate of the top-left corner
50 int width = 0; //!< width of the rectangle
51 int height = 0; //!< height of the rectangle
54 inline bool operator==(const Rect& lhs, const Rect& rhs)
56 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height;
59 inline bool operator!=(const Rect& lhs, const Rect& rhs)
64 inline Rect& operator&=(Rect& lhs, const Rect& rhs)
66 int x1 = std::max(lhs.x, rhs.x);
67 int y1 = std::max(lhs.y, rhs.y);
68 lhs.width = std::min(lhs.x + lhs.width, rhs.x + rhs.width) - x1;
69 lhs.height = std::min(lhs.y + lhs.height, rhs.y + rhs.height) - y1;
72 if( lhs.width <= 0 || lhs.height <= 0 )
77 inline const Rect operator&(const Rect& lhs, const Rect& rhs)
83 inline std::ostream& operator<<(std::ostream& o, const Rect& rect)
85 return o << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]";
92 Size(int _width, int _height) : width(_width), height(_height) {};
93 #if !defined(GAPI_STANDALONE)
94 Size(const cv::Size& other) : width(other.width), height(other.height) {};
95 inline Size& operator=(const cv::Size& rhs)
101 #endif // !defined(GAPI_STANDALONE)
107 inline Size& operator+=(Size& lhs, const Size& rhs)
109 lhs.width += rhs.width;
110 lhs.height += rhs.height;
114 inline bool operator==(const Size& lhs, const Size& rhs)
116 return lhs.width == rhs.width && lhs.height == rhs.height;
119 inline bool operator!=(const Size& lhs, const Size& rhs)
121 return !(lhs == rhs);
125 inline std::ostream& operator<<(std::ostream& o, const Size& s)
127 o << "[" << s.width << " x " << s.height << "]";
135 #endif // OPENCV_GAPI_TYPES_HPP