• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 21489819490

29 Jan 2026 06:21PM UTC coverage: 80.077% (-1.9%) from 81.953%
21489819490

Pull #3757

github

web-flow
Merge d08626053 into f7a734189
Pull Request #3757: Testing point detectors

16004 of 22621 branches covered (70.75%)

Branch coverage included in aggregate %.

94 of 518 new or added lines in 26 files covered. (18.15%)

1021 existing lines in 52 files now uncovered.

53779 of 64524 relevant lines covered (83.35%)

8016833.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.74
/include/openmc/position.h
1
#ifndef OPENMC_POSITION_H
2
#define OPENMC_POSITION_H
3

4
#include <cmath> // for sqrt
5
#include <iostream>
6
#include <stdexcept> // for out_of_range
7

8
#include "fmt/format.h"
9
#include "openmc/array.h"
10
#include "openmc/vector.h"
11

12
namespace openmc {
13

14
//==============================================================================
15
//! Type representing a position in Cartesian coordinates
16
//==============================================================================
17

18
struct Position {
19
  // Constructors
20
  Position() = default;
298,630,173✔
21
  Position(double x_, double y_, double z_) : x {x_}, y {y_}, z {z_} {};
367,861,691✔
22
  Position(const double xyz[]) : x {xyz[0]}, y {xyz[1]}, z {xyz[2]} {};
588✔
23
  Position(const vector<double>& xyz) : x {xyz[0]}, y {xyz[1]}, z {xyz[2]} {};
359✔
24
  Position(const array<double, 3>& xyz) : x {xyz[0]}, y {xyz[1]}, z {xyz[2]} {};
25

26
  // Unary operators
27
  Position& operator+=(Position);
28
  Position& operator+=(double);
29
  Position& operator-=(Position);
30
  Position& operator-=(double);
31
  Position& operator*=(Position);
32
  Position& operator*=(double);
33
  Position& operator/=(Position);
34
  Position& operator/=(double);
35
  Position operator-() const;
36

37
  const double& operator[](int i) const
2,147,483,647✔
38
  {
39
    switch (i) {
2,147,483,647!
40
    case 0:
954,321,628✔
41
      return x;
954,321,628✔
42
    case 1:
944,408,810✔
43
      return y;
944,408,810✔
44
    case 2:
862,858,556✔
45
      return z;
862,858,556✔
46
    default:
×
47
      throw std::out_of_range {"Index in Position must be between 0 and 2."};
×
48
    }
49
  }
50
  double& operator[](int i)
2,147,483,647✔
51
  {
52
    switch (i) {
×
53
    case 0:
2,147,483,647✔
54
      return x;
2,147,483,647✔
55
    case 1:
2,147,483,647✔
56
      return y;
2,147,483,647✔
57
    case 2:
795,361,249✔
58
      return z;
795,361,249✔
59
    default:
×
60
      throw std::out_of_range {"Index in Position must be between 0 and 2."};
×
61
    }
62
  }
63

64
  // Access to x, y, or z by compile time known index (specializations below)
65
  template<int i>
66
  const double& get() const
67
  {
68
    throw std::out_of_range {"Index in Position must be between 0 and 2."};
69
  }
70
  template<int i>
71
  double& get()
72
  {
73
    throw std::out_of_range {"Index in Position must be between 0 and 2."};
74
  }
75

76
  // Other member functions
77

78
  //! Dot product of two vectors
79
  //! \param[in] other Vector to take dot product with
80
  //! \result Resulting dot product
81
  inline double dot(Position other) const
763,434,949✔
82
  {
83
    return x * other.x + y * other.y + z * other.z;
763,434,949✔
84
  }
85
  inline double norm() const { return std::sqrt(x * x + y * y + z * z); }
257,362,052✔
86
  inline Position cross(Position other) const
43✔
87
  {
88
    return {y * other.z - z * other.y, z * other.x - x * other.z,
43✔
89
      x * other.y - y * other.x};
43✔
90
  }
91

92
  //! Reflect a direction across a normal vector
93
  //! \param[in] other Vector to reflect across
94
  //! \result Reflected vector
95
  Position reflect(Position n) const;
96

97
  //! Rotate the position by applying a rotation matrix
98
  template<typename T>
99
  Position rotate(const T& rotation) const
1,905,232✔
100
  {
101
    return {x * rotation[0] + y * rotation[1] + z * rotation[2],
1,905,232✔
102
      x * rotation[3] + y * rotation[4] + z * rotation[5],
1,905,232✔
103
      x * rotation[6] + y * rotation[7] + z * rotation[8]};
3,810,464✔
104
  }
105

106
  //! Rotate the position by applying the inverse of a rotation matrix
107
  //! using the fact that rotation matrices are orthonormal.
108
  template<typename T>
109
  Position inverse_rotate(const T& rotation) const
×
110
  {
111
    return {x * rotation[0] + y * rotation[3] + z * rotation[6],
×
112
      x * rotation[1] + y * rotation[4] + z * rotation[7],
×
113
      x * rotation[2] + y * rotation[5] + z * rotation[8]};
×
114
  }
115

116
  // Data members
117
  double x = 0.;
118
  double y = 0.;
119
  double z = 0.;
120
};
121

122
// Compile-time known member index access functions
123
template<>
124
inline const double& Position::get<0>() const
125
{
126
  return x;
127
}
128
template<>
129
inline const double& Position::get<1>() const
130
{
131
  return y;
132
}
133
template<>
134
inline const double& Position::get<2>() const
135
{
136
  return z;
137
}
138
template<>
139
inline double& Position::get<0>()
467,393,867✔
140
{
141
  return x;
467,393,867✔
142
}
143
template<>
144
inline double& Position::get<1>()
467,437,060✔
145
{
146
  return y;
467,437,060✔
147
}
148
template<>
149
inline double& Position::get<2>()
328,599,692✔
150
{
151
  return z;
328,599,692✔
152
}
153

154
// Binary operators
155
inline Position operator+(Position a, Position b)
573,202,834✔
156
{
157
  return a += b;
573,202,834✔
158
}
159
inline Position operator+(Position a, double b)
160
{
161
  return a += b;
162
}
163
inline Position operator+(double a, Position b)
164
{
165
  return b += a;
166
}
167

168
inline Position operator-(Position a, Position b)
318,626,396✔
169
{
170
  return a -= b;
318,626,396✔
171
}
172
inline Position operator-(Position a, double b)
173
{
174
  return a -= b;
175
}
176
inline Position operator-(double a, Position b)
177
{
178
  return b -= a;
179
}
180

181
inline Position operator*(Position a, Position b)
1,357,136✔
182
{
183
  return a *= b;
1,357,136✔
184
}
185
inline Position operator*(Position a, double b)
555,712,812✔
186
{
187
  return a *= b;
555,712,812✔
188
}
189
inline Position operator*(double a, Position b)
1,210,919,907✔
190
{
191
  return b *= a;
1,210,919,907✔
192
}
193

194
inline Position operator/(Position a, Position b)
195
{
196
  return a /= b;
197
}
198
inline Position operator/(Position a, double b)
199,990,235✔
199
{
200
  return a /= b;
199,990,235✔
201
}
202
inline Position operator/(double a, Position b)
203
{
204
  return b /= a;
205
}
206

NEW
207
inline bool operator<(Position a, Position b)
×
208
{
NEW
209
  if (a[0] != b[0])
×
NEW
210
    return (a[0] < b[0]);
×
NEW
211
  if (a[1] != b[1])
×
NEW
212
    return (a[1] < b[1]);
×
NEW
213
  if (a[2] != b[2])
×
NEW
214
    return (a[2] < b[2]);
×
NEW
215
  return false;
×
216
}
217

218
inline Position Position::reflect(Position n) const
59,229,103✔
219
{
220
  const double projection = n.dot(*this);
59,229,103✔
221
  const double magnitude = n.dot(n);
59,229,103✔
222
  n *= (2.0 * projection / magnitude);
59,229,103✔
223
  return *this - n;
59,229,103✔
224
}
225

UNCOV
226
inline bool operator==(Position a, Position b)
×
227
{
UNCOV
228
  return a.x == b.x && a.y == b.y && a.z == b.z;
×
229
}
230

231
inline bool operator!=(Position a, Position b)
176,513,852✔
232
{
233
  return a.x != b.x || a.y != b.y || a.z != b.z;
176,513,852✔
234
}
235

236
std::ostream& operator<<(std::ostream& os, Position a);
237

238
//==============================================================================
239
//! Type representing a vector direction in Cartesian coordinates
240
//==============================================================================
241

242
using Direction = Position;
243

244
} // namespace openmc
245

246
namespace fmt {
247

248
template<>
249
struct formatter<openmc::Position> : formatter<std::string> {
250
  template<typename FormatContext>
251
#if FMT_VERSION >= 110000 // Version 11.0.0 and above
252
  auto format(const openmc::Position& pos, FormatContext& ctx) const {
7✔
253
#else // For versions below 11.0.0
254
  auto format(const openmc::Position& pos, FormatContext& ctx)
255
  {
256
#endif
257
    return formatter<std::string>::format(
14✔
258
      fmt::format("({}, {}, {})", pos.x, pos.y, pos.z), ctx);
21✔
259
}
260
}; // namespace fmt
261

262
} // namespace fmt
263

264
#endif // OPENMC_POSITION_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc