File size: 2,758 Bytes
7fc5a59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef OPENPOSE_CORE_RECTANGLE_HPP
#define OPENPOSE_CORE_RECTANGLE_HPP

#include <string>
#include <openpose/core/macros.hpp>
#include <openpose/core/point.hpp>

namespace op
{
    template<typename T>
    struct Rectangle
    {
        T x;
        T y;
        T width;
        T height;

        Rectangle(const T x = 0, const T y = 0, const T width = 0, const T height = 0);

        /**
         * Copy constructor.
         * It performs `fast copy`: For performance purpose, copying a Rectangle<T> or Datum or cv::Mat just copies
         * the reference, it still shares the same internal data.
         * Modifying the copied element will modify the original one.
         * Use clone() for a slower but real copy, similarly to cv::Mat and Rectangle<T>.
         * @param rectangle Rectangle to be copied.
         */
        Rectangle<T>(const Rectangle<T>& rectangle);

        /**
         * Copy assignment.
         * Similar to Rectangle<T>(const Rectangle<T>& rectangle).
         * @param rectangle Rectangle to be copied.
         * @return The resulting Rectangle.
         */
        Rectangle<T>& operator=(const Rectangle<T>& rectangle);

        /**
         * Move constructor.
         * It destroys the original Rectangle to be moved.
         * @param rectangle Rectangle to be moved.
         */
        Rectangle<T>(Rectangle<T>&& rectangle);

        /**
         * Move assignment.
         * Similar to Rectangle<T>(Rectangle<T>&& rectangle).
         * @param rectangle Rectangle to be moved.
         * @return The resulting Rectangle.
         */
        Rectangle<T>& operator=(Rectangle<T>&& rectangle);

        Point<T> center() const;

        inline Point<T> topLeft() const
        {
            return Point<T>{x, y};
        }

        Point<T> bottomRight() const;

        inline T area() const
        {
            return width * height;
        }

        void recenter(const T newWidth, const T newHeight);

        /**
         * It returns a string with the whole Rectangle<T> data. Useful for debugging.
         * The format is: `[x, y, width, height]`
         * @return A string with the Rectangle<T> values in the above format.
         */
        std::string toString() const;

        // ------------------------------ Basic Operators ------------------------------ //
        Rectangle<T>& operator*=(const T value);

        Rectangle<T> operator*(const T value) const;

        Rectangle<T>& operator/=(const T value);

        Rectangle<T> operator/(const T value) const;
    };

    // Static methods
    template<typename T>
    Rectangle<T> recenter(const Rectangle<T>& rectangle, const T newWidth, const T newHeight);

    OVERLOAD_C_OUT(Rectangle)
}

#endif // OPENPOSE_CORE_RECTANGLE_HPP