• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #ifndef POINT3_H
17 #define POINT3_H
18 
19 #include "utils/scalar.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
24 class Point3 {
25 public:
26     inline Point3() noexcept;
27     inline Point3(const Point3& p) noexcept;
28     inline Point3(scalar x, scalar y, scalar z) noexcept;
29 
~Point3()30     inline ~Point3() {}
31 
32     inline scalar GetX() const;
33     inline scalar GetY() const;
34     inline scalar GetZ() const;
35 
36     inline void SetX(scalar x);
37     inline void SetY(scalar y);
38     inline void SetZ(scalar z);
39 
40     inline Point3& operator+=(const Point3& p);
41     inline Point3& operator-=(const Point3& p);
42     inline Point3& operator*=(scalar scale);
43     inline Point3& operator/=(scalar divisor);
44 
45     friend inline const Point3 operator+(const Point3& p1, const Point3& p2);
46     friend inline const Point3 operator-(const Point3& p1, const Point3& p2);
47     friend inline const Point3 operator*(scalar scale, const Point3& p);
48     friend inline const Point3 operator*(const Point3& p, scalar scale);
49     friend inline const Point3 operator/(const Point3& p, scalar divisor);
50     friend inline const Point3 operator+(const Point3& p);
51     friend inline const Point3 operator-(const Point3& p);
52     friend inline bool operator==(const Point3& p1, const Point3& p2);
53     friend inline bool operator!=(const Point3& p1, const Point3& p2);
54 
55 private:
56     scalar x_;
57     scalar y_;
58     scalar z_;
59 };
60 
Point3()61 inline Point3::Point3() noexcept : x_(0.0), y_(0.0), z_(0.0) {}
62 
Point3(const Point3 & p)63 inline Point3::Point3(const Point3& p) noexcept : x_(p.GetX()), y_(p.GetY()), z_(p.GetZ()) {}
64 
Point3(scalar x,scalar y,scalar z)65 inline Point3::Point3(scalar x, scalar y, scalar z) noexcept : x_(x), y_(y), z_(z) {}
66 
GetX()67 inline scalar Point3::GetX() const
68 {
69     return x_;
70 }
71 
GetY()72 inline scalar Point3::GetY() const
73 {
74     return y_;
75 }
76 
GetZ()77 inline scalar Point3::GetZ() const
78 {
79     return z_;
80 }
81 
SetX(scalar x)82 inline void Point3::SetX(scalar x)
83 {
84     x_ = x;
85 }
86 
SetY(scalar y)87 inline void Point3::SetY(scalar y)
88 {
89     y_ = y;
90 }
91 
SetZ(scalar z)92 inline void Point3::SetZ(scalar z)
93 {
94     z_ = z;
95 }
96 
97 inline Point3& Point3::operator+=(const Point3& p)
98 {
99     x_ += p.x_;
100     y_ += p.y_;
101     z_ += p.z_;
102     return *this;
103 }
104 
105 inline Point3& Point3::operator-=(const Point3& p)
106 {
107     x_ -= p.x_;
108     y_ -= p.y_;
109     z_ -= p.z_;
110     return *this;
111 }
112 
113 inline Point3& Point3::operator*=(scalar scale)
114 {
115     x_ = static_cast<int64_t>(x_ * scale);
116     y_ = static_cast<int64_t>(y_ * scale);
117     z_ = static_cast<int64_t>(z_ * scale);
118     return *this;
119 }
120 
121 inline Point3& Point3::operator/=(scalar divisor)
122 {
123     if (divisor == 0) {
124         return *this;
125     }
126     x_ = static_cast<int>(x_ / divisor);
127     y_ = static_cast<int>(y_ / divisor);
128     z_ = static_cast<int>(z_ / divisor);
129     return *this;
130 }
131 
132 inline const Point3 operator+(const Point3& p1, const Point3& p2)
133 {
134     return Point3(p1.x_ + p1.y_, p2.x_ + p2.y_, p1.z_ + p2.z_);
135 }
136 
137 inline const Point3 operator-(const Point3& p1, const Point3& p2)
138 {
139     return Point3(p1.x_ - p2.x_, p1.y_ - p2.y_, p1.z_ - p2.z_);
140 }
141 
142 inline const Point3 operator*(scalar scale, const Point3& p)
143 {
144     return Point3(
145         static_cast<int64_t>(scale * p.x_), static_cast<int64_t>(scale * p.y_), static_cast<int64_t>(scale * p.z_));
146 }
147 
148 inline const Point3 operator*(const Point3& p, scalar scale)
149 {
150     return Point3(
151         static_cast<int64_t>(p.x_ * scale), static_cast<int64_t>(p.y_ * scale), static_cast<int64_t>(p.z_ * scale));
152 }
153 
154 inline const Point3 operator/(const Point3& p, scalar divisor)
155 {
156     if (divisor == 0) {
157         return Point3(p.x_, p.y_, p.z_);
158     }
159     return Point3(p.x_ / divisor, p.y_ / divisor, p.z_ / divisor);
160 }
161 
162 inline const Point3 operator+(const Point3& p)
163 {
164     return Point3(p.x_, p.y_, p.z_);
165 }
166 
167 inline const Point3 operator-(const Point3& p)
168 {
169     return Point3(-p.x_, -p.y_, -p.z_);
170 }
171 
172 inline bool operator==(const Point3& p1, const Point3& p2)
173 {
174     return IsScalarAlmostEqual(p1.x_, p2.x_) && IsScalarAlmostEqual(p1.y_, p2.y_) && IsScalarAlmostEqual(p1.z_, p2.z_);
175 }
176 
177 inline bool operator!=(const Point3& p1, const Point3& p2)
178 {
179     return !IsScalarAlmostEqual(p1.x_, p2.x_) || !IsScalarAlmostEqual(p1.y_, p2.y_) ||
180         !IsScalarAlmostEqual(p1.z_, p2.z_);
181 }
182 } // namespace Drawing
183 } // namespace Rosen
184 } // namespace OHOS
185 #endif