Debian Codegraph @

packages/seacas/applications/ejoin/EJ_vector3d.C

raw
1 // Copyright(C) 1999-2020, 2023, 2024 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "EJ_vector3d.h"
8 #include <cmath>
9
10 //----------------------------------------------------------------------------
11 vector3d::vector3d(double X, double Y, double Z) : x(X), y(Y), z(Z) {}
12
13 //----------------------------------------------------------------------------
14 vector3d::vector3d(const double location[3]) : x(location[0]), y(location[1]), z(location[2]) {}
15
16 void vector3d::set(double X, double Y, double Z)
17 {
18 x = X;
19 y = Y;
20 z = Z;
21 }
22
23 void vector3d::set(const double location[3])
24 {
25 x = location[0];
26 y = location[1];
27 z = location[2];
28 }
29
30 vector3d &vector3d::reverse()
31 {
32 x = -x;
33 y = -y;
34 z = -z;
35 return *this;
36 }
37
38 bool operator==(const vector3d &lhs, const vector3d &rhs)
39 {
40 return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
41 }
42
43 bool operator!=(const vector3d &lhs, const vector3d &rhs)
44 {
45 return (lhs.x != rhs.x || lhs.y != rhs.y || lhs.z == rhs.z);
46 }
47
48 vector3d operator+(const vector3d &lhs, const vector3d &rhs)
49 {
50 vector3d tmp(lhs);
51 return tmp += rhs;
52 }
53
54 vector3d operator-(const vector3d &lhs, const vector3d &rhs)
55 {
56 vector3d tmp(lhs);
57 return tmp -= rhs;
58 }
59
60 vector3d operator*(const vector3d &lhs, double scalar)
61 {
62 vector3d tmp(lhs);
63 return tmp *= scalar;
64 }
65
66 vector3d vector3d::operator-() const
67 {
68 vector3d tmp(x, y, z);
69 return tmp *= -1.0;
70 }
71
72 vector3d operator*(double scalar, const vector3d &from)
73 {
74 vector3d tmp(from);
75 return tmp *= scalar;
76 }
77
78 vector3d operator/(const vector3d &lhs, double scalar)
79 {
80 if (scalar != 0.0) {
81 vector3d tmp(lhs);
82 return tmp /= scalar;
83 }
84
85 return {HUGE_VAL, HUGE_VAL, HUGE_VAL};
86 }
87
88 vector3d &vector3d::operator/=(double scalar)
89 {
90 if (scalar != 0.0) {
91 x /= scalar;
92 y /= scalar;
93 z /= scalar;
94 }
95 else {
96 x = HUGE_VAL;
97 y = HUGE_VAL;
98 z = HUGE_VAL;
99 }
100
101 return *this;
102 }
103
104 double vector3d::length() const { return sqrt(x * x + y * y + z * z); }