OGS
Point3d.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include <Eigen/Core>
16 #include <limits>
17 
18 #include "mathlib_export.h"
19 
20 namespace MathLib
21 {
26 class Point3d
27 {
28 public:
30  Point3d();
31 
36  explicit Point3d(std::array<double, 3> x);
37 
39  virtual ~Point3d() = default;
40 
41  Point3d(Point3d const&) = default;
42  Point3d& operator=(Point3d const&) = default;
43 
49  const double& operator[](std::size_t idx) const
50  {
51  assert(idx < 3);
52  return x_[idx];
53  }
57  double& operator[](std::size_t idx)
58  {
59  return const_cast<double&>(static_cast<const Point3d&>(*this)[idx]);
60  }
61 
63  const double* data() const { return x_.data(); }
64 
65  double* data() { return x_.data(); }
66 
67  Eigen::Vector3d const& asEigenVector3d() const { return x_; }
68  Eigen::Vector3d& asEigenVector3d() { return x_; }
69 
70 private:
71  Eigen::Vector3d x_;
72 };
73 
74 inline bool operator<(Point3d const& a, Point3d const& b)
75 {
76  return std::lexicographical_compare(a.data(), a.data() + 3, b.data(),
77  b.data() + 3);
78 }
79 
91 bool lessEq(Point3d const& a, Point3d const& b,
92  double eps = std::numeric_limits<double>::epsilon());
93 
95 inline std::ostream& operator<<(std::ostream& os, const Point3d& p)
96 {
97  os << p[0] << " " << p[1] << " " << p[2];
98  return os;
99 }
100 
108 MathLib::Point3d operator*(Eigen::Matrix3d const& mat,
109  MathLib::Point3d const& p);
110 
113 double sqrDist(MathLib::Point3d const& p0, MathLib::Point3d const& p1);
114 
117 inline bool operator==(Point3d const& a, Point3d const& b)
118 {
119  auto const sqr_dist(sqrDist(a, b));
120  auto const eps = std::numeric_limits<double>::epsilon();
121  return (sqr_dist < eps * eps);
122 }
123 
126 inline double sqrDist2d(MathLib::Point3d const& p0, MathLib::Point3d const& p1)
127 {
128  return (p0[0] - p1[0]) * (p0[0] - p1[0]) +
129  (p0[1] - p1[1]) * (p0[1] - p1[1]);
130 }
131 
132 } // end namespace MathLib
Eigen::Vector3d const & asEigenVector3d() const
Definition: Point3d.h:67
Point3d(Point3d const &)=default
const double & operator[](std::size_t idx) const
const access operator The access to the point coordinates is like the access to a field....
Definition: Point3d.h:49
const double * data() const
Definition: Point3d.h:63
virtual ~Point3d()=default
Eigen::Vector3d x_
Definition: Point3d.h:71
double & operator[](std::size_t idx)
access operator (see book Effektiv C++ programmieren - subsection 1.3.2 ).
Definition: Point3d.h:57
Eigen::Vector3d & asEigenVector3d()
Definition: Point3d.h:68
double * data()
Definition: Point3d.h:65
Point3d & operator=(Point3d const &)=default
#define MATHLIB_EXPORT
bool operator<(Point3d const &a, Point3d const &b)
Definition: Point3d.h:74
MathLib::Point3d operator*(Eigen::Matrix3d const &mat, MathLib::Point3d const &p)
Definition: Point3d.cpp:19
std::ostream & operator<<(std::ostream &os, const Point3d &p)
Definition: Point3d.h:95
bool operator==(Point3d const &a, Point3d const &b)
Definition: Point3d.h:117
static const double p
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.h:126
bool lessEq(Point3d const &a, Point3d const &b, double eps)
Definition: Point3d.cpp:31
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.cpp:26
const Point3d ORIGIN
Definition: Point3d.h:101