16 : m_firstFraction(firstFraction), m_fraction(fraction) {}
19 std::vector<std::pair<double, double>> inputVector)
const {
20 if (inputVector.empty()) {
21 return VertexingError::EmptyInput;
23 if (inputVector.size() == 1) {
24 return inputVector.begin()->first;
29 std::sort(inputVector.begin(), inputVector.end(),
30 [](std::pair<double, double>
a, std::pair<double, double>
b) {
31 return a.first <
b.first;
35 auto begin = inputVector.begin();
36 auto end = inputVector.end();
38 double overallweight(0.);
39 auto best_begin = begin;
44 bool isthelast =
false;
47 double fraction = m_firstFraction;
51 fraction = m_fraction;
53 int step = (
int)std::floor(fraction * (end - begin + 1));
58 auto j_end = i + step - 1;
59 for (
auto j = i; j != j_end; j++) {
60 overallweight += j->second;
64 auto i_last = begin + step - 1;
66 for (
auto i = begin; i != (end - step + 1); ++i, ++i_last) {
68 overallweight += i_last->second;
70 double new_value = ((i + step - 1)->first - i->first) / overallweight;
71 if (new_value < last_value) {
72 last_value = ((i + step - 1)->first - i->first) / overallweight;
74 best_end = i + step - 1;
76 overallweight -= i->second;
85 if (best_end - best_begin <= 2) {
90 if (best_end - best_begin == 2) {
93 return (begin->first * begin->second + medium->first * medium->second +
94 end->first * end->second) /
95 (begin->second + medium->second + end->second);
98 return (begin->first * begin->second + end->first * end->second) /
99 (begin->second + end->second);