KiCad PCB EDA Suite
|
Helper class that collects solutions and keeps one with the best deviation. More...
Public Member Functions | |
SolutionCollector (double aTarget) | |
void | Add2RLookupResults (std::pair< RESISTANCE &, RESISTANCE & > aResults, std::function< double(double)> aValueFunc, std::function< RESISTANCE(RESISTANCE &)> aResultFunc) |
Add two solutions, based on single 2R buffer lookup, to the collector. | |
RESISTANCE | GetBest () |
Return the best collected combination, running the corresponding result_func. | |
Private Member Functions | |
void | addSolution (double aValue, RESISTANCE *aFound, std::function< RESISTANCE(RESISTANCE &)> &aResultFunc) |
Add single solution to the collector. | |
Private Attributes | |
double | m_target |
double | m_best_deviation = INFINITY |
RESISTANCE * | m_best_found_resistance = nullptr |
std::function< RESISTANCE(RESISTANCE &)> | m_best_result_func |
Helper class that collects solutions and keeps one with the best deviation.
In order to avoid performing costly string operations too frequently, they are postponed until the very end, when we know the best combination.
Definition at line 45 of file resistor_substitution_utils.cpp.
|
inline |
Definition at line 53 of file resistor_substitution_utils.cpp.
|
inline |
Add two solutions, based on single 2R buffer lookup, to the collector.
aResults | are the resistances found in 2R buffer |
aValueFunc | transforms value from aResults into final value of the combination |
aResultFunc | transforms RESISTANCE instance from aResults into final instance |
Definition at line 62 of file resistor_substitution_utils.cpp.
References addSolution().
Referenced by RES_EQUIV_CALC::calculate2RSolution(), RES_EQUIV_CALC::calculate3RSolution(), and RES_EQUIV_CALC::calculate4RSolution().
|
inlineprivate |
Add single solution to the collector.
aValue | is a value of the combination in Ohms |
aFound | is the corresponding RESISTANCE found in 2R buffer |
aResultFunc | is a function calculating final result (RESISTANCE instance) for this combination |
Definition at line 90 of file resistor_substitution_utils.cpp.
References std::abs(), m_best_deviation, m_best_found_resistance, m_best_result_func, and m_target.
Referenced by Add2RLookupResults().
|
inline |
Return the best collected combination, running the corresponding result_func.
Definition at line 73 of file resistor_substitution_utils.cpp.
References m_best_found_resistance, and m_best_result_func.
Referenced by RES_EQUIV_CALC::calculate2RSolution(), RES_EQUIV_CALC::calculate3RSolution(), and RES_EQUIV_CALC::calculate4RSolution().
|
private |
Definition at line 103 of file resistor_substitution_utils.cpp.
Referenced by addSolution().
|
private |
Definition at line 104 of file resistor_substitution_utils.cpp.
Referenced by addSolution(), and GetBest().
|
private |
Definition at line 105 of file resistor_substitution_utils.cpp.
Referenced by addSolution(), and GetBest().
|
private |
Definition at line 102 of file resistor_substitution_utils.cpp.
Referenced by addSolution().