• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "Vector3.h"
17 #include <cmath>
18 #include "cmath"
Add(Vector3 lhs,Vector3 rhs)19 Vector3 Vector3::Add(Vector3 lhs, Vector3 rhs)
20 {
21     return Vector3(lhs.dataX + rhs.dataX, lhs.dataY + rhs.dataY, lhs.dataZ + rhs.dataZ);
22 }
23 
Subtract(Vector3 lhs,Vector3 rhs)24 Vector3 Vector3::Subtract(Vector3 lhs, Vector3 rhs)
25 {
26     return Vector3(lhs.dataX - rhs.dataX, lhs.dataY - rhs.dataY, lhs.dataZ - rhs.dataZ);
27 }
28 
Multiply(Vector3 lhs,float rhs)29 Vector3 Vector3::Multiply(Vector3 lhs, float rhs) { return Vector3(lhs.dataX * rhs, lhs.dataY * rhs, lhs.dataZ * rhs); }
GetDataX()30 float Vector3::GetDataX() { return this->dataX; }
SetDataX(float xData)31 void Vector3::SetDataX(float xData) { this->dataX = xData; }
GetDataY()32 float Vector3::GetDataY() { return this->dataY; }
SetDataY(float yData)33 void Vector3::SetDataY(float yData) { this->dataY = yData; }
GetDataZ()34 float Vector3::GetDataZ() { return this->dataZ; }
SetDataZ(float zData)35 void Vector3::SetDataZ(float zData) { this->dataZ = zData; }
36 
Length(Vector3 lhs)37 float Vector3::Length(Vector3 lhs)
38 {
39     return static_cast<float>(std::sqrt(lhs.dataX * lhs.dataX + lhs.dataY * lhs.dataY + lhs.dataZ * lhs.dataZ));
40 }
41 
Normalize(Vector3 lhs)42 Vector3 Vector3::Normalize(Vector3 lhs)
43 {
44     float oneOverLen = 1.0F / Length(lhs);
45     return isfinite(oneOverLen) ? Vector3(lhs.dataX * oneOverLen, lhs.dataY * oneOverLen, lhs.dataZ * oneOverLen)
46                                 : Vector3(0, 0, 0);
47 }
48 
Cross(Vector3 lhs,Vector3 rhs)49 Vector3 Vector3::Cross(Vector3 lhs, Vector3 rhs)
50 {
51     float newDataX = lhs.dataY * rhs.dataZ - lhs.dataZ * rhs.dataY;
52     float newDataY = lhs.dataZ * rhs.dataX - lhs.dataX * rhs.dataZ;
53     float newDataZ = lhs.dataX * rhs.dataY - lhs.dataY * rhs.dataX;
54     return Vector3(newDataX, newDataY, newDataZ);
55 }
56 
Dot(Vector3 lhs,Vector3 rhs)57 float Vector3::Dot(Vector3 lhs, Vector3 rhs)
58 {
59     return lhs.dataX * rhs.dataX + lhs.dataY * rhs.dataY + lhs.dataZ * rhs.dataZ;
60 }
61