123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_RECT_H 1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_RECT_H 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include <algorithm> 2023b3eb3cSopenharmony_ci 2123b3eb3cSopenharmony_ci#include "base/geometry/offset.h" 2223b3eb3cSopenharmony_ci#include "base/geometry/point.h" 2323b3eb3cSopenharmony_ci#include "base/geometry/size.h" 2423b3eb3cSopenharmony_ci 2523b3eb3cSopenharmony_cinamespace OHOS::Ace { 2623b3eb3cSopenharmony_ci 2723b3eb3cSopenharmony_ciclass Rect { 2823b3eb3cSopenharmony_cipublic: 2923b3eb3cSopenharmony_ci Rect() = default; 3023b3eb3cSopenharmony_ci ~Rect() = default; 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_ci Rect(double x, double y, double width, double height) 3323b3eb3cSopenharmony_ci { 3423b3eb3cSopenharmony_ci SetRect(x, y, width, height); 3523b3eb3cSopenharmony_ci } 3623b3eb3cSopenharmony_ci 3723b3eb3cSopenharmony_ci Rect(const Offset& offset, const Size& size) 3823b3eb3cSopenharmony_ci { 3923b3eb3cSopenharmony_ci SetOffset(offset); 4023b3eb3cSopenharmony_ci SetSize(size); 4123b3eb3cSopenharmony_ci } 4223b3eb3cSopenharmony_ci 4323b3eb3cSopenharmony_ci void SetRect(double x, double y, double width, double height) 4423b3eb3cSopenharmony_ci { 4523b3eb3cSopenharmony_ci x_ = x; 4623b3eb3cSopenharmony_ci y_ = y; 4723b3eb3cSopenharmony_ci width_ = width; 4823b3eb3cSopenharmony_ci height_ = height; 4923b3eb3cSopenharmony_ci } 5023b3eb3cSopenharmony_ci 5123b3eb3cSopenharmony_ci void SetRect(const Offset& offset, const Size& size) 5223b3eb3cSopenharmony_ci { 5323b3eb3cSopenharmony_ci SetOffset(offset); 5423b3eb3cSopenharmony_ci SetSize(size); 5523b3eb3cSopenharmony_ci } 5623b3eb3cSopenharmony_ci 5723b3eb3cSopenharmony_ci void ApplyScale(double scale) 5823b3eb3cSopenharmony_ci { 5923b3eb3cSopenharmony_ci x_ *= scale; 6023b3eb3cSopenharmony_ci y_ *= scale; 6123b3eb3cSopenharmony_ci width_ *= scale; 6223b3eb3cSopenharmony_ci height_ *= scale; 6323b3eb3cSopenharmony_ci } 6423b3eb3cSopenharmony_ci 6523b3eb3cSopenharmony_ci void ApplyScaleAndRound(const Size& scale) 6623b3eb3cSopenharmony_ci { 6723b3eb3cSopenharmony_ci x_ = round(x_ * scale.Width()); 6823b3eb3cSopenharmony_ci y_ = round(y_ * scale.Height()); 6923b3eb3cSopenharmony_ci width_ = round(width_ * scale.Width()); 7023b3eb3cSopenharmony_ci height_ = round(height_ * scale.Height()); 7123b3eb3cSopenharmony_ci } 7223b3eb3cSopenharmony_ci 7323b3eb3cSopenharmony_ci double Left() const 7423b3eb3cSopenharmony_ci { 7523b3eb3cSopenharmony_ci return GreatNotEqual(width_, 0.0) ? x_ : x_ + width_; 7623b3eb3cSopenharmony_ci } 7723b3eb3cSopenharmony_ci 7823b3eb3cSopenharmony_ci double Top() const 7923b3eb3cSopenharmony_ci { 8023b3eb3cSopenharmony_ci return GreatNotEqual(height_, 0.0) ? y_ : y_ + height_; 8123b3eb3cSopenharmony_ci } 8223b3eb3cSopenharmony_ci 8323b3eb3cSopenharmony_ci double Right() const 8423b3eb3cSopenharmony_ci { 8523b3eb3cSopenharmony_ci return GreatNotEqual(width_, 0.0) ? x_ + width_ : x_; 8623b3eb3cSopenharmony_ci } 8723b3eb3cSopenharmony_ci 8823b3eb3cSopenharmony_ci double Bottom() const 8923b3eb3cSopenharmony_ci { 9023b3eb3cSopenharmony_ci return GreatNotEqual(height_, 0.0) ? y_ + height_ : y_; 9123b3eb3cSopenharmony_ci } 9223b3eb3cSopenharmony_ci 9323b3eb3cSopenharmony_ci double Width() const 9423b3eb3cSopenharmony_ci { 9523b3eb3cSopenharmony_ci return width_; 9623b3eb3cSopenharmony_ci } 9723b3eb3cSopenharmony_ci 9823b3eb3cSopenharmony_ci double Height() const 9923b3eb3cSopenharmony_ci { 10023b3eb3cSopenharmony_ci return height_; 10123b3eb3cSopenharmony_ci } 10223b3eb3cSopenharmony_ci 10323b3eb3cSopenharmony_ci void SetSize(const Size& size) 10423b3eb3cSopenharmony_ci { 10523b3eb3cSopenharmony_ci width_ = size.Width(); 10623b3eb3cSopenharmony_ci height_ = size.Height(); 10723b3eb3cSopenharmony_ci } 10823b3eb3cSopenharmony_ci 10923b3eb3cSopenharmony_ci Size GetSize() const 11023b3eb3cSopenharmony_ci { 11123b3eb3cSopenharmony_ci return Size(width_, height_); 11223b3eb3cSopenharmony_ci } 11323b3eb3cSopenharmony_ci 11423b3eb3cSopenharmony_ci void SetOffset(const Offset& offset) 11523b3eb3cSopenharmony_ci { 11623b3eb3cSopenharmony_ci x_ = offset.GetX(); 11723b3eb3cSopenharmony_ci y_ = offset.GetY(); 11823b3eb3cSopenharmony_ci } 11923b3eb3cSopenharmony_ci 12023b3eb3cSopenharmony_ci Offset GetOffset() const 12123b3eb3cSopenharmony_ci { 12223b3eb3cSopenharmony_ci return Offset(x_, y_); 12323b3eb3cSopenharmony_ci } 12423b3eb3cSopenharmony_ci 12523b3eb3cSopenharmony_ci void SetLeft(double left) 12623b3eb3cSopenharmony_ci { 12723b3eb3cSopenharmony_ci x_ = left; 12823b3eb3cSopenharmony_ci } 12923b3eb3cSopenharmony_ci 13023b3eb3cSopenharmony_ci void SetTop(double top) 13123b3eb3cSopenharmony_ci { 13223b3eb3cSopenharmony_ci y_ = top; 13323b3eb3cSopenharmony_ci } 13423b3eb3cSopenharmony_ci 13523b3eb3cSopenharmony_ci void SetWidth(double width) 13623b3eb3cSopenharmony_ci { 13723b3eb3cSopenharmony_ci width_ = width; 13823b3eb3cSopenharmony_ci } 13923b3eb3cSopenharmony_ci 14023b3eb3cSopenharmony_ci void SetHeight(double height) 14123b3eb3cSopenharmony_ci { 14223b3eb3cSopenharmony_ci height_ = height; 14323b3eb3cSopenharmony_ci } 14423b3eb3cSopenharmony_ci 14523b3eb3cSopenharmony_ci bool IsInRegion(const Point& point) const 14623b3eb3cSopenharmony_ci { 14723b3eb3cSopenharmony_ci return (point.GetX() >= x_) && (point.GetX() < (x_ + width_)) && (point.GetY() >= y_) && 14823b3eb3cSopenharmony_ci (point.GetY() < (y_ + height_)); 14923b3eb3cSopenharmony_ci } 15023b3eb3cSopenharmony_ci 15123b3eb3cSopenharmony_ci bool IsWrappedBy(const Rect& other) const 15223b3eb3cSopenharmony_ci { 15323b3eb3cSopenharmony_ci return (Left() >= other.Left()) && (Right() <= other.Right()) && (Top() >= other.Top()) && 15423b3eb3cSopenharmony_ci (Bottom() <= other.Bottom()); 15523b3eb3cSopenharmony_ci } 15623b3eb3cSopenharmony_ci 15723b3eb3cSopenharmony_ci bool IsValid() const 15823b3eb3cSopenharmony_ci { 15923b3eb3cSopenharmony_ci return width_ > 0.0 && height_ > 0.0; 16023b3eb3cSopenharmony_ci } 16123b3eb3cSopenharmony_ci 16223b3eb3cSopenharmony_ci Rect Constrain(const Rect& other) 16323b3eb3cSopenharmony_ci { 16423b3eb3cSopenharmony_ci double right = Right(); 16523b3eb3cSopenharmony_ci double bottom = Bottom(); 16623b3eb3cSopenharmony_ci double left = std::clamp(x_, other.Left(), other.Right()); 16723b3eb3cSopenharmony_ci double top = std::clamp(y_, other.Top(), other.Bottom()); 16823b3eb3cSopenharmony_ci right = std::clamp(right, other.Left(), other.Right()) - left; 16923b3eb3cSopenharmony_ci bottom = std::clamp(bottom, other.Top(), other.Bottom()) - top; 17023b3eb3cSopenharmony_ci return Rect(left, top, right, bottom); 17123b3eb3cSopenharmony_ci } 17223b3eb3cSopenharmony_ci 17323b3eb3cSopenharmony_ci Rect& operator+=(const Offset& offset) 17423b3eb3cSopenharmony_ci { 17523b3eb3cSopenharmony_ci x_ += offset.GetX(); 17623b3eb3cSopenharmony_ci y_ += offset.GetY(); 17723b3eb3cSopenharmony_ci return *this; 17823b3eb3cSopenharmony_ci } 17923b3eb3cSopenharmony_ci 18023b3eb3cSopenharmony_ci Rect& operator-=(const Offset& offset) 18123b3eb3cSopenharmony_ci { 18223b3eb3cSopenharmony_ci x_ -= offset.GetX(); 18323b3eb3cSopenharmony_ci y_ -= offset.GetY(); 18423b3eb3cSopenharmony_ci return *this; 18523b3eb3cSopenharmony_ci } 18623b3eb3cSopenharmony_ci 18723b3eb3cSopenharmony_ci Rect& operator+=(const Size& size) 18823b3eb3cSopenharmony_ci { 18923b3eb3cSopenharmony_ci width_ += size.Width(); 19023b3eb3cSopenharmony_ci height_ += size.Height(); 19123b3eb3cSopenharmony_ci return *this; 19223b3eb3cSopenharmony_ci } 19323b3eb3cSopenharmony_ci 19423b3eb3cSopenharmony_ci Rect& operator-=(const Size& size) 19523b3eb3cSopenharmony_ci { 19623b3eb3cSopenharmony_ci width_ -= size.Width(); 19723b3eb3cSopenharmony_ci height_ -= size.Height(); 19823b3eb3cSopenharmony_ci return *this; 19923b3eb3cSopenharmony_ci } 20023b3eb3cSopenharmony_ci 20123b3eb3cSopenharmony_ci Rect operator+(const Offset& offset) const 20223b3eb3cSopenharmony_ci { 20323b3eb3cSopenharmony_ci return Rect(x_ + offset.GetX(), y_ + offset.GetY(), width_, height_); 20423b3eb3cSopenharmony_ci } 20523b3eb3cSopenharmony_ci 20623b3eb3cSopenharmony_ci Rect operator-(const Offset& offset) const 20723b3eb3cSopenharmony_ci { 20823b3eb3cSopenharmony_ci return Rect(x_ - offset.GetX(), y_ - offset.GetY(), width_, height_); 20923b3eb3cSopenharmony_ci } 21023b3eb3cSopenharmony_ci 21123b3eb3cSopenharmony_ci Rect operator+(const Size& size) const 21223b3eb3cSopenharmony_ci { 21323b3eb3cSopenharmony_ci return Rect(x_, y_, width_ + size.Width(), height_ + size.Height()); 21423b3eb3cSopenharmony_ci } 21523b3eb3cSopenharmony_ci 21623b3eb3cSopenharmony_ci Rect operator-(const Size& size) const 21723b3eb3cSopenharmony_ci { 21823b3eb3cSopenharmony_ci return Rect(x_, y_, width_ - size.Width(), height_ - size.Height()); 21923b3eb3cSopenharmony_ci } 22023b3eb3cSopenharmony_ci 22123b3eb3cSopenharmony_ci Rect operator*(double scale) const 22223b3eb3cSopenharmony_ci { 22323b3eb3cSopenharmony_ci return Rect(x_ * scale, y_ * scale, width_ * scale, height_ * scale); 22423b3eb3cSopenharmony_ci } 22523b3eb3cSopenharmony_ci 22623b3eb3cSopenharmony_ci bool operator==(const Rect& rect) const 22723b3eb3cSopenharmony_ci { 22823b3eb3cSopenharmony_ci return (GetOffset() == rect.GetOffset()) && (GetSize() == rect.GetSize()); 22923b3eb3cSopenharmony_ci } 23023b3eb3cSopenharmony_ci 23123b3eb3cSopenharmony_ci bool operator!=(const Rect& rect) const 23223b3eb3cSopenharmony_ci { 23323b3eb3cSopenharmony_ci return !operator==(rect); 23423b3eb3cSopenharmony_ci } 23523b3eb3cSopenharmony_ci 23623b3eb3cSopenharmony_ci bool IsIntersectWith(const Rect& other) const 23723b3eb3cSopenharmony_ci { 23823b3eb3cSopenharmony_ci return !(other.Right() < Left() || other.Left() > Right() || other.Bottom() < Top() || other.Top() > Bottom()); 23923b3eb3cSopenharmony_ci } 24023b3eb3cSopenharmony_ci 24123b3eb3cSopenharmony_ci bool IsIntersectByCommonSideWith(const Rect& other) const 24223b3eb3cSopenharmony_ci { 24323b3eb3cSopenharmony_ci return !( 24423b3eb3cSopenharmony_ci other.Right() <= Left() || other.Left() >= Right() || other.Bottom() <= Top() || other.Top() >= Bottom()); 24523b3eb3cSopenharmony_ci } 24623b3eb3cSopenharmony_ci 24723b3eb3cSopenharmony_ci Rect IntersectRect(const Rect& other) const 24823b3eb3cSopenharmony_ci { 24923b3eb3cSopenharmony_ci double left = std::max(Left(), other.Left()); 25023b3eb3cSopenharmony_ci double right = std::min(Right(), other.Right()); 25123b3eb3cSopenharmony_ci double top = std::max(Top(), other.Top()); 25223b3eb3cSopenharmony_ci double bottom = std::min(Bottom(), other.Bottom()); 25323b3eb3cSopenharmony_ci return Rect(left, top, right - left, bottom - top); 25423b3eb3cSopenharmony_ci } 25523b3eb3cSopenharmony_ci 25623b3eb3cSopenharmony_ci Rect CombineRect(const Rect& other) const 25723b3eb3cSopenharmony_ci { 25823b3eb3cSopenharmony_ci double left = std::min(Left(), other.Left()); 25923b3eb3cSopenharmony_ci double right = std::max(Right(), other.Right()); 26023b3eb3cSopenharmony_ci double top = std::min(Top(), other.Top()); 26123b3eb3cSopenharmony_ci double bottom = std::max(Bottom(), other.Bottom()); 26223b3eb3cSopenharmony_ci return Rect(left, top, right - left, bottom - top); 26323b3eb3cSopenharmony_ci } 26423b3eb3cSopenharmony_ci 26523b3eb3cSopenharmony_ci /** 26623b3eb3cSopenharmony_ci * @brief Magnetically attracted to a "magnetic" rect. 26723b3eb3cSopenharmony_ci * 26823b3eb3cSopenharmony_ci * Let's show some cases to illustrate how this method works: 26923b3eb3cSopenharmony_ci * 27023b3eb3cSopenharmony_ci * Case 1 : Inside. Rect won't be move because it is already attracted by magnet. 27123b3eb3cSopenharmony_ci * Result: Offset(0, 0) 27223b3eb3cSopenharmony_ci * 27323b3eb3cSopenharmony_ci * +-----------------------------+ 27423b3eb3cSopenharmony_ci * | | 27523b3eb3cSopenharmony_ci * | Magnetical Rect | 27623b3eb3cSopenharmony_ci * | | 27723b3eb3cSopenharmony_ci * | +-------+ | 27823b3eb3cSopenharmony_ci * | | R | | 27923b3eb3cSopenharmony_ci * | | | | 28023b3eb3cSopenharmony_ci * | +-------+ | 28123b3eb3cSopenharmony_ci * +-----------------------------+ 28223b3eb3cSopenharmony_ci * 28323b3eb3cSopenharmony_ci * Case 2: Outside. R will be attracted to position R' 28423b3eb3cSopenharmony_ci * Result: Offset(-12, -3) 28523b3eb3cSopenharmony_ci * 28623b3eb3cSopenharmony_ci * +-----------------------+ 28723b3eb3cSopenharmony_ci * | | 28823b3eb3cSopenharmony_ci * | Magnetical Rect +--+ 28923b3eb3cSopenharmony_ci * | | | 29023b3eb3cSopenharmony_ci * | |R'| +--+ 29123b3eb3cSopenharmony_ci * +-----------------------+ |R | 29223b3eb3cSopenharmony_ci * | | 29323b3eb3cSopenharmony_ci * +--+ 29423b3eb3cSopenharmony_ci * 29523b3eb3cSopenharmony_ci * Case 3: Half Inside. R will be moved totally into magnet. 29623b3eb3cSopenharmony_ci * Result: Offset(-8, 0) 29723b3eb3cSopenharmony_ci * 29823b3eb3cSopenharmony_ci * +-----------------------------+ +-----------------------------+ 29923b3eb3cSopenharmony_ci * | | | | 30023b3eb3cSopenharmony_ci * | Magnetical Rect | +----------> | Magnetical Rect | 30123b3eb3cSopenharmony_ci * | | | | 30223b3eb3cSopenharmony_ci * | +----------+ | +----------+ 30323b3eb3cSopenharmony_ci * | | | R | | | R' | 30423b3eb3cSopenharmony_ci * | +----------+ | +----------+ 30523b3eb3cSopenharmony_ci * | | | | 30623b3eb3cSopenharmony_ci * +-----------------------------+ +-----------------------------+ 30723b3eb3cSopenharmony_ci * 30823b3eb3cSopenharmony_ci * Case 4: Outside or Half Outside but space not enough. R will be moved into magnet as more as possible. 30923b3eb3cSopenharmony_ci * Result: Offset(0, 1) 31023b3eb3cSopenharmony_ci * 31123b3eb3cSopenharmony_ci * +--+ 31223b3eb3cSopenharmony_ci * | | +--+ 31323b3eb3cSopenharmony_ci * |R | | | 31423b3eb3cSopenharmony_ci * | | |R'| 31523b3eb3cSopenharmony_ci * +---------------------------+ +---------------------------+ 31623b3eb3cSopenharmony_ci * | | | | | | | | 31723b3eb3cSopenharmony_ci * | Magnetical Rect | | | +-----> | Magnetical Rect | | | 31823b3eb3cSopenharmony_ci * | +--+ | | | | | 31923b3eb3cSopenharmony_ci * +---------------------------+ +------------------+--+-----+ 32023b3eb3cSopenharmony_ci * 32123b3eb3cSopenharmony_ci * Case 5: Totally Across magnet. Nothing should happen. 32223b3eb3cSopenharmony_ci * Result: Offset(0, 0) 32323b3eb3cSopenharmony_ci * 32423b3eb3cSopenharmony_ci * +--+ 32523b3eb3cSopenharmony_ci * | | 32623b3eb3cSopenharmony_ci * |R | 32723b3eb3cSopenharmony_ci * | | 32823b3eb3cSopenharmony_ci * +---------------------------+ 32923b3eb3cSopenharmony_ci * | | | | 33023b3eb3cSopenharmony_ci * | Magnetical Rect | | | 33123b3eb3cSopenharmony_ci * | | | | 33223b3eb3cSopenharmony_ci * +---------------------------+ 33323b3eb3cSopenharmony_ci * | | 33423b3eb3cSopenharmony_ci * +--+ 33523b3eb3cSopenharmony_ci * 33623b3eb3cSopenharmony_ci * @param[in] magnet The magnetical rectangle. 33723b3eb3cSopenharmony_ci * 33823b3eb3cSopenharmony_ci * @return The offset that this rect need to moving into magnet. 33923b3eb3cSopenharmony_ci */ 34023b3eb3cSopenharmony_ci Offset MagneticAttractedBy(const Rect& magnet) 34123b3eb3cSopenharmony_ci { 34223b3eb3cSopenharmony_ci Offset offset = Offset::Zero(); 34323b3eb3cSopenharmony_ci if (IsWrappedBy(magnet)) { 34423b3eb3cSopenharmony_ci return Offset::Zero(); 34523b3eb3cSopenharmony_ci } 34623b3eb3cSopenharmony_ci 34723b3eb3cSopenharmony_ci if (Left() < magnet.Left()) { 34823b3eb3cSopenharmony_ci offset.SetX(std::max(0.0, std::min(magnet.Left() - Left(), magnet.Right() - Right()))); 34923b3eb3cSopenharmony_ci } else if (Right() > magnet.Right()) { 35023b3eb3cSopenharmony_ci offset.SetX(std::min(0.0, std::max(magnet.Left() - Left(), magnet.Right() - Right()))); 35123b3eb3cSopenharmony_ci } 35223b3eb3cSopenharmony_ci 35323b3eb3cSopenharmony_ci if (Top() < magnet.Top()) { 35423b3eb3cSopenharmony_ci offset.SetY(std::max(0.0, std::min(magnet.Top() - Top(), magnet.Bottom() - Bottom()))); 35523b3eb3cSopenharmony_ci } else if (Bottom() > magnet.Bottom()) { 35623b3eb3cSopenharmony_ci offset.SetY(std::min(0.0, std::max(magnet.Top() - Top(), magnet.Bottom() - Bottom()))); 35723b3eb3cSopenharmony_ci } 35823b3eb3cSopenharmony_ci 35923b3eb3cSopenharmony_ci *this += offset; 36023b3eb3cSopenharmony_ci 36123b3eb3cSopenharmony_ci return offset; 36223b3eb3cSopenharmony_ci } 36323b3eb3cSopenharmony_ci 36423b3eb3cSopenharmony_ci std::string ToString() const 36523b3eb3cSopenharmony_ci { 36623b3eb3cSopenharmony_ci std::stringstream ss; 36723b3eb3cSopenharmony_ci ss << "Rect (" << std::fixed << std::setprecision(2) << x_ << ", " << y_ << ") - ["; 36823b3eb3cSopenharmony_ci if (NearEqual(width_, Size::INFINITE_SIZE)) { 36923b3eb3cSopenharmony_ci ss << "INFINITE"; 37023b3eb3cSopenharmony_ci } else { 37123b3eb3cSopenharmony_ci ss << width_; 37223b3eb3cSopenharmony_ci } 37323b3eb3cSopenharmony_ci ss << " x "; 37423b3eb3cSopenharmony_ci if (NearEqual(height_, Size::INFINITE_SIZE)) { 37523b3eb3cSopenharmony_ci ss << "INFINITE"; 37623b3eb3cSopenharmony_ci } else { 37723b3eb3cSopenharmony_ci ss << height_; 37823b3eb3cSopenharmony_ci } 37923b3eb3cSopenharmony_ci ss << "]"; 38023b3eb3cSopenharmony_ci std::string output = ss.str(); 38123b3eb3cSopenharmony_ci return output; 38223b3eb3cSopenharmony_ci } 38323b3eb3cSopenharmony_ci 38423b3eb3cSopenharmony_ci std::string ToBounds() const 38523b3eb3cSopenharmony_ci { 38623b3eb3cSopenharmony_ci std::stringstream ss; 38723b3eb3cSopenharmony_ci ss << "[" << std::fixed << std::setprecision(2) << x_ << ", " << y_ << "]["; 38823b3eb3cSopenharmony_ci if (NearEqual(width_, Size::INFINITE_SIZE)) { 38923b3eb3cSopenharmony_ci ss << "INFINITE"; 39023b3eb3cSopenharmony_ci } else { 39123b3eb3cSopenharmony_ci ss << (x_ + width_); 39223b3eb3cSopenharmony_ci } 39323b3eb3cSopenharmony_ci ss << ","; 39423b3eb3cSopenharmony_ci if (NearEqual(height_, Size::INFINITE_SIZE)) { 39523b3eb3cSopenharmony_ci ss << "INFINITE"; 39623b3eb3cSopenharmony_ci } else { 39723b3eb3cSopenharmony_ci ss << (y_ + height_); 39823b3eb3cSopenharmony_ci } 39923b3eb3cSopenharmony_ci ss << "]"; 40023b3eb3cSopenharmony_ci std::string output = ss.str(); 40123b3eb3cSopenharmony_ci return output; 40223b3eb3cSopenharmony_ci } 40323b3eb3cSopenharmony_ci 40423b3eb3cSopenharmony_ci Offset Center() const 40523b3eb3cSopenharmony_ci { 40623b3eb3cSopenharmony_ci return Offset(width_ / 2.0 + x_, height_ / 2.0 + y_); 40723b3eb3cSopenharmony_ci } 40823b3eb3cSopenharmony_ci 40923b3eb3cSopenharmony_ciprivate: 41023b3eb3cSopenharmony_ci double x_ = 0.0; 41123b3eb3cSopenharmony_ci double y_ = 0.0; 41223b3eb3cSopenharmony_ci double width_ = 0.0; 41323b3eb3cSopenharmony_ci double height_ = 0.0; 41423b3eb3cSopenharmony_ci}; 41523b3eb3cSopenharmony_ci 41623b3eb3cSopenharmony_ci} // namespace OHOS::Ace 41723b3eb3cSopenharmony_ci 41823b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_RECT_H 419