#ifndef OPENPOSE_CORE_RECTANGLE_HPP #define OPENPOSE_CORE_RECTANGLE_HPP #include #include #include namespace op { template 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 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. * @param rectangle Rectangle to be copied. */ Rectangle(const Rectangle& rectangle); /** * Copy assignment. * Similar to Rectangle(const Rectangle& rectangle). * @param rectangle Rectangle to be copied. * @return The resulting Rectangle. */ Rectangle& operator=(const Rectangle& rectangle); /** * Move constructor. * It destroys the original Rectangle to be moved. * @param rectangle Rectangle to be moved. */ Rectangle(Rectangle&& rectangle); /** * Move assignment. * Similar to Rectangle(Rectangle&& rectangle). * @param rectangle Rectangle to be moved. * @return The resulting Rectangle. */ Rectangle& operator=(Rectangle&& rectangle); Point center() const; inline Point topLeft() const { return Point{x, y}; } Point 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 data. Useful for debugging. * The format is: `[x, y, width, height]` * @return A string with the Rectangle values in the above format. */ std::string toString() const; // ------------------------------ Basic Operators ------------------------------ // Rectangle& operator*=(const T value); Rectangle operator*(const T value) const; Rectangle& operator/=(const T value); Rectangle operator/(const T value) const; }; // Static methods template Rectangle recenter(const Rectangle& rectangle, const T newWidth, const T newHeight); OVERLOAD_C_OUT(Rectangle) } #endif // OPENPOSE_CORE_RECTANGLE_HPP