-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinearcurveevaluator.cpp
48 lines (39 loc) · 1.29 KB
/
linearcurveevaluator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "LinearCurveEvaluator.h"
#include <assert.h>
void LinearCurveEvaluator::evaluateCurve(const std::vector<Point>& ptvCtrlPts,
std::vector<Point>& ptvEvaluatedCurvePts,
const float& fAniLength,
const bool& bWrap, const bool& bAdaptive,
const double& dTension) const
{
int iCtrlPtCount = ptvCtrlPts.size();
ptvEvaluatedCurvePts.assign(ptvCtrlPts.begin(), ptvCtrlPts.end());
float x = 0.0;
float y1;
if (bWrap) {
// if wrapping is on, interpolate the y value at xmin and
// xmax so that the slopes of the lines adjacent to the
// wraparound are equal.
if ((ptvCtrlPts[0].x + fAniLength) - ptvCtrlPts[iCtrlPtCount - 1].x > 0.0f) {
y1 = (ptvCtrlPts[0].y * (fAniLength - ptvCtrlPts[iCtrlPtCount - 1].x) +
ptvCtrlPts[iCtrlPtCount - 1].y * ptvCtrlPts[0].x) /
(ptvCtrlPts[0].x + fAniLength - ptvCtrlPts[iCtrlPtCount - 1].x);
}
else
y1 = ptvCtrlPts[0].y;
}
else {
// if wrapping is off, make the first and last segments of
// the curve horizontal.
y1 = ptvCtrlPts[0].y;
}
ptvEvaluatedCurvePts.push_back(Point(x, y1));
/// set the endpoint based on the wrap flag.
float y2;
x = fAniLength;
if (bWrap)
y2 = y1;
else
y2 = ptvCtrlPts[iCtrlPtCount - 1].y;
ptvEvaluatedCurvePts.push_back(Point(x, y2));
}