1bafb9395Sopenharmony_ci/* 2bafb9395Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3bafb9395Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bafb9395Sopenharmony_ci * you may not use this file except in compliance with the License. 5bafb9395Sopenharmony_ci * You may obtain a copy of the License at 6bafb9395Sopenharmony_ci * 7bafb9395Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bafb9395Sopenharmony_ci * 9bafb9395Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bafb9395Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bafb9395Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bafb9395Sopenharmony_ci * See the License for the specific language governing permissions and 13bafb9395Sopenharmony_ci * limitations under the License. 14bafb9395Sopenharmony_ci */ 15bafb9395Sopenharmony_ci 16bafb9395Sopenharmony_ci/** 17bafb9395Sopenharmony_ci * @addtogroup UI_Utils 18bafb9395Sopenharmony_ci * @{ 19bafb9395Sopenharmony_ci * 20bafb9395Sopenharmony_ci * @brief Defines basic UI utils. 21bafb9395Sopenharmony_ci * 22bafb9395Sopenharmony_ci * @since 1.0 23bafb9395Sopenharmony_ci * @version 1.0 24bafb9395Sopenharmony_ci */ 25bafb9395Sopenharmony_ci 26bafb9395Sopenharmony_ci/** 27bafb9395Sopenharmony_ci * @file rect.h 28bafb9395Sopenharmony_ci * 29bafb9395Sopenharmony_ci * @brief Defines a rectangle, including the position data of the four boundaries of the rectangle, and provides 30bafb9395Sopenharmony_ci * functions for rectangle inclusion, intersection, and aggregation. 31bafb9395Sopenharmony_ci * @since 1.0 32bafb9395Sopenharmony_ci * @version 1.0 33bafb9395Sopenharmony_ci */ 34bafb9395Sopenharmony_ci 35bafb9395Sopenharmony_ci#ifndef GRAPHIC_LITE_RECT_H 36bafb9395Sopenharmony_ci#define GRAPHIC_LITE_RECT_H 37bafb9395Sopenharmony_ci 38bafb9395Sopenharmony_ci#include "gfx_utils/graphic_math.h" 39bafb9395Sopenharmony_ci#include "gfx_utils/graphic_types.h" 40bafb9395Sopenharmony_ci#include "gfx_utils/heap_base.h" 41bafb9395Sopenharmony_ci 42bafb9395Sopenharmony_cinamespace OHOS { 43bafb9395Sopenharmony_ci/** 44bafb9395Sopenharmony_ci * @brief Defines a rectangle, including the position data of the four boundaries of the rectangle, and provides 45bafb9395Sopenharmony_ci * functions for rectangle inclusion, intersection, and aggregation. 46bafb9395Sopenharmony_ci * @since 1.0 47bafb9395Sopenharmony_ci * @version 1.0 48bafb9395Sopenharmony_ci */ 49bafb9395Sopenharmony_citemplate <typename T> class CommonRect : public HeapBase { 50bafb9395Sopenharmony_cipublic: 51bafb9395Sopenharmony_ci /** 52bafb9395Sopenharmony_ci * @brief A constructor used to create a <b>CommonRect</b> instance. 53bafb9395Sopenharmony_ci * @since 1.0 54bafb9395Sopenharmony_ci * @version 1.0 55bafb9395Sopenharmony_ci */ 56bafb9395Sopenharmony_ci CommonRect() : left_(0), top_(0), right_(0), bottom_(0) {} 57bafb9395Sopenharmony_ci 58bafb9395Sopenharmony_ci /** 59bafb9395Sopenharmony_ci * @brief A destructor used to delete the <b>CommonRect</b> instance. 60bafb9395Sopenharmony_ci * @since 1.0 61bafb9395Sopenharmony_ci * @version 1.0 62bafb9395Sopenharmony_ci */ 63bafb9395Sopenharmony_ci ~CommonRect() {} 64bafb9395Sopenharmony_ci 65bafb9395Sopenharmony_ci /** 66bafb9395Sopenharmony_ci * @brief A constructor used to create a <b>CommonRect</b> instance based on the coordinates of the four boundaries. 67bafb9395Sopenharmony_ci * @param left Indicates the coordinate of the left boundary. 68bafb9395Sopenharmony_ci * @param top Indicates the coordinate of the top boundary. 69bafb9395Sopenharmony_ci * @param right Indicates the coordinate of the right boundary. 70bafb9395Sopenharmony_ci * @param bottom Indicates the coordinate of the bottom boundary. 71bafb9395Sopenharmony_ci * @since 1.0 72bafb9395Sopenharmony_ci * @version 1.0 73bafb9395Sopenharmony_ci */ 74bafb9395Sopenharmony_ci CommonRect(T left, T top, T right, T bottom) : left_(left), top_(top), right_(right), bottom_(bottom) {} 75bafb9395Sopenharmony_ci 76bafb9395Sopenharmony_ci /** 77bafb9395Sopenharmony_ci * @brief A constructor used to create a <b>CommonRect</b> instance by copying another rectangle. 78bafb9395Sopenharmony_ci * 79bafb9395Sopenharmony_ci * @param other Indicates the rectangle to copy. 80bafb9395Sopenharmony_ci * @since 1.0 81bafb9395Sopenharmony_ci * @version 1.0 82bafb9395Sopenharmony_ci */ 83bafb9395Sopenharmony_ci CommonRect(const CommonRect<T>& other) = default; 84bafb9395Sopenharmony_ci 85bafb9395Sopenharmony_ci /** 86bafb9395Sopenharmony_ci * @brief A constructor used to create a <b>CommonRect</b> instance by copying another rectangle. 87bafb9395Sopenharmony_ci * 88bafb9395Sopenharmony_ci * @param other Indicates the rectangle to copy. 89bafb9395Sopenharmony_ci * @since 1.0 90bafb9395Sopenharmony_ci * @version 1.0 91bafb9395Sopenharmony_ci */ 92bafb9395Sopenharmony_ci CommonRect(CommonRect<T>&& other) = default; 93bafb9395Sopenharmony_ci 94bafb9395Sopenharmony_ci /** 95bafb9395Sopenharmony_ci * @brief Sets the coordinates of the four boundaries of a rectangle. 96bafb9395Sopenharmony_ci * 97bafb9395Sopenharmony_ci * @param left Indicates the coordinate of the left boundary. 98bafb9395Sopenharmony_ci * @param top Indicates the coordinate of the top boundary. 99bafb9395Sopenharmony_ci * @param right Indicates the coordinate of the right boundary. 100bafb9395Sopenharmony_ci * @param bottom Indicates the coordinate of the bottom boundary. 101bafb9395Sopenharmony_ci * @since 1.0 102bafb9395Sopenharmony_ci * @version 1.0 103bafb9395Sopenharmony_ci */ 104bafb9395Sopenharmony_ci void SetRect(T left, T top, T right, T bottom) 105bafb9395Sopenharmony_ci { 106bafb9395Sopenharmony_ci left_ = left; 107bafb9395Sopenharmony_ci right_ = right; 108bafb9395Sopenharmony_ci top_ = top; 109bafb9395Sopenharmony_ci bottom_ = bottom; 110bafb9395Sopenharmony_ci } 111bafb9395Sopenharmony_ci 112bafb9395Sopenharmony_ci /** 113bafb9395Sopenharmony_ci * @brief Obtains the rectangle width. 114bafb9395Sopenharmony_ci * @return Returns the rectangle width. 115bafb9395Sopenharmony_ci * @since 1.0 116bafb9395Sopenharmony_ci * @version 1.0 117bafb9395Sopenharmony_ci */ 118bafb9395Sopenharmony_ci T GetWidth() const 119bafb9395Sopenharmony_ci { 120bafb9395Sopenharmony_ci return right_ - left_ + 1; 121bafb9395Sopenharmony_ci } 122bafb9395Sopenharmony_ci 123bafb9395Sopenharmony_ci /** 124bafb9395Sopenharmony_ci * @brief Obtains the rectangle height. 125bafb9395Sopenharmony_ci * @return Returns the rectangle height. 126bafb9395Sopenharmony_ci * @since 1.0 127bafb9395Sopenharmony_ci * @version 1.0 128bafb9395Sopenharmony_ci */ 129bafb9395Sopenharmony_ci T GetHeight() const 130bafb9395Sopenharmony_ci { 131bafb9395Sopenharmony_ci return bottom_ - top_ + 1; 132bafb9395Sopenharmony_ci } 133bafb9395Sopenharmony_ci 134bafb9395Sopenharmony_ci /** 135bafb9395Sopenharmony_ci * @brief Obtains the left boundary coordinate of the rectangle. 136bafb9395Sopenharmony_ci * @return Returns the left boundary coordinate. 137bafb9395Sopenharmony_ci * @since 1.0 138bafb9395Sopenharmony_ci * @version 1.0 139bafb9395Sopenharmony_ci */ 140bafb9395Sopenharmony_ci T GetX() const 141bafb9395Sopenharmony_ci { 142bafb9395Sopenharmony_ci return left_; 143bafb9395Sopenharmony_ci } 144bafb9395Sopenharmony_ci 145bafb9395Sopenharmony_ci /** 146bafb9395Sopenharmony_ci * @brief Obtains the top boundary coordinate of the rectangle. 147bafb9395Sopenharmony_ci * @return Returns the top boundary coordinate. 148bafb9395Sopenharmony_ci * @since 1.0 149bafb9395Sopenharmony_ci * @version 1.0 150bafb9395Sopenharmony_ci */ 151bafb9395Sopenharmony_ci T GetY() const 152bafb9395Sopenharmony_ci { 153bafb9395Sopenharmony_ci return top_; 154bafb9395Sopenharmony_ci } 155bafb9395Sopenharmony_ci 156bafb9395Sopenharmony_ci /** 157bafb9395Sopenharmony_ci * @brief Obtains the left boundary coordinate of the rectangle. 158bafb9395Sopenharmony_ci * @return Returns the left boundary coordinate. 159bafb9395Sopenharmony_ci * @since 1.0 160bafb9395Sopenharmony_ci * @version 1.0 161bafb9395Sopenharmony_ci */ 162bafb9395Sopenharmony_ci T GetLeft() const 163bafb9395Sopenharmony_ci { 164bafb9395Sopenharmony_ci return left_; 165bafb9395Sopenharmony_ci } 166bafb9395Sopenharmony_ci 167bafb9395Sopenharmony_ci /** 168bafb9395Sopenharmony_ci * @brief Obtains the top boundary coordinate of the rectangle. 169bafb9395Sopenharmony_ci * @return Returns the top boundary coordinate. 170bafb9395Sopenharmony_ci * @since 1.0 171bafb9395Sopenharmony_ci * @version 1.0 172bafb9395Sopenharmony_ci */ 173bafb9395Sopenharmony_ci T GetTop() const 174bafb9395Sopenharmony_ci { 175bafb9395Sopenharmony_ci return top_; 176bafb9395Sopenharmony_ci } 177bafb9395Sopenharmony_ci 178bafb9395Sopenharmony_ci /** 179bafb9395Sopenharmony_ci * @brief Obtains the right boundary coordinate of the rectangle. 180bafb9395Sopenharmony_ci * @return Returns the right boundary coordinate. 181bafb9395Sopenharmony_ci * @since 1.0 182bafb9395Sopenharmony_ci * @version 1.0 183bafb9395Sopenharmony_ci */ 184bafb9395Sopenharmony_ci T GetRight() const 185bafb9395Sopenharmony_ci { 186bafb9395Sopenharmony_ci return right_; 187bafb9395Sopenharmony_ci } 188bafb9395Sopenharmony_ci 189bafb9395Sopenharmony_ci /** 190bafb9395Sopenharmony_ci * @brief Obtains the bottom boundary coordinate of the rectangle. 191bafb9395Sopenharmony_ci * @return Returns the bottom boundary coordinate. 192bafb9395Sopenharmony_ci * @since 1.0 193bafb9395Sopenharmony_ci * @version 1.0 194bafb9395Sopenharmony_ci */ 195bafb9395Sopenharmony_ci T GetBottom() const 196bafb9395Sopenharmony_ci { 197bafb9395Sopenharmony_ci return bottom_; 198bafb9395Sopenharmony_ci } 199bafb9395Sopenharmony_ci 200bafb9395Sopenharmony_ci /** 201bafb9395Sopenharmony_ci * @brief Changes the left boundary coordinate of the rectangle without changing the rectangle width. 202bafb9395Sopenharmony_ci * @param x Indicates the coordinate of the left boundary. 203bafb9395Sopenharmony_ci * @since 1.0 204bafb9395Sopenharmony_ci * @version 1.0 205bafb9395Sopenharmony_ci */ 206bafb9395Sopenharmony_ci void SetX(T x) 207bafb9395Sopenharmony_ci { 208bafb9395Sopenharmony_ci right_ += x - left_; 209bafb9395Sopenharmony_ci left_ = x; 210bafb9395Sopenharmony_ci } 211bafb9395Sopenharmony_ci 212bafb9395Sopenharmony_ci /** 213bafb9395Sopenharmony_ci * @brief Changes the top boundary coordinate of the rectangle without changing the rectangle height. 214bafb9395Sopenharmony_ci * @param y Indicates the coordinate of the top boundary. 215bafb9395Sopenharmony_ci * @since 1.0 216bafb9395Sopenharmony_ci * @version 1.0 217bafb9395Sopenharmony_ci */ 218bafb9395Sopenharmony_ci void SetY(T y) 219bafb9395Sopenharmony_ci { 220bafb9395Sopenharmony_ci bottom_ += y - top_; 221bafb9395Sopenharmony_ci top_ = y; 222bafb9395Sopenharmony_ci } 223bafb9395Sopenharmony_ci 224bafb9395Sopenharmony_ci /** 225bafb9395Sopenharmony_ci * @brief Changes the coordinates of the left and top boundaries of the rectangle without changing the rectangle 226bafb9395Sopenharmony_ci * width and height. 227bafb9395Sopenharmony_ci * @param x Indicates the coordinate of the left boundary. 228bafb9395Sopenharmony_ci * @param y Indicates the coordinate of the top boundary. 229bafb9395Sopenharmony_ci * @since 1.0 230bafb9395Sopenharmony_ci * @version 1.0 231bafb9395Sopenharmony_ci */ 232bafb9395Sopenharmony_ci void SetPosition(T x, T y) 233bafb9395Sopenharmony_ci { 234bafb9395Sopenharmony_ci right_ += x - left_; 235bafb9395Sopenharmony_ci bottom_ += y - top_; 236bafb9395Sopenharmony_ci left_ = x; 237bafb9395Sopenharmony_ci top_ = y; 238bafb9395Sopenharmony_ci } 239bafb9395Sopenharmony_ci 240bafb9395Sopenharmony_ci /** 241bafb9395Sopenharmony_ci * @brief Changes the width of the rectangle without changing the coordinate of the left boundary. 242bafb9395Sopenharmony_ci * @param width Indicates the width of the rectangle. 243bafb9395Sopenharmony_ci * @since 1.0 244bafb9395Sopenharmony_ci * @version 1.0 245bafb9395Sopenharmony_ci */ 246bafb9395Sopenharmony_ci void SetWidth(T width) 247bafb9395Sopenharmony_ci { 248bafb9395Sopenharmony_ci right_ = left_ + width - 1; 249bafb9395Sopenharmony_ci } 250bafb9395Sopenharmony_ci 251bafb9395Sopenharmony_ci /** 252bafb9395Sopenharmony_ci * @brief Changes the height of the rectangle without changing the coordinate of the top boundary. 253bafb9395Sopenharmony_ci * @param height Indicates the height of the rectangle. 254bafb9395Sopenharmony_ci * @since 1.0 255bafb9395Sopenharmony_ci * @version 1.0 256bafb9395Sopenharmony_ci */ 257bafb9395Sopenharmony_ci void SetHeight(T height) 258bafb9395Sopenharmony_ci { 259bafb9395Sopenharmony_ci bottom_ = top_ + height - 1; 260bafb9395Sopenharmony_ci } 261bafb9395Sopenharmony_ci 262bafb9395Sopenharmony_ci /** 263bafb9395Sopenharmony_ci * @brief Sets the coordinate of the left boundary of a rectangle. 264bafb9395Sopenharmony_ci * @param left Indicates the coordinate of the left boundary. 265bafb9395Sopenharmony_ci * @since 1.0 266bafb9395Sopenharmony_ci * @version 1.0 267bafb9395Sopenharmony_ci */ 268bafb9395Sopenharmony_ci void SetLeft(T left) 269bafb9395Sopenharmony_ci { 270bafb9395Sopenharmony_ci left_ = left; 271bafb9395Sopenharmony_ci } 272bafb9395Sopenharmony_ci 273bafb9395Sopenharmony_ci /** 274bafb9395Sopenharmony_ci * @brief Sets the coordinate of the top boundary of a rectangle. 275bafb9395Sopenharmony_ci * @param top Indicates the coordinate of the top boundary. 276bafb9395Sopenharmony_ci * @since 1.0 277bafb9395Sopenharmony_ci * @version 1.0 278bafb9395Sopenharmony_ci */ 279bafb9395Sopenharmony_ci void SetTop(T top) 280bafb9395Sopenharmony_ci { 281bafb9395Sopenharmony_ci top_ = top; 282bafb9395Sopenharmony_ci } 283bafb9395Sopenharmony_ci 284bafb9395Sopenharmony_ci /** 285bafb9395Sopenharmony_ci * @brief Sets the coordinate of the right boundary of a rectangle. 286bafb9395Sopenharmony_ci * @param right Indicates the coordinate of the right boundary. 287bafb9395Sopenharmony_ci * @since 1.0 288bafb9395Sopenharmony_ci * @version 1.0 289bafb9395Sopenharmony_ci */ 290bafb9395Sopenharmony_ci void SetRight(T right) 291bafb9395Sopenharmony_ci { 292bafb9395Sopenharmony_ci right_ = right; 293bafb9395Sopenharmony_ci } 294bafb9395Sopenharmony_ci 295bafb9395Sopenharmony_ci /** 296bafb9395Sopenharmony_ci * @brief Sets the coordinate of the bottom boundary of a rectangle. 297bafb9395Sopenharmony_ci * @param bottom Indicates the coordinate of the bottom boundary. 298bafb9395Sopenharmony_ci * @since 1.0 299bafb9395Sopenharmony_ci * @version 1.0 300bafb9395Sopenharmony_ci */ 301bafb9395Sopenharmony_ci void SetBottom(T bottom) 302bafb9395Sopenharmony_ci { 303bafb9395Sopenharmony_ci bottom_ = bottom; 304bafb9395Sopenharmony_ci } 305bafb9395Sopenharmony_ci 306bafb9395Sopenharmony_ci /** 307bafb9395Sopenharmony_ci * @brief Sets the width and height of a rectangle. 308bafb9395Sopenharmony_ci * @param width Indicates the width of the rectangle. 309bafb9395Sopenharmony_ci * @param height Indicates the height of the rectangle. 310bafb9395Sopenharmony_ci * @since 1.0 311bafb9395Sopenharmony_ci * @version 1.0 312bafb9395Sopenharmony_ci */ 313bafb9395Sopenharmony_ci void Resize(T width, T height) 314bafb9395Sopenharmony_ci { 315bafb9395Sopenharmony_ci right_ = left_ + width - 1; 316bafb9395Sopenharmony_ci bottom_ = top_ + height - 1; 317bafb9395Sopenharmony_ci } 318bafb9395Sopenharmony_ci 319bafb9395Sopenharmony_ci /** 320bafb9395Sopenharmony_ci * @brief Obtains the area of a rectangle. 321bafb9395Sopenharmony_ci * @return Returns the area of the rectangle. 322bafb9395Sopenharmony_ci * @since 1.0 323bafb9395Sopenharmony_ci * @version 1.0 324bafb9395Sopenharmony_ci */ 325bafb9395Sopenharmony_ci uint32_t GetSize() const 326bafb9395Sopenharmony_ci { 327bafb9395Sopenharmony_ci return static_cast<uint32_t>(right_ - left_ + 1) * (bottom_ - top_ + 1); 328bafb9395Sopenharmony_ci } 329bafb9395Sopenharmony_ci 330bafb9395Sopenharmony_ci /** 331bafb9395Sopenharmony_ci * @brief Checks whether two rectangles intersect. 332bafb9395Sopenharmony_ci * @param rect1 Indicates the first rectangle to check. 333bafb9395Sopenharmony_ci * @param rect2 Indicates the second rectangle to check. 334bafb9395Sopenharmony_ci * @return Returns <b>true</b> if the two rectangles intersect; returns <b>false</b> otherwise. 335bafb9395Sopenharmony_ci * @since 1.0 336bafb9395Sopenharmony_ci * @version 1.0 337bafb9395Sopenharmony_ci */ 338bafb9395Sopenharmony_ci bool Intersect(const CommonRect<T>& rect1, const CommonRect<T>& rect2) 339bafb9395Sopenharmony_ci { 340bafb9395Sopenharmony_ci /* Get the smaller area from 'rect1' and 'rect2' */ 341bafb9395Sopenharmony_ci left_ = MATH_MAX(rect1.left_, rect2.left_); 342bafb9395Sopenharmony_ci top_ = MATH_MAX(rect1.top_, rect2.top_); 343bafb9395Sopenharmony_ci right_ = MATH_MIN(rect1.right_, rect2.right_); 344bafb9395Sopenharmony_ci bottom_ = MATH_MIN(rect1.bottom_, rect2.bottom_); 345bafb9395Sopenharmony_ci if ((left_ > right_) || (top_ > bottom_)) { 346bafb9395Sopenharmony_ci return false; 347bafb9395Sopenharmony_ci } 348bafb9395Sopenharmony_ci 349bafb9395Sopenharmony_ci return true; 350bafb9395Sopenharmony_ci } 351bafb9395Sopenharmony_ci 352bafb9395Sopenharmony_ci /** 353bafb9395Sopenharmony_ci * @brief Obtains the minimum rectangle that contains another two rectangles. 354bafb9395Sopenharmony_ci * @param rect1 Indicates the first rectangle to contain. 355bafb9395Sopenharmony_ci * @param rect2 Indicates the second rectangle to contain. 356bafb9395Sopenharmony_ci * @since 1.0 357bafb9395Sopenharmony_ci * @version 1.0 358bafb9395Sopenharmony_ci */ 359bafb9395Sopenharmony_ci void Join(const CommonRect<T>& rect1, const CommonRect<T>& rect2) 360bafb9395Sopenharmony_ci { 361bafb9395Sopenharmony_ci left_ = MATH_MIN(rect1.left_, rect2.left_); 362bafb9395Sopenharmony_ci top_ = MATH_MIN(rect1.top_, rect2.top_); 363bafb9395Sopenharmony_ci right_ = MATH_MAX(rect1.right_, rect2.right_); 364bafb9395Sopenharmony_ci bottom_ = MATH_MAX(rect1.bottom_, rect2.bottom_); 365bafb9395Sopenharmony_ci } 366bafb9395Sopenharmony_ci 367bafb9395Sopenharmony_ci /** 368bafb9395Sopenharmony_ci * @brief Checks whether the rectangle contains a coordinate point. 369bafb9395Sopenharmony_ci * @param point Indicates the coordinate point. 370bafb9395Sopenharmony_ci * @return Returns <b>true</b> if the input coordinate point is contained; returns <b>false</b> otherwise. 371bafb9395Sopenharmony_ci * @since 1.0 372bafb9395Sopenharmony_ci * @version 1.0 373bafb9395Sopenharmony_ci */ 374bafb9395Sopenharmony_ci bool IsContains(const Vector2<T>& point) const 375bafb9395Sopenharmony_ci { 376bafb9395Sopenharmony_ci bool isContains = false; 377bafb9395Sopenharmony_ci 378bafb9395Sopenharmony_ci if ((point.x_ >= this->left_) && (point.x_ <= this->right_) && (point.y_ >= this->top_) && 379bafb9395Sopenharmony_ci (point.y_ <= this->bottom_)) { 380bafb9395Sopenharmony_ci isContains = true; 381bafb9395Sopenharmony_ci } 382bafb9395Sopenharmony_ci 383bafb9395Sopenharmony_ci return isContains; 384bafb9395Sopenharmony_ci } 385bafb9395Sopenharmony_ci 386bafb9395Sopenharmony_ci /** 387bafb9395Sopenharmony_ci * @brief Checks whether the rectangle contains a coordinate point. 388bafb9395Sopenharmony_ci * @param point Indicates the coordinate point. 389bafb9395Sopenharmony_ci * @return Returns <b>true</b> if the input coordinate point is contained; returns <b>false</b> otherwise. 390bafb9395Sopenharmony_ci * @since 1.0 391bafb9395Sopenharmony_ci * @version 1.0 392bafb9395Sopenharmony_ci */ 393bafb9395Sopenharmony_ci bool IsContains(const Point& point) const 394bafb9395Sopenharmony_ci { 395bafb9395Sopenharmony_ci bool isContains = false; 396bafb9395Sopenharmony_ci 397bafb9395Sopenharmony_ci if ((point.x >= this->left_) && (point.x <= this->right_) && (point.y >= this->top_) && 398bafb9395Sopenharmony_ci (point.y <= this->bottom_)) { 399bafb9395Sopenharmony_ci isContains = true; 400bafb9395Sopenharmony_ci } 401bafb9395Sopenharmony_ci 402bafb9395Sopenharmony_ci return isContains; 403bafb9395Sopenharmony_ci } 404bafb9395Sopenharmony_ci 405bafb9395Sopenharmony_ci /** 406bafb9395Sopenharmony_ci * @brief Checks whether the rectangle is adjacent to another rectangle horizontally or vertically. 407bafb9395Sopenharmony_ci * @param other Indicates the rectangle to be used for check. 408bafb9395Sopenharmony_ci * @return Returns <b>true</b> if the rectangle is adjacent to the input rectangle; returns <b>false</b> otherwise. 409bafb9395Sopenharmony_ci * @since 1.0 410bafb9395Sopenharmony_ci * @version 1.0 411bafb9395Sopenharmony_ci */ 412bafb9395Sopenharmony_ci bool IsExtends(const CommonRect<T>& other) const 413bafb9395Sopenharmony_ci { 414bafb9395Sopenharmony_ci if (left_ == other.left_ && right_ == other.right_) { 415bafb9395Sopenharmony_ci return (top_ == other.bottom_ + 1) || (bottom_ == other.top_ - 1); 416bafb9395Sopenharmony_ci } 417bafb9395Sopenharmony_ci 418bafb9395Sopenharmony_ci if (top_ == other.top_ && bottom_ == other.bottom_) { 419bafb9395Sopenharmony_ci return (left_ == other.right_ + 1) || (right_ == other.left_ - 1); 420bafb9395Sopenharmony_ci } 421bafb9395Sopenharmony_ci 422bafb9395Sopenharmony_ci return false; 423bafb9395Sopenharmony_ci } 424bafb9395Sopenharmony_ci 425bafb9395Sopenharmony_ci /** 426bafb9395Sopenharmony_ci * @brief Checks whether the rectangle intersects with another rectangle. 427bafb9395Sopenharmony_ci * @param other Indicates the rectangle to be used for check. 428bafb9395Sopenharmony_ci * @return Returns <b>true</b> if the two rectangles intersect; returns <b>false</b> otherwise. 429bafb9395Sopenharmony_ci * @since 1.0 430bafb9395Sopenharmony_ci * @version 1.0 431bafb9395Sopenharmony_ci */ 432bafb9395Sopenharmony_ci bool IsIntersect(const CommonRect<T>& other) const 433bafb9395Sopenharmony_ci { 434bafb9395Sopenharmony_ci if ((this->left_ <= other.right_) && (this->right_ >= other.left_) && (this->top_ <= other.bottom_) && 435bafb9395Sopenharmony_ci (this->bottom_ >= other.top_)) { 436bafb9395Sopenharmony_ci return true; 437bafb9395Sopenharmony_ci } else { 438bafb9395Sopenharmony_ci return false; 439bafb9395Sopenharmony_ci } 440bafb9395Sopenharmony_ci } 441bafb9395Sopenharmony_ci 442bafb9395Sopenharmony_ci /** 443bafb9395Sopenharmony_ci * @brief Checks whether the rectangle contains another rectangle. 444bafb9395Sopenharmony_ci * 445bafb9395Sopenharmony_ci * @param other Indicates the rectangle to be used for check. 446bafb9395Sopenharmony_ci * @return Returns <b>true</b> if the input rectangle is contained; returns <b>false</b> otherwise. 447bafb9395Sopenharmony_ci * @since 1.0 448bafb9395Sopenharmony_ci * @version 1.0 449bafb9395Sopenharmony_ci */ 450bafb9395Sopenharmony_ci bool IsContains(const CommonRect<T>& other) const 451bafb9395Sopenharmony_ci { 452bafb9395Sopenharmony_ci bool isContains = false; 453bafb9395Sopenharmony_ci 454bafb9395Sopenharmony_ci if (other.left_ >= this->left_ && other.top_ >= this->top_ && other.right_ <= this->right_ && 455bafb9395Sopenharmony_ci other.bottom_ <= this->bottom_) { 456bafb9395Sopenharmony_ci isContains = true; 457bafb9395Sopenharmony_ci } 458bafb9395Sopenharmony_ci 459bafb9395Sopenharmony_ci return isContains; 460bafb9395Sopenharmony_ci } 461bafb9395Sopenharmony_ci 462bafb9395Sopenharmony_ci void Inflate(T delta); 463bafb9395Sopenharmony_ci void operator=(const CommonRect<T>& other) 464bafb9395Sopenharmony_ci { 465bafb9395Sopenharmony_ci left_ = other.left_; 466bafb9395Sopenharmony_ci right_ = other.right_; 467bafb9395Sopenharmony_ci top_ = other.top_; 468bafb9395Sopenharmony_ci bottom_ = other.bottom_; 469bafb9395Sopenharmony_ci } 470bafb9395Sopenharmony_ci void operator=(const CommonRect<T>&& other) 471bafb9395Sopenharmony_ci { 472bafb9395Sopenharmony_ci left_ = other.left_; 473bafb9395Sopenharmony_ci right_ = other.right_; 474bafb9395Sopenharmony_ci top_ = other.top_; 475bafb9395Sopenharmony_ci bottom_ = other.bottom_; 476bafb9395Sopenharmony_ci } 477bafb9395Sopenharmony_ci bool operator==(const CommonRect<T>& other) const 478bafb9395Sopenharmony_ci { 479bafb9395Sopenharmony_ci if (left_ == other.left_ && right_ == other.right_ && top_ == other.top_ && bottom_ == other.bottom_) { 480bafb9395Sopenharmony_ci return true; 481bafb9395Sopenharmony_ci } else { 482bafb9395Sopenharmony_ci return false; 483bafb9395Sopenharmony_ci } 484bafb9395Sopenharmony_ci } 485bafb9395Sopenharmony_ci 486bafb9395Sopenharmony_ci void Normalize() 487bafb9395Sopenharmony_ci { 488bafb9395Sopenharmony_ci T t; 489bafb9395Sopenharmony_ci if (left_ > right_) { 490bafb9395Sopenharmony_ci t = left_; 491bafb9395Sopenharmony_ci left_ = right_; 492bafb9395Sopenharmony_ci right_ = t; 493bafb9395Sopenharmony_ci } 494bafb9395Sopenharmony_ci if (top_ > bottom_) { 495bafb9395Sopenharmony_ci t = top_; 496bafb9395Sopenharmony_ci top_ = bottom_; 497bafb9395Sopenharmony_ci bottom_ = t; 498bafb9395Sopenharmony_ci } 499bafb9395Sopenharmony_ci } 500bafb9395Sopenharmony_ci 501bafb9395Sopenharmony_ciprotected: 502bafb9395Sopenharmony_ci T left_; 503bafb9395Sopenharmony_ci T top_; 504bafb9395Sopenharmony_ci T right_; 505bafb9395Sopenharmony_ci T bottom_; 506bafb9395Sopenharmony_ci}; 507bafb9395Sopenharmony_ciusing Rect = CommonRect<int16_t>; 508bafb9395Sopenharmony_ciusing Rect32 = CommonRect<int32_t>; 509bafb9395Sopenharmony_ci} // namespace OHOS 510bafb9395Sopenharmony_ci#endif // GRAPHIC_LITE_RECT_H 511