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();
149 throw std::runtime_error(
"Cannot normalize a zero length vector");
158 double res = x * x + y * y + z * z;
164 double res = x * x + y * y + z * z;
169 double res = x * (other.
x) + y * (other.
y) + z * (other.
z);
180 double lsq = lengthSq() * other.
lengthSq();
181 double dotProd = dotProduct(other);
182 dotProd /= sqrt(lsq);
185 if (dotProd <= -1.0) {
188 if (dotProd >= 1.0) {
192 return acos(dotProd);
201 double res = this->angleTo(other);
204 res = 2.0 *
M_PI - res;
229 res.
x = y * (other.
z) - z * (other.
y);
230 res.
y = -x * (other.
z) + z * (other.
x);
231 res.
z = x * (other.
y) - y * (other.
x);
290 Point2D(
double xv,
double yv) : x(xv), y(yv) {}
299 inline unsigned int dimension()
const override {
return 2; }
363 double ln = this->length();
365 throw std::runtime_error(
"Cannot normalize a zero length vector");
380 double res = x * x + y * y;
385 double res = x * x + y * y;
390 double res = x * (other.
x) + y * (other.
y);
399 double dotProd = t1.dotProduct(t2);
401 if (dotProd < -1.0) {
403 }
else if (dotProd > 1.0) {
406 return acos(dotProd);
410 double res = this->angleTo(other);
412 res = 2.0 *
M_PI - res;
432 dp_storage.reset(nvec);
438 dp_storage.reset(nvec);
444 template <
typename T>
447 dp_storage.reset(nvec);
449 typename T::const_iterator it;
462 return dp_storage.get()->getVal(i);
466 return (*dp_storage.get())[i];
469 inline void normalize()
override { dp_storage.get()->normalize(); }
471 inline double length()
const override {
return dp_storage.get()->normL2(); }
474 return dp_storage.get()->normL2Sq();
477 unsigned int dimension()
const override {
return dp_storage.get()->size(); }
480 if (
this == &other) {
486 dp_storage.reset(nvec);
491 (*dp_storage.get()) += (*other.getStorage());
496 (*dp_storage.get()) -= (*other.getStorage());
501 (*dp_storage.get()) *= scale;
506 (*dp_storage.get()) /= scale;
512 "Point dimensions do not match");
520 return dp_storage.get()->dotProduct(*other.getStorage());
524 double dp = this->dotProduct(other);
525 double n1 = this->length();
526 double n2 = other.
length();
527 if ((n1 > 1.e-8) && (n2 > 1.e-8)) {
532 }
else if (dp > 1.0) {
539 VECT_SH_PTR dp_storage;
541 return dp_storage.get();
545#if !defined(__clang__) && defined(__GNUC__)
546#pragma GCC diagnostic pop
#define POSTCONDITION(expr, mess)
#define PRECONDITION(expr, mess)
static constexpr double zero_tolerance
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