45 lines
922 B
C++
Executable file
45 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());
|
|
}
|