OGS
Point3d.h
Go to the documentation of this file.
1
13#pragma once
14
15#include <Eigen/Core>
16#include <cassert>
17#include <limits>
18
19#include "mathlib_export.h"
20
21namespace MathLib
22{
24{
25public:
27 Point3d();
28
33 explicit Point3d(std::array<double, 3> x);
34
36 virtual ~Point3d() = default;
37
38 Point3d(Point3d const&) = default;
39 Point3d& operator=(Point3d const&) = default;
40
46 const double& operator[](std::size_t idx) const
47 {
48 assert(idx < 3);
49 return x_[idx];
50 }
54 double& operator[](std::size_t idx)
55 {
56 return const_cast<double&>(static_cast<const Point3d&>(*this)[idx]);
57 }
58
60 const double* data() const { return x_.data(); }
61
62 double* data() { return x_.data(); }
63
64 Eigen::Vector3d const& asEigenVector3d() const { return x_; }
65 Eigen::Vector3d& asEigenVector3d() { return x_; }
66
67private:
68 Eigen::Vector3d x_;
69};
70
71inline bool operator<(Point3d const& a, Point3d const& b)
72{
73 return std::lexicographical_compare(a.data(), a.data() + 3, b.data(),
74 b.data() + 3);
75}
76
88bool lessEq(Point3d const& a, Point3d const& b,
89 double eps = std::numeric_limits<double>::epsilon());
90
92inline std::ostream& operator<<(std::ostream& os, const Point3d& p)
93{
94 os << p[0] << " " << p[1] << " " << p[2];
95 return os;
96}
97
105MathLib::Point3d operator*(Eigen::Matrix3d const& mat,
106 MathLib::Point3d const& p);
107
110double sqrDist(MathLib::Point3d const& p0, MathLib::Point3d const& p1);
111
114inline bool operator==(Point3d const& a, Point3d const& b)
115{
116 auto const sqr_dist(sqrDist(a, b));
117 auto const eps = std::numeric_limits<double>::epsilon();
118 return (sqr_dist < eps * eps);
119}
120
123inline double sqrDist2d(MathLib::Point3d const& p0, MathLib::Point3d const& p1)
124{
125 return (p0[0] - p1[0]) * (p0[0] - p1[0]) +
126 (p0[1] - p1[1]) * (p0[1] - p1[1]);
127}
128
129} // 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:46
double & operator[](std::size_t idx)
access operator (see book Effektiv C++ programmieren - subsection 1.3.2 ).
Definition Point3d.h:54
Eigen::Vector3d const & asEigenVector3d() const
Definition Point3d.h:64
Point3d & operator=(Point3d const &)=default
const double * data() const
Definition Point3d.h:60
Eigen::Vector3d & asEigenVector3d()
Definition Point3d.h:65
Point3d(Point3d const &)=default
virtual ~Point3d()=default
double * data()
Definition Point3d.h:62
Eigen::Vector3d x_
Definition Point3d.h:68
#define MATHLIB_EXPORT
bool operator<(Point3d const &a, Point3d const &b)
Definition Point3d.h:71
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:92
bool operator==(Point3d const &a, Point3d const &b)
Definition Point3d.h:114
static const double p
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.h:123
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:98