19#define M_PI 3.14159265358979323846
24#include <boost/smart_ptr.hpp>
46#if !defined(__clang__) && defined(__GNUC__)
47#pragma GCC diagnostic push
48#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
60 constexpr Point3D(
double xv,
double yv,
double zv) :
x(xv),
y(yv),
z(zv) {}
65 :
Point(other),
x(other.
x),
y(other.
y),
z(other.
z) {}
67 [[nodiscard]]
constexpr Point *
copy()
const override {
71 constexpr unsigned int dimension()
const override {
return 3; }
73 constexpr double operator[](
unsigned int i)
const override {
102 if (&other ==
this) {
148 double l = this->
length();
150 throw std::runtime_error(
"Cannot normalize a zero length vector");
159 double res =
x *
x +
y *
y +
z *
z;
165 double res =
x *
x +
y *
y +
z *
z;
170 double res =
x * (other.
x) +
y * (other.
y) +
z * (other.
z);
183 dotProd /= sqrt(lsq);
186 if (dotProd <= -1.0) {
189 if (dotProd >= 1.0) {
193 return acos(dotProd);
202 double res = this->
angleTo(other);
205 res = 2.0 *
M_PI - res;
230 res.
x =
y * (other.
z) -
z * (other.
y);
231 res.
y = -
x * (other.
z) +
z * (other.
x);
232 res.
z =
x * (other.
y) -
y * (other.
x);
290 constexpr Point2D(
double xv,
double yv) :
x(xv),
y(yv) {}
294 :
Point(other),
x(other.
x),
y(other.
y) {}
302 constexpr unsigned int dimension()
const override {
return 2; }
366 double ln = this->
length();
368 throw std::runtime_error(
"Cannot normalize a zero length vector");
383 double res =
x *
x +
y *
y;
388 double res =
x *
x +
y *
y;
393 double res =
x * (other.
x) +
y * (other.
y);
402 double dotProd = t1.dotProduct(t2);
404 if (dotProd < -1.0) {
406 }
else if (dotProd > 1.0) {
409 return acos(dotProd);
413 double res = this->
angleTo(other);
415 res = 2.0 *
M_PI - res;
435 dp_storage.reset(nvec);
441 dp_storage.reset(nvec);
449 return dp_storage.get()->getVal(i);
453 return (*dp_storage.get())[i];
456 inline void normalize()
override { dp_storage.get()->normalize(); }
458 inline double length()
const override {
return dp_storage.get()->normL2(); }
461 return dp_storage.get()->normL2Sq();
464 unsigned int dimension()
const override {
return dp_storage.get()->size(); }
467 if (
this == &other) {
473 dp_storage.reset(nvec);
478 (*dp_storage.get()) += (*other.getStorage());
483 (*dp_storage.get()) -= (*other.getStorage());
488 (*dp_storage.get()) *= scale;
493 (*dp_storage.get()) /= scale;
499 "Point dimensions do not match");
507 return dp_storage.get()->dotProduct(*other.getStorage());
512 double n1 = this->
length();
513 double n2 = other.
length();
514 if ((n1 > 1.e-8) && (n2 > 1.e-8)) {
519 }
else if (dp > 1.0) {
526 VECT_SH_PTR dp_storage;
528 return dp_storage.get();
532#if !defined(__clang__) && defined(__GNUC__)
533#pragma GCC diagnostic pop
#define PRECONDITION(expr, mess)
static constexpr double zero_tolerance
constexpr Point2D operator-() const
constexpr double dotProduct(const Point2D &other) const
Point2D directionVector(const Point2D &other) const
constexpr Point * copy() const override
constexpr Point2D(const Point3D &p3d)
construct from a Point3D (ignoring the z coordinate)
constexpr Point2D & operator=(const Point2D &other)
constexpr ~Point2D() override
constexpr Point2D(const Point2D &other)
constexpr Point2D & operator-=(const Point2D &other)
constexpr Point2D & operator*=(double scale)
constexpr Point2D & operator/=(double scale)
constexpr Point2D(double xv, double yv)
constexpr Point2D & operator+=(const Point2D &other)
constexpr double lengthSq() const override
constexpr double & operator[](unsigned int i) override
void normalize() override
constexpr double operator[](unsigned int i) const override
constexpr unsigned int dimension() const override
double length() const override
constexpr void rotate90()
double signedAngleTo(const Point2D &other) const
double angleTo(const Point2D &other) const
constexpr Point3D & operator+=(const Point3D &other)
constexpr Point3D & operator-=(const Point3D &other)
constexpr Point3D & operator/=(double scale)
constexpr Point3D(double xv, double yv, double zv)
double signedAngleTo(const Point3D &other) const
determines the signed angle between a vector to this point from the origin and a vector to the other ...
double angleTo(const Point3D &other) const
determines the angle between a vector to this point from the origin and a vector to the other point.
constexpr ~Point3D() override
constexpr double & operator[](unsigned int i) override
constexpr Point * copy() const override
double length() const override
constexpr Point3D(const Point3D &other)
constexpr double lengthSq() const override
constexpr Point3D & operator=(const Point3D &other)
constexpr Point3D operator-() const
constexpr unsigned int dimension() const override
constexpr Point3D & operator*=(double scale)
constexpr Point3D crossProduct(const Point3D &other) const
Cross product of this point with the another point.
constexpr double dotProduct(const Point3D &other) const
Point3D directionVector(const Point3D &other) const
Returns a normalized direction vector from this point to another.
constexpr double operator[](unsigned int i) const override
constexpr void normalize() override
Point3D getPerpendicular() const
Get a unit perpendicular from this point (treating it as a vector):
PointND & operator+=(const PointND &other)
PointND & operator/=(double scale)
double & operator[](unsigned int i) override
double length() const override
unsigned int dimension() const override
boost::shared_ptr< RDNumeric::Vector< double > > VECT_SH_PTR
double dotProduct(const PointND &other) const
~PointND() override=default
PointND & operator=(const PointND &other)
double lengthSq() const override
PointND(const PointND &other)
void normalize() override
double angleTo(const PointND &other) const
PointND & operator*=(double scale)
PointND & operator-=(const PointND &other)
double operator[](unsigned int i) const override
Point * copy() const override
PointND(unsigned int dim)
PointND directionVector(const PointND &other)
virtual double lengthSq() const =0
virtual Point * copy() const =0
virtual double length() const =0
virtual void normalize()=0
virtual unsigned int dimension() const =0
virtual constexpr ~Point()
virtual double operator[](unsigned int i) const =0
virtual double & operator[](unsigned int i)=0
A class to represent vectors of numbers.
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
#define RDKIT_RDGEOMETRYLIB_EXPORT
Point3DPtrVect::iterator Point3DPtrVect_I
std::vector< RDGeom::Point * > PointPtrVect
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator/(const RDGeom::Point3D &p1, double v)
PointPtrVect::const_iterator PointPtrVect_CI
std::vector< const RDGeom::Point3D * > Point3DConstPtrVect
std::map< int, Point2D > INT_POINT2D_MAP
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator*(const RDGeom::Point3D &p1, double v)
Point3DConstPtrVect::iterator Point3DConstPtrVect_I
std::vector< Point3D >::iterator POINT3D_VECT_I
Point3DPtrVect::const_iterator Point3DPtrVect_CI
std::vector< RDGeom::Point3D * > Point3DPtrVect
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator-(const RDGeom::Point3D &p1, const RDGeom::Point3D &p2)
Point3DConstPtrVect::const_iterator Point3DConstPtrVect_CI
Point2DPtrVect::iterator Point2DPtrVect_I
RDKIT_RDGEOMETRYLIB_EXPORT std::ostream & operator<<(std::ostream &target, const RDGeom::Point &pt)
INT_POINT2D_MAP::const_iterator INT_POINT2D_MAP_CI
RDKIT_RDGEOMETRYLIB_EXPORT double computeDihedralAngle(const Point3D &pt1, const Point3D &pt2, const Point3D &pt3, const Point3D &pt4)
std::vector< Point3D >::const_iterator POINT3D_VECT_CI
INT_POINT2D_MAP::iterator INT_POINT2D_MAP_I
std::vector< RDGeom::Point2D * > Point2DPtrVect
Point2DPtrVect::const_iterator Point2DPtrVect_CI
std::vector< Point3D > POINT3D_VECT
RDKIT_RDGEOMETRYLIB_EXPORT double computeSignedDihedralAngle(const Point3D &pt1, const Point3D &pt2, const Point3D &pt3, const Point3D &pt4)
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator+(const RDGeom::Point3D &p1, const RDGeom::Point3D &p2)
PointPtrVect::iterator PointPtrVect_I