20#define M_PI 3.14159265358979323846
25#include <boost/smart_ptr.hpp>
47#if !defined(__clang__) && defined(__GNUC__)
48#pragma GCC diagnostic push
49#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
61 Point3D(
double xv,
double yv,
double zv) : x(xv), y(yv), z(zv) {}
66 :
Point(other), x(other.x), y(other.y), z(other.z) {}
70 inline unsigned int dimension()
const override {
return 3; }
72 inline double operator[](
unsigned int i)
const override {
101 if (&other ==
this) {
147 double l = this->length();
154 double res = x * x + y * y + z * z;
160 double res = x * x + y * y + z * z;
165 double res = x * (other.
x) + y * (other.
y) + z * (other.
z);
176 double lsq = lengthSq() * other.
lengthSq();
177 double dotProd = dotProduct(other);
178 dotProd /= sqrt(lsq);
181 if (dotProd <= -1.0) {
184 if (dotProd >= 1.0) {
188 return acos(dotProd);
197 double res = this->angleTo(other);
199 if ((this->x * other.
y - this->y * other.
x) < -1e-6) {
200 res = 2.0 *
M_PI - res;
225 res.
x = y * (other.
z) - z * (other.
y);
226 res.
y = -x * (other.
z) + z * (other.
x);
227 res.
z = x * (other.
y) - y * (other.
x);
286 Point2D(
double xv,
double yv) : x(xv), y(yv) {}
295 inline unsigned int dimension()
const override {
return 2; }
359 double ln = this->length();
372 double res = x * x + y * y;
377 double res = x * x + y * y;
382 double res = x * (other.
x) + y * (other.
y);
391 double dotProd = t1.dotProduct(t2);
393 if (dotProd < -1.0) {
395 }
else if (dotProd > 1.0) {
398 return acos(dotProd);
402 double res = this->angleTo(other);
403 if ((this->x * other.
y - this->y * other.
x) < -1e-6) {
404 res = 2.0 *
M_PI - res;
424 dp_storage.reset(nvec);
430 dp_storage.reset(nvec);
436 template <
typename T>
439 dp_storage.reset(nvec);
441 typename T::const_iterator it;
454 return dp_storage.get()->getVal(i);
458 return (*dp_storage.get())[i];
461 inline void normalize()
override { dp_storage.get()->normalize(); }
463 inline double length()
const override {
return dp_storage.get()->normL2(); }
466 return dp_storage.get()->normL2Sq();
469 unsigned int dimension()
const override {
return dp_storage.get()->size(); }
472 if (
this == &other) {
478 dp_storage.reset(nvec);
483 (*dp_storage.get()) += (*other.getStorage());
488 (*dp_storage.get()) -= (*other.getStorage());
493 (*dp_storage.get()) *= scale;
498 (*dp_storage.get()) /= scale;
504 "Point dimensions do not match");
512 return dp_storage.get()->dotProduct(*other.getStorage());
516 double dp = this->dotProduct(other);
517 double n1 = this->length();
518 double n2 = other.
length();
519 if ((n1 > 1.e-8) && (n2 > 1.e-8)) {
524 }
else if (dp > 1.0) {
531 VECT_SH_PTR dp_storage;
533 return dp_storage.get();
537#if !defined(__clang__) && defined(__GNUC__)
538#pragma GCC diagnostic pop
#define POSTCONDITION(expr, mess)
#define PRECONDITION(expr, mess)
unsigned int dimension() const override
Point2D(double xv, double yv)
Point2D(const Point2D &other)
Point2D directionVector(const Point2D &other) const
Point2D & operator*=(double scale)
Point2D & operator=(const Point2D &other)
Point2D & operator/=(double scale)
Point2D & operator+=(const Point2D &other)
Point2D & operator-=(const Point2D &other)
Point2D(const Point3D &p3d)
construct from a Point3D (ignoring the z coordinate)
~Point2D() override=default
Point2D operator-() const
double dotProduct(const Point2D &other) const
double lengthSq() const override
Point * copy() const override
void normalize() override
double length() const override
double operator[](unsigned int i) const override
double & operator[](unsigned int i) override
double signedAngleTo(const Point2D &other) const
double angleTo(const Point2D &other) const
Point3D(const Point3D &other)
double lengthSq() const override
Point3D operator-() const
unsigned int dimension() const override
Point3D & operator=(const Point3D &other)
double dotProduct(const Point3D &other) const
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 operator[](unsigned int i) const override
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.
Point3D & operator-=(const Point3D &other)
Point3D crossProduct(const Point3D &other) const
Cross product of this point with the another point.
~Point3D() override=default
double & operator[](unsigned int i) override
double length() const override
Point3D(double xv, double yv, double zv)
Point * copy() const override
void normalize() override
Point3D & operator/=(double scale)
Point3D directionVector(const Point3D &other) const
Returns a normalized direction vector from this point to another.
Point3D & operator+=(const Point3D &other)
Point3D getPerpendicular() const
Get a unit perpendicular from this point (treating it as a vector):
Point3D & operator*=(double scale)
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 double operator[](unsigned int i) const =0
virtual double & operator[](unsigned int i)=0
A class to represent vectors of numbers.
void setVal(unsigned int i, TYPE val)
sets the index at a particular value
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