1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_NG_RADIUST_H 16 #define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_NG_RADIUST_H 17 18 #include <string> 19 20 #include "base/geometry/dimension.h" 21 namespace OHOS::Ace::NG { 22 class Radius final { 23 public: 24 Radius() = default; Radius(double value)25 explicit Radius(double value) : Radius(value, value) {} Radius(const Dimension & value)26 explicit Radius(const Dimension& value) : Radius(value, value) {} Radius(double x,double y)27 Radius(double x, double y) : x_(Dimension(x)), y_(Dimension(y)) {} Radius(const Dimension & x,const Dimension & y)28 Radius(const Dimension& x, const Dimension& y) : x_(x), y_(y) {} 29 ~Radius() = default; 30 IsValid()31 bool IsValid() const 32 { 33 return x_.IsValid() && y_.IsValid(); 34 } 35 HasValue()36 bool HasValue() const 37 { 38 return x_.IsValid() || y_.IsValid(); 39 } 40 GetX()41 Dimension GetX() const 42 { 43 return x_; 44 } 45 GetY()46 Dimension GetY() const 47 { 48 return y_; 49 } 50 SetX(const Dimension & x)51 void SetX(const Dimension& x) 52 { 53 // bug to fix: unit of x will be convert to PX 54 x_ = Dimension(x); 55 } 56 SetY(const Dimension & y)57 void SetY(const Dimension& y) 58 { 59 // bug to fix: unit of x will be convert to PX 60 y_ = Dimension(y); 61 } 62 63 Radius operator+(const Radius& radius) const 64 { 65 return Radius(x_ + radius.x_, y_ + radius.y_); 66 } 67 68 Radius operator-(const Radius& radius) const 69 { 70 return Radius(x_ - radius.x_, y_ - radius.y_); 71 } 72 73 bool operator==(const Radius& radius) const 74 { 75 return (radius.x_ == x_) && (radius.y_ == y_); 76 } 77 78 bool operator!=(const Radius& radius) const 79 { 80 return (radius.x_ != x_) || (radius.y_ != y_); 81 } 82 83 Radius operator=(const Radius& radius) 84 { 85 x_ = radius.x_; 86 y_ = radius.y_; 87 return *this; 88 } 89 ToString()90 std::string ToString() const 91 { 92 return std::string("x:").append(x_.ToString()).append(", y:").append(y_.ToString()); 93 } 94 95 private: 96 Dimension x_; 97 Dimension y_; 98 }; 99 } // namespace OHOS::Ace::NG 100 #endif