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
20namespace MathLib
21{
23{
24public:
26 Point3d();
27
32 explicit Point3d(std::array<double, 3> x);
33
35 virtual ~Point3d() = default;
36
37 Point3d(Point3d const&) = default;
38 Point3d& operator=(Point3d const&) = default;
39
45 const double& operator[](std::size_t idx) const
46 {
47 assert(idx < 3);
48 return x_[idx];
49 }
53 double& operator[](std::size_t idx)
54 {
55 return const_cast<double&>(static_cast<const Point3d&>(*this)[idx]);
56 }
57
59 const double* data() const { return x_.data(); }
60
61 double* data() { return x_.data(); }
62
63 Eigen::Vector3d const& asEigenVector3d() const { return x_; }
64 Eigen::Vector3d& asEigenVector3d() { return x_; }
65
66private:
67 Eigen::Vector3d x_;
68};
69
70inline bool operator<(Point3d const& a, Point3d const& b)
71{
72 return std::lexicographical_compare(a.data(), a.data() + 3, b.data(),
73 b.data() + 3);
74}
75
87bool lessEq(Point3d const& a, Point3d const& b,
88 double eps = std::numeric_limits<double>::epsilon());
89
91inline std::ostream& operator<<(std::ostream& os, const Point3d& p)
92{
93 os << p[0] << " " << p[1] << " " << p[2];
94 return os;
95}
96
104MathLib::Point3d operator*(Eigen::Matrix3d const& mat,
105 MathLib::Point3d const& p);
106
109double sqrDist(MathLib::Point3d const& p0, MathLib::Point3d const& p1);
110
113inline bool operator==(Point3d const& a, Point3d const& b)
114{
115 auto const sqr_dist(sqrDist(a, b));
116 auto const eps = std::numeric_limits<double>::epsilon();
117 return (sqr_dist < eps * eps);
118}
119
122inline double sqrDist2d(MathLib::Point3d const& p0, MathLib::Point3d const& p1)
123{
124 return (p0[0] - p1[0]) * (p0[0] - p1[0]) +
125 (p0[1] - p1[1]) * (p0[1] - p1[1]);
126}
127
128} // end namespace MathLib
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:45
double & operator[](std::size_t idx)
access operator (see book Effektiv C++ programmieren - subsection 1.3.2 ).
Definition Point3d.h:53
Eigen::Vector3d const & asEigenVector3d() const
Definition Point3d.h:63
Point3d & operator=(Point3d const &)=default
const double * data() const
Definition Point3d.h:59
Eigen::Vector3d & asEigenVector3d()
Definition Point3d.h:64
Point3d(Point3d const &)=default
virtual ~Point3d()=default
double * data()
Definition Point3d.h:61
Eigen::Vector3d x_
Definition Point3d.h:67
#define MATHLIB_EXPORT
bool operator<(Point3d const &a, Point3d const &b)
Definition Point3d.h:70
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:91
bool operator==(Point3d const &a, Point3d const &b)
Definition Point3d.h:113
static const double p
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.h:122
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:97