| 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::Vector2d Vector2D; |
| 42 |
|
| 43 |
#else |
| 44 |
|
| 45 |
class Vector2D { |
| 46 |
public: |
| 47 |
Vector2D(const double* d) { |
| 48 |
xy_[0] = d[0]; |
| 49 |
xy_[1] = d[1]; |
| 50 |
} |
| 51 |
|
| 52 |
Vector2D(double x, double y) { |
| 53 |
xy_[0] = x; |
| 54 |
xy_[1] = y; |
| 55 |
} |
| 56 |
|
| 57 |
Vector2D() { |
| 58 |
// Warning, data_ is uninitialised |
| 59 |
} |
| 60 |
|
| 61 |
static Vector2D Map(const double* data) { return Vector2D(data); } |
| 62 |
|
| 63 |
// Operators |
| 64 |
|
| 65 |
double operator[](size_t i) const { return xy_[i]; } |
| 66 |
|
| 67 |
// Vector2D operator*(const Vector2D &) const; |
| 68 |
Vector2D operator-(const Vector2D& other) const { return Vector2D(x() - other.x(), y() - other.y()); } |
| 69 |
|
| 70 |
Vector2D operator+(const Vector2D& other) const { return Vector2D(x() + other.x(), y() + other.y()); } |
| 71 |
|
| 72 |
Vector2D operator-() const { return Vector2D(-x(), -y()); } |
| 73 |
|
| 74 |
double norm() const { return sqrt(squaredNorm()); } |
| 75 |
|
| 76 |
double squaredNorm() const { return x() * x() + y() * y(); } |
| 77 |
|
| 78 |
double dot(const Vector2D& other) const { return x() * other.x() + y() * other.y(); } |
| 79 |
|
| 80 |
double cross(const Vector2D& other) const { return x() * other.y() - y() * other.x(); } |
| 81 |
|
| 82 |
void print(std::ostream& s) const; |
| 83 |
|
| 84 |
friend std::ostream& operator<<(std::ostream& s, const Vector2D& p) { |
| 85 |
p.print(s); |
| 86 |
return s; |
| 87 |
} |
| 88 |
|
| 89 |
double* data() { return xy_; } |
| 90 |
|
| 91 |
const double* data() const { return xy_; } |
| 92 |
|
| 93 |
double x() const { return xy_[0]; } |
| 94 |
double y() const { return xy_[1]; } |
| 95 |
|
| 96 |
private: |
| 97 |
double xy_[2]; |
| 98 |
}; |
| 99 |
|
| 100 |
Vector2D operator*(double, const Vector2D&); |
| 101 |
|
| 102 |
#endif |
| 103 |
|
| 104 |
//---------------------------------------------------------------------------------------------------------------------- |
| 105 |
|
| 106 |
} // namespace interpolation |
| 107 |
} // namespace atlas |