2
0
Fork 0
OB-Xd/Modules/gin/utilities/integrator.cpp

46 lines
922 B
C++
Executable File

/*==============================================================================
Copyright 2018 by Roland Rabien
For more information visit www.rabiensoftware.com
==============================================================================*/
void Integrator::clear()
{
first = true;
curSum = 0;
oldX = 0;
oldY = 0;
}
double Integrator::getIntegral()
{
return curSum;
}
void Integrator::addPoint (double x, double y)
{
if (first)
{
first = false;
}
else
{
double curY = (oldY + y) / 2.0;
curSum += curY * (x - oldX);
}
oldX = x;
oldY = y;
}
void Integrator::addPoint (juce::Point<double> point)
{
addPoint (point.getX(), point.getY());
}
void Integrator::addPoints (Array<juce::Point<double>> points)
{
for (auto point : points)
addPoint (point.getX(), point.getY());
}