5#include <Common/assertion.h>
33 T
evaluate(T x, std::size_t p0Index, std::size_t p1Index)
const;
46 std::vector<TVector2<T>> m_points;
63 if (x <= m_points.front().x())
return m_points.front().y();
64 else if(x >= m_points.back().x())
return m_points.back().y();
66 const auto& result = std::lower_bound(m_points.begin(), m_points.end(),
TVector2<T>(x),
67 &TPiecewiseLinear1D::pointDomainComparator);
68 PH_ASSERT(result != m_points.begin() && result != m_points.end());
69 const std::size_t i1 = result - m_points.begin();
70 const std::size_t i0 = i1 - 1;
72 return evaluate(x, i0, i1);
77 const std::size_t p0Index,
78 const std::size_t p1Index)
const
80 PH_ASSERT(p0Index < m_points.size() && p1Index < m_points.size());
84 return p0.
x() != p1.
x() ? (x - p0.
x()) / (p1.
x() - p0.
x()) * (p1.
y() - p0.
y()) + p0.
y()
85 : (p0.
y() + p1.
y()) / 2;
91 std::stable_sort(m_points.begin(), m_points.end(),
92 &TPiecewiseLinear1D::pointDomainComparator);
98 m_points.push_back(point);
104 m_points.insert(std::end(m_points),
105 std::begin(points.m_points), std::end(points.m_points));
112 for(
const auto& point : m_points)
114 mirrored.
addPoint({
static_cast<T
>(2) * pivotX - point.x(), point.y()});
123 return m_points.size();
129 return m_points[pointIndex];
135 std::string result(
"piecewise linear function, composed of following points: ");
136 for(
const auto& point : m_points)
138 result += point.toString();
147 return pA.
x() < pB.
x();
Definition TPiecewiseLinear1D.h:26
TPiecewiseLinear1D getMirrored(T pivotX) const
Definition TPiecewiseLinear1D.h:109
TVector2< T > getPoint(std::size_t pointIndex) const
Definition TPiecewiseLinear1D.h:127
std::size_t numPoints() const
Definition TPiecewiseLinear1D.h:121
T evaluate(T x) const
Definition TPiecewiseLinear1D.h:54
void addPoint(const TVector2< T > &point)
Definition TPiecewiseLinear1D.h:96
std::string toString() const
Definition TPiecewiseLinear1D.h:133
void update()
Definition TPiecewiseLinear1D.h:89
void addPoints(const TPiecewiseLinear1D &points)
Definition TPiecewiseLinear1D.h:102
Represents a 2-D vector.
Definition TVector2.h:19
T & x()
Definition TVector2.ipp:38
T & y()
Definition TVector2.ipp:44
Math functions and utilities.
Definition TransformInfo.h:10