Scine::Readuct  6.0.0
This is the SCINE module ReaDuct.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
PointSequence.h
Go to the documentation of this file.
1 
8 #ifndef READUCT_ELEMENTARYSTEPOPTIMIZATION_POINTSEQUENCE_H
9 #define READUCT_ELEMENTARYSTEPOPTIMIZATION_POINTSEQUENCE_H
10 
11 #include <cassert>
12 #include <vector>
13 
14 // TODO: Improve documentation
15 
16 namespace Scine {
17 namespace Readuct {
18 
19 namespace ElementaryStepOptimization {
20 
26  public:
27  PointSequence() = default;
28  PointSequence(double min, double max, int numberPoints);
29 
30  int count() const;
31 
33  bool isUniform() const;
34 
36  double interval() const;
37 
38  double operator[](int index) const;
39  double at(int index) const;
40 
41  double min() const;
42  double max() const;
43 
44  const std::vector<double>& underlyingArray() const;
45 
46  private:
47  using container = std::vector<double>;
48 
49  container points_;
50  double interval_{0};
51 };
52 
53 inline PointSequence::PointSequence(double min, double max, int numberPoints) {
54  assert(max >= min);
55  assert(numberPoints > 1);
56 
57  interval_ = (max - min) / (numberPoints - 1);
58 
59  points_.resize(numberPoints);
60 
61  for (int i = 0; i < numberPoints; ++i) {
62  points_[i] = min + i * interval_;
63  }
64 }
65 
66 inline int PointSequence::count() const {
67  return static_cast<int>(points_.size());
68 }
69 
70 inline bool PointSequence::isUniform() const {
71  return true;
72 }
73 
74 inline double PointSequence::interval() const {
75  assert(isUniform());
76  return interval_;
77 }
78 
79 inline double PointSequence::operator[](int index) const {
80  return points_[static_cast<container::size_type>(index)];
81 }
82 
83 inline double PointSequence::at(int index) const {
84  return points_.at(static_cast<container::size_type>(index));
85 }
86 
87 inline double PointSequence::min() const {
88  return points_.front();
89 }
90 
91 inline double PointSequence::max() const {
92  return points_.back();
93 }
94 
95 inline const std::vector<double>& PointSequence::underlyingArray() const {
96  return points_;
97 }
98 
99 } // namespace ElementaryStepOptimization
100 } // namespace Readuct
101 } // namespace Scine
102 
103 #endif // ELEMENTARYSTEPOPTIMIZATION_POINTSEQUENCE_H
double interval() const
Definition: PointSequence.h:74
bool isUniform() const
Definition: PointSequence.h:70