/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file c_wgl_rect.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This header file contains public interfaces, constant and type 
 *         definitions of the Widget Library.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @addtogroup groupMW_WGL
 *  @{ 
 */
/*----------------------------------------------------------------------------*/
 
#ifndef _C_WGL_RECT_H_
#define _C_WGL_RECT_H_

/*-----------------------------------------------------------------------------
                    include files
 ----------------------------------------------------------------------------*/
#include "u_wgl_rect.h"

#ifdef __cplusplus
extern "C" {
#endif

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/


/*-----------------------------------------------------------------------------
                    structures
 ----------------------------------------------------------------------------*/


/*-----------------------------------------------------------------------------
                    functions
 ----------------------------------------------------------------------------*/

/*------------------------------------------------------------------*/
/*! @brief This function sets the rectangle with specified values. 
 *  @param [in]  i4_left The x coordinate of the upper-left corner of the rectangle. 
  *  @param [in] i4_top  The y coordinate of the upper-left corner of the rectangle. 
 *  @param [in]  i4_right    The x coordinate of the lower-right corner of the rectangle. 
 *  @param [in]  i4_bottom   The y coordinate of the lower-right corner of the rectangle.
 *  @param [out] pt_rect	Pointer to the rectangle.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval  WGLR_OK     The routine was successful.
  *  @retval WGLR_INV_ARG    The argument pt_rect is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_set(
        GL_RECT_T*                      pt_rect,
        INT32                           i4_left,
        INT32                           i4_top,
        INT32                           i4_right,
        INT32                           i4_bottom);


/*------------------------------------------------------------------*/
/*! @brief This function copies the coordinates of the source rectangle pointed to by pt_src_rect to the destination rectangle pointed to by pt_dest_rect.
 *  @param [in] pt_src_rect	Pointer to the source rectangle.
 *  @param [out] pt_dest _rect	Pointer to the destination rectangle. 
 *  @note
 *  @see
 *  @return  return error code
 *  @retval  WGLR_OK     The routine was successful.
  *  @retval WGLR_INV_ARG    The argument pt_src_rect or pt_dest_rect is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_copy(
        GL_RECT_T*                      pt_dest_rect,
        const GL_RECT_T*                pt_src_rect);


/*------------------------------------------------------------------*/
/*! @brief This function increases or decreases the width and height of the specified rectangle pt_rect. This function adds cx units to the right of the rectangle and cy units to the bottom. Positive values increases the width and height, and negative values decreases them.
 *  @param [in]  i4_cx   The value inflating the width of the rectangle.
 *  @param [in]  i4_cy   The value inflating the height of the rectangle.
 *  @param [out] pt_rect	Pointer to the rectangle.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval  WGLR_OK     The routine was successful.
  *  @retval WGLR_INV_ARG    The argument pt_rect is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_inflate(
        GL_RECT_T*                      pt_rect,
        INT32                           i4_cx,
        INT32                           i4_cy);


/*------------------------------------------------------------------*/
/*! @brief This function calculates the intersection of two source rectangles (pt_src_rect1 and pt_src_rect2) and places the coordinates of the intersection rectangle into the destination rectangle pointed to by pt_intersect_rect. If the source rectangles do not intersect, and empty rectangle (in which all coordinates are set to zero) is placed into the destination rectangle.
 *  @param [in]  pt_src_rect1    Pointer to the first source rectangle.
 *  @param [in]  pt_src_rect2    Pointer to the second source rectangle.
 *  @param [out] pt_intersect_rect	Pointer to the destination rectangle.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval  WGLR_OK     The routine was successful.
 *  @retval WGLR_INV_ARG    The argument pt_dest_rect, pt_src_rect1, or pt_src_rect2 is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_intersect(
        GL_RECT_T*                      pt_intersect_rect,
        const GL_RECT_T*                pt_src_rect1,
        const GL_RECT_T*                pt_src_rect2);


/*------------------------------------------------------------------*/
/*! @brief This function calculates the union of two source rectangles (pt_src_rect1 and pt_src_rect2) and places the coordinates of the union rectangle into the destination rectangle pointed to by pt_union_rect.
 *  @param [in]  pt_src_rect1    Pointer to the first source rectangle.
  *  @param [in] pt_src_rect2    Pointer to the second source rectangle.
 *  @param [out] pt_union _rect	Pointer to the destination rectangle.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval  WGLR_OK     The routine was successful.
  *  @retval  WGLR_INV_ARG    The argument pt_union_rect, pt_src_rect1, or pt_src_rect2 is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_union(
        GL_RECT_T*                      pt_union_rect,
        const GL_RECT_T*                pt_src_rect1,
        const GL_RECT_T*                pt_src_rect2);


/*------------------------------------------------------------------*/
/*! @brief This function moves the specified rectangle by the specified offsets. if i4_x is a negative value, the rectangle would be moved to the left, and if i4_y is a negative value, it would be moved up.
 *  @param [in]  i4_x    The x offset.
  *  @param [in]  i4_y    The y offset.
 *  @param [out] pt_rect	Pointer to the rectangle.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval  WGLR_OK     The routine was successful.
 *  @retval WGLR_INV_ARG    The argument pt_rect is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_offset(
        GL_RECT_T*                      pt_rect,
        INT32                           i4_x,
        INT32                           i4_y);

/*------------------------------------------------------------------*/
/*! @brief inset the specified rectange by the specified inset
 *  @param [in]  i4_left left inset 
 *  @param [in]  i4_top top inset 
 *  @param [in]  i4_right right inset 
 *  @param [in]  i4_bottom bottom inset 
 *  @param [out] [out] pt_rect	Pointer to the rectangle.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval   WGLR_OK     The routine was successful.
 *  @retval  WGLR_INV_ARG    The argument pt_rect is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_inset(
        GL_RECT_T*                      pt_rect,
        INT32                           i4_left,
        INT32                           i4_top,
        INT32                           i4_right,
        INT32                           i4_bottom);

/*------------------------------------------------------------------*/
/*! @brief This function empties the rectangle pointed to by pt_rect. After this function, all coordinates of the rectangle would be zero.
 *  @param [in] None.
 *  @param [out] pt_rect	Pointer to the rectangle.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval   WGLR_OK     The routine was successful.
 *  @retval  WGLR_INV_ARG    The argument pt_rect is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_empty(
        GL_RECT_T*                      pt_rect);


/*------------------------------------------------------------------*/
/*! @brief This function  normalizes the rectangle. After this function,  the left would be less than the right, and the top would be less than the bottom.
 *  @param [in] None
 *  @param [out]  pt_rect	Pointer to the rectangle.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval  WGLR_OK     The routine was successful.
  *  @retval WGLR_INV_ARG    The argument pt_rect is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_normalize(
        GL_RECT_T*                      pt_rect);


/*------------------------------------------------------------------*/
/*! @brief This function determines whether the two specified rectangles (pt_rect1 and pt_rect2) are equal by comparing the coordinates of the upper-left and lower-right corners.
 *  @param [in]   pt_rect1    Pointer to the source rectangle.
 *  @param [in]   pt_rect2    Pointer to the source rectangle.
 *  @param [out]  pb_is_equal	Pointer to a BOOL variable to receive the result.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval   WGLR_OK     The routine was successful.
 *  @retval   WGLR_INV_ARG    The argument pt_rect1, pt_rect2, or pb_is_equal is NULL
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_equal(
        BOOL*                           pb_is_equal,
        const GL_RECT_T*                pt_rect1,
        const GL_RECT_T*                pt_rect2);


/*------------------------------------------------------------------*/
/*! @brief This function determines whether the specified rectangle pt_rect is empty. An empty rectangle is one that has no area; that is, the coordinates of the right side is equal to the coordinate of the left side, or the coordinates of the bottom side is equal to the coordinate of the top side.
 *  @param [in] pt_rect	Pointer to the source rectangle.
 *  @param [out]  pb_is_empty	Pointer to a BOOL variable to receive the result.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval  WGLR_OK     The routine was successful.
 *  @retval  WGLR_INV_ARG    The argument pt_rect or pb_is_empty is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_is_empty(
        BOOL*                           pb_is_empty,
        const GL_RECT_T*                pt_rect);


/*------------------------------------------------------------------*/
/*! @brief This function determines whether two rectangles (pt_rect1 and pt_rect2) intersect.
 *  @param [in]   pt_rect1    Pointer to the first rectangle.
 *  @param [in]   pt_rect2    Pointer to the second rectangle.
 *  @param [out] pb_is_cross	Pointer to a BOOL variable to receive the result.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval   WGLR_OK     The routine was successful.
 *  @retval  WGLR_INV_ARG    The argument pt_rect1, pt_rect2, or pb_is_cross is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_is_cross(
        BOOL*                           pb_is_intersected,
        const GL_RECT_T*                pt_rect1,
        const GL_RECT_T*                pt_rect2);


/*------------------------------------------------------------------*/
/*! @brief This function determines whether pt_rect1 includes pt_rect2.
 *  @param [in]   pt_rect1    Pointer to the first rectangle.
 *  @param [in] pt_rect2    Pointer to the second rectangle.
 *  @param [out]  pb_is_included	Pointer to a BOOL variable to receive the result.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval   WGLR_OK     The routine was successful.
 *  @retval   WGLR_INV_ARG    The argument pt_rect1, pt_rect2, or pb_is_included is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_is_included(
        BOOL*                           pb_is_included,
        const GL_RECT_T*                pt_rect1,
        const GL_RECT_T*                pt_rect2);


/*------------------------------------------------------------------*/
/*! @brief This function determines whether pt_point is in pt_rect.
 *  @param [in]   pt_rect Pointer to the rectangle.
 *  @param [in]   pt_point    Pointer to the point.
 *  @param [out]  pb_is_included	Pointer to a BOOL variable to receive the result.
 *  @note
 *  @see
 *  @return  return error code
 *  @retval   WGLR_OK     The routine was successful.
 *  @retval   WGLR_INV_ARG    The argument pt_rect, pt_point, or pb_is_included is NULL.
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 c_wgl_rect_is_point_included (
        BOOL*                           pb_is_included,
        const GL_RECT_T*                pt_rect,
        const GL_POINT_T*               pt_point);


#ifdef __cplusplus
}
#endif

#endif

/*----------------------------------------------------------------------------*/
/*! @} */   /* end of  groupMW_WGL*/
/*----------------------------------------------------------------------------*/



