Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
OneUnknownSolver.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
5struct ObjectData;
6
7template<typename InputT, typename OutputT>
9public:
10 using ParamSetter = std::function<void(InputT)>; // Sets the value for the unknown parameter we are solving for
11 using SimulationRun = std::function<bool()>; // Runs the simulation up until a stop condition is reached
12 using ResultExtractor = std::function<OutputT()>; // Gets a value to compare to the target value after an iteration
13
14 OneUnknownSolver(ParamSetter setParameter,
15 SimulationRun runSimulation,
16 ResultExtractor extractResult,
17 OutputT target,
18 OutputT tolerance = static_cast<OutputT>(0.001),
19 int maxIterations = 30);
20
21 bool stepFrame();
22
23 InputT current;
24private:
25 bool intervalFound = false;
26 float delta = 0.5f;
27 int expandIterations = 0;
28 OutputT prevError{};
29
30 ParamSetter setParam;
31 SimulationRun runSim;
32 ResultExtractor extract;
33
34 OutputT target;
35 InputT high{};
36 InputT low{};
37 OutputT tolerance;
38};
std::function< OutputT()> ResultExtractor
std::function< void(InputT)> ParamSetter
std::function< bool()> SimulationRun