18 : m_firstFraction(firstFraction), m_fraction(fraction) {}
21 std::vector<std::pair<double, double>> inputVector)
const {
22 if (inputVector.empty()) {
23 return VertexingError::EmptyInput;
25 if (inputVector.size() == 1) {
26 return inputVector.begin()->first;
31 std::sort(inputVector.begin(), inputVector.end(),
32 [](std::pair<double, double>
a, std::pair<double, double>
b) {
33 return a.first <
b.first;
37 auto begin = inputVector.begin();
38 auto end = inputVector.end();
40 double overallweight(0.);
41 auto best_begin =
begin;
44 double last_value = std::numeric_limits<double>::max();
46 bool isthelast =
false;
49 double fraction = m_firstFraction;
53 fraction = m_fraction;
55 int step = (int)std::floor(fraction * (
end - begin + 1));
60 auto j_end =
i + step - 1;
61 for (
auto j =
i;
j != j_end;
j++) {
62 overallweight +=
j->second;
66 auto i_last = begin + step - 1;
68 for (
auto i = begin;
i != (
end - step + 1); ++
i, ++i_last) {
70 overallweight += i_last->second;
72 double new_value = ((
i + step - 1)->first -
i->first) / overallweight;
73 if (new_value < last_value) {
74 last_value = ((
i + step - 1)->first -
i->first) / overallweight;
76 best_end =
i + step - 1;
78 overallweight -=
i->second;
84 last_value = std::numeric_limits<double>::max();
87 if (best_end - best_begin <= 2) {
92 if (best_end - best_begin == 2) {
95 return (begin->first * begin->second + medium->first * medium->second +
96 end->first *
end->second) /
97 (begin->second + medium->second +
end->second);
100 return (begin->first * begin->second +
end->first *
end->second) /
101 (begin->second +
end->second);