Coverage Report

Created: 2026-03-31 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rdkit/Code/Geometry/point.cpp
Line
Count
Source
1
// $Id$
2
//
3
// Copyright (C) 2003-2006 Rational Discovery LLC
4
//
5
//   @@ All Rights Reserved @@
6
//  This file is part of the RDKit.
7
//  The contents are covered by the terms of the BSD license
8
//  which is included in the file license.txt, found at the root
9
//  of the RDKit source tree.
10
//
11
#include "point.h"
12
// #include <Numerics/Vector.h>
13
14
namespace RDGeom {
15
double computeSignedDihedralAngle(const Point3D &pt1, const Point3D &pt2,
16
0
                                  const Point3D &pt3, const Point3D &pt4) {
17
0
  Point3D begEndVec = pt3 - pt2;
18
0
  Point3D begNbrVec = pt1 - pt2;
19
0
  Point3D crs1 = begNbrVec.crossProduct(begEndVec);
20
21
0
  Point3D endNbrVec = pt4 - pt3;
22
0
  Point3D crs2 = endNbrVec.crossProduct(begEndVec);
23
24
0
  double ang = crs1.angleTo(crs2);
25
26
  // now calculate the sign:
27
0
  Point3D crs3 = crs1.crossProduct(crs2);
28
0
  double dot = crs3.dotProduct(begEndVec);
29
0
  if (dot < 0.0) {
30
0
    ang *= -1;
31
0
  }
32
33
0
  return ang;
34
0
}
35
double computeDihedralAngle(const Point3D &pt1, const Point3D &pt2,
36
2.00k
                            const Point3D &pt3, const Point3D &pt4) {
37
2.00k
  Point3D begEndVec = pt3 - pt2;
38
2.00k
  Point3D begNbrVec = pt1 - pt2;
39
2.00k
  Point3D crs1 = begNbrVec.crossProduct(begEndVec);
40
41
2.00k
  Point3D endNbrVec = pt4 - pt3;
42
2.00k
  Point3D crs2 = endNbrVec.crossProduct(begEndVec);
43
44
2.00k
  double ang = crs1.angleTo(crs2);
45
2.00k
  return ang;
46
2.00k
}
47
48
0
std::ostream &operator<<(std::ostream &target, const Point &pt) {
49
0
  for (unsigned int di = 0; di < pt.dimension(); ++di) {
50
0
    target << pt[di] << " ";
51
0
  }
52
53
0
  return target;
54
0
}
55
56
0
Point3D operator+(const Point3D &p1, const Point3D &p2) {
57
0
  Point3D res;
58
0
  res.x = p1.x + p2.x;
59
0
  res.y = p1.y + p2.y;
60
0
  res.z = p1.z + p2.z;
61
0
  return res;
62
0
}
63
64
94.8k
Point3D operator-(const Point3D &p1, const Point3D &p2) {
65
94.8k
  Point3D res;
66
94.8k
  res.x = p1.x - p2.x;
67
94.8k
  res.y = p1.y - p2.y;
68
94.8k
  res.z = p1.z - p2.z;
69
94.8k
  return res;
70
94.8k
}
71
72
0
Point3D operator*(const Point3D &p1, double v) {
73
0
  Point3D res;
74
0
  res.x = p1.x * v;
75
0
  res.y = p1.y * v;
76
0
  res.z = p1.z * v;
77
0
  return res;
78
0
}
79
80
0
Point3D operator/(const Point3D &p1, double v) {
81
0
  Point3D res;
82
0
  res.x = p1.x / v;
83
0
  res.y = p1.y / v;
84
0
  res.z = p1.z / v;
85
0
  return res;
86
0
}
87
88
0
Point2D operator+(const Point2D &p1, const Point2D &p2) {
89
0
  Point2D res;
90
0
  res.x = p1.x + p2.x;
91
0
  res.y = p1.y + p2.y;
92
0
  return res;
93
0
}
94
95
0
Point2D operator-(const Point2D &p1, const Point2D &p2) {
96
0
  Point2D res;
97
0
  res.x = p1.x - p2.x;
98
0
  res.y = p1.y - p2.y;
99
0
  return res;
100
0
}
101
102
0
Point2D operator*(const Point2D &p1, double v) {
103
0
  Point2D res;
104
0
  res.x = p1.x * v;
105
0
  res.y = p1.y * v;
106
0
  return res;
107
0
}
108
109
0
Point2D operator/(const Point2D &p1, double v) {
110
0
  Point2D res;
111
0
  res.x = p1.x / v;
112
0
  res.y = p1.y / v;
113
0
  return res;
114
0
}
115
116
0
PointND operator+(const PointND &p1, const PointND &p2) {
117
0
  unsigned int dim;
118
0
  if (p1.dimension() < p2.dimension()) {
119
0
    dim = p1.dimension();
120
0
  } else {
121
0
    dim = p2.dimension();
122
0
  }
123
0
  PointND res(dim);
124
0
  for (unsigned int i = 0; i < dim; ++i) {
125
0
    res[i] = p1[i] + p2[i];
126
0
  }
127
0
  return res;
128
0
}
129
0
PointND operator-(const PointND &p1, const PointND &p2) {
130
0
  unsigned int dim;
131
0
  if (p1.dimension() < p2.dimension()) {
132
0
    dim = p1.dimension();
133
0
  } else {
134
0
    dim = p2.dimension();
135
0
  }
136
0
  PointND res(dim);
137
0
  for (unsigned int i = 0; i < dim; ++i) {
138
0
    res[i] = p1[i] - p2[i];
139
0
  }
140
0
  return res;
141
0
}
142
143
0
PointND operator*(const PointND &p1, double v) {
144
0
  PointND res(p1.dimension());
145
0
  for (unsigned int i = 0; i < p1.dimension(); ++i) {
146
0
    res[i] = p1[i] * v;
147
0
  }
148
0
  return res;
149
0
}
150
151
0
PointND operator/(const PointND &p1, double v) {
152
0
  PointND res(p1.dimension());
153
0
  for (unsigned int i = 0; i < p1.dimension(); ++i) {
154
0
    res[i] = p1[i] / v;
155
0
  }
156
0
  return res;
157
0
}
158
}  // namespace RDGeom