Skip to content

Commit

Permalink
Refactored binarySearch function out of PointCurve class.
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMaas1978 committed Jun 19, 2024
1 parent 291d778 commit 00df5ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
4 changes: 4 additions & 0 deletions FECore/FELoadCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ FELoadCurve::FELoadCurve(FEModel* fem) : FELoadController(fem)
FELoadCurve::FELoadCurve(const FELoadCurve& lc) : FELoadController(lc)
{
m_fnc = lc.m_fnc;
m_int = lc.m_int;
m_ext = lc.m_ext;
}

void FELoadCurve::operator = (const FELoadCurve& lc)
{
m_fnc = lc.m_fnc;
m_int = lc.m_int;
m_ext = lc.m_ext;
}

FELoadCurve::~FELoadCurve()
Expand Down
34 changes: 17 additions & 17 deletions FECore/PointCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ SOFTWARE.*/
#define min(a,b) ((a)<(b)?(a):(b))
#endif

size_t binarySearch(const std::vector<vec2d>& points, double x)
{
size_t N = points.size();
size_t low = 0;
size_t high = N - 1;
// Repeat until the pointers low and high meet each other
while (low <= high) {
size_t mid = low + (high - low) / 2;

if (points[mid].x() <= x)
low = mid + 1;
else
high = mid - 1;
}
return low;
}

class PointCurve::Imp
{
public:
Expand Down Expand Up @@ -817,20 +834,3 @@ bool PointCurve::Update()
}
return bvalid;
}

size_t PointCurve::binarySearch(std::vector<vec2d> points, double x) const
{
size_t N = points.size();
size_t low = 0;
size_t high = N-1;
// Repeat until the pointers low and high meet each other
while (low <= high) {
size_t mid = low + (high - low) / 2;

if (points[mid].x() <= x)
low = mid + 1;
else
high = mid - 1;
}
return low;
}
3 changes: 0 additions & 3 deletions FECore/PointCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ class FECORE_API PointCurve
void Scale(double s);

public:
//! returns the point interval in which x lies
size_t binarySearch(std::vector<vec2d> points, double x) const;

//! returns the value of the load curve at time
double value(double x) const;

Expand Down

0 comments on commit 00df5ac

Please sign in to comment.