Debian Codegraph @

src/core/components/commonutils.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/components/commonutils.cpp`/
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "commonutils.h"cxx . . $ `<file>/src/core/components/commonutils.h`/
5
6 #include "common/mathutils.h"cxx . . $ `<file>/src/common/mathutils.h`/
7 #include <algorithm>
8 #include <cstddef>
9 #include <iterator>
10
11 namespace Utilscxx . . $ Utils/::Commoncxx . . $ Utils/Common/ {
12
13 void normalizePointscxx . . $ Utils/Common/normalizePoints(c5e3ead2f69f5981).(
14 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<unitscxx . . $ units/::temperaturecxx . . $ units/temperature/::celsius_tcxx . . $ units/temperature/celsius_t#,
15 unitscxx . . $ units/::concentrationcxx . . $ units/concentration/::percent_tcxx . . $ units/concentration/percent_t#>> &points,
16 stdcxx . . $ std/::paircxx . . $ std/pair#<unitscxx . . $ units/::temperaturecxx . . $ units/temperature/::celsius_tcxx . . $ units/temperature/celsius_t#, unitscxx . . $ units/::temperaturecxx . . $ units/temperature/::celsius_tcxx . . $ units/temperature/celsius_t#> tempRange,
17 stdcxx . . $ std/::paircxx . . $ std/pair#<unitscxx . . $ units/::concentrationcxx . . $ units/concentration/::percent_tcxx . . $ units/concentration/percent_t#, unitscxx . . $ units/::concentrationcxx . . $ units/concentration/::percent_tcxx . . $ units/concentration/percent_t#>
18 speedRange)
19 {
20 stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> tempscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
21
22 if (stdcxx . . $ std/::any_ofcxx . . $ std/any_of(f82cc6ce9cd000ea).(points.cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), points.cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), [&](auto const &point) {
23 return point.first < tempRange.firstcxx . . $ std/pair#first. || point.first > tempRange.secondcxx . . $ std/pair#second.;
24 })) {
25 stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(
26 points.cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), points.cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(temps),
27 [](auto const &point) { return point.first.template to<double>(); });
28
29 auto [minTemp, maxTemp] = stdcxx . . $ std/::minmax_elementcxx . . $ std/minmax_element(823186a669f4f7c8).(temps.cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), temps.cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).());
30
31 Utilscxx . . $ Utils/::Mathcxx . . $ Utils/Math/::linearNormcxx . . $ Utils/Math/linearNorm(985260a9f02479ec).(
32 temps, stdcxx . . $ std/::make_paircxx . . $ std/make_pair(1d30b6e115203116).(stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(0.0, *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).minTemp), stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(90.0, *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).maxTemp)),
33 stdcxx . . $ std/::make_paircxx . . $ std/make_pair(1d30b6e115203116).(tempRange.firstcxx . . $ std/pair#first..tocxx . . $ units/unit_t#to(88b827abdede45d2).<double>(),
34 tempRange.secondcxx . . $ std/pair#second..tocxx . . $ units/unit_t#to(88b827abdede45d2).<double>()));
35 }
36
37 for (size_t i = 0; i < points.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) {
38 auto &[temp, pwm] = points.atcxx . . $ std/vector#at(428bb168810b9e52).(i);
39 pwm =cxx . . $ units/unit_t#`operator=`(ee8d7c56080e6c63). stdcxx . . $ std/::clampcxx . . $ std/clamp(3dbe0c69cb86ae06).(pwm, speedRange.firstcxx . . $ std/pair#first., speedRange.secondcxx . . $ std/pair#second.);
40
41 // ensure that point.pwm >= prevPoint.pwm
42 if (points.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() > 1 && i > 0) {
43 auto const &[_, prevPwm] = points.atcxx . . $ std/vector#at(428bb168810b9e52).(i - 1);
44 if (pwm <cxx . . $ units/unit_t#`operator<`(9aef86f709355c52). prevPwm)
45 pwm =cxx . . $ units/unit_t#`operator=`(ee8d7c56080e6c63). prevPwm;
46 }
47
48 if (!temps.emptycxx . . $ std/vector#empty(3482b152b9333168).())
49 temp =cxx . . $ units/unit_t#`operator=`(dbc6560b31f0f4ef). unitscxx . . $ units/::temperaturecxx . . $ units/temperature/::celsius_tcxx . . $ units/temperature/celsius_t#(temps[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]);
50 }
51 }
52
53 } // namespace Utils::Common