/**
 * @file Rect.h
 * @author apio (cloudapio.eu)
 * @brief A simple 2D rectangle representation.
 *
 * @copyright Copyright (c) 2023, the Luna authors.
 *
 */

#pragma once
#include <ui/Point.h>

namespace ui
{
    /**
     * @brief A simple rectangle.
     */
    struct Rect
    {
        Point pos;
        int width;
        int height;

        /**
         * @brief Check if a point is contained in this rectangle.
         *
         * @param point The point to check.
         * @return true The point is contained inside the rectangle.
         * @return false The point is not contained inside the rectangle.
         */
        bool contains(Point point);

        /**
         * @brief Check if another rectangle is contained in this one.
         *
         * @param point The rectangle to check.
         * @return true The other rectangle is contained inside this one.
         * @return false The other rectangle is not contained inside this one.
         */
        bool contains(Rect rect);

        /**
         * @brief Normalize a point to fit inside this rectangle.
         *
         * @param point The original point.
         * @return Point The normalized point.
         */
        Point normalize(Point point);

        /**
         * @brief Transform an absolute position to a position relative to this rectangle.
         *
         * @param pos The original absolute position.
         * @return Point The position relative to this rectangle.
         */
        Point relative(Point pos);

        /**
         * @brief Transform a position relative to this rectangle to an absolute position.
         *
         * @param pos The original relative position.
         * @return Point The absolute position.
         */
        Point absolute(Point pos);

        /**
         * @brief Transform another rectangle relative to this one to an absolute rectangle.
         *
         * @param rect The original relative rectangle.
         * @return Point The absolute rectangle.
         */
        Rect absolute(Rect rect);

        /**
         * @brief Return a copy of this rectangle with no negative values (normalized to 0).
         *
         * @return Rect The new rectangle.
         */
        Rect normalized();
    };
}