Debian Codegraph @

src/atlas/interpolation/Vector3D.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include "atlas/library/config.h"
14
15 #if ATLAS_HAVE_EIGEN
16
17 #define EIGEN_NO_AUTOMATIC_RESIZING
18 //#define EIGEN_DONT_ALIGN
19 //#define EIGEN_DONT_VECTORIZE
20
21 ATLAS_SUPPRESS_WARNINGS_PUSH
22 ATLAS_SUPPRESS_WARNINGS_INTEGER_SIGN_CHANGE
23 ATLAS_SUPPRESS_WARNINGS_CODE_IS_UNREACHABLE
24 #include <Eigen/Core>
25 #include <Eigen/Dense>
26 ATLAS_SUPPRESS_WARNINGS_POP
27 #else
28
29 #include <cmath>
30 #include <iosfwd>
31
32 #endif
33
34 namespace atlas {
35 namespace interpolation {
36
37 //----------------------------------------------------------------------------------------------------------------------
38
39 #if ATLAS_HAVE_EIGEN
40
41 typedef Eigen::Vector3d Vector3D;
42
43 #else
44
45 class Vector3D {
46 public:
47 Vector3D(const double* d) {
48 xyz_[0] = d[0];
49 xyz_[1] = d[1];
50 xyz_[2] = d[2];
51 }
52
53 Vector3D(double x, double y, double z) {
54 xyz_[0] = x;
55 xyz_[1] = y;
56 xyz_[2] = z;
57 }
58
59 Vector3D() {
60 // Warning, data_ is uninitialised
61 }
62
63 static Vector3D Map(const double* data) { return Vector3D(data); }
64
65 // Operators
66
67 double operator[](size_t i) const { return xyz_[i]; }
68
69 // Vector3D operator*(const Vector3D &) const;
70 Vector3D operator-(const Vector3D& other) const {
71 return Vector3D(x() - other.x(), y() - other.y(), z() - other.z());
72 }
73
74 Vector3D operator+(const Vector3D& other) const {
75 return Vector3D(x() + other.x(), y() + other.y(), z() + other.z());
76 }
77
78 Vector3D operator-() const { return Vector3D(-x(), -y(), -z()); }
79
80 Vector3D operator/(double a) const { return Vector3D(x() / a, y() / a, z() / a); }
81
82 Vector3D operator*(double a) const { return Vector3D(x() * a, y() * a, z() * a); }
83
84 double norm() const { return std::sqrt(squaredNorm()); }
85
86 double squaredNorm() const { return x() * x() + y() * y() + z() * z(); }
87
88 double dot(const Vector3D& other) const { return x() * other.x() + y() * other.y() + z() * other.z(); }
89
90 Vector3D cross(const Vector3D& other) const {
91 return Vector3D(y() * other.z() - z() * other.y(), z() * other.x() - x() * other.z(),
92 x() * other.y() - y() * other.x());
93 }
94
95 void print(std::ostream& s) const;
96
97 friend std::ostream& operator<<(std::ostream& s, const Vector3D& p) {
98 p.print(s);
99 return s;
100 }
101
102 double* data() { return xyz_; }
103
104 const double* data() const { return xyz_; }
105
106 private:
107 double x() const { return xyz_[0]; }
108 double y() const { return xyz_[1]; }
109 double z() const { return xyz_[2]; }
110 double xyz_[3];
111 };
112
113 Vector3D operator*(double, const Vector3D&);
114
115 #endif
116
117 //----------------------------------------------------------------------------------------------------------------------
118
119 } // namespace interpolation
120 } // namespace atlas