49 distCfMode_ = _distCfMode;
50 distRelFuncIdx_ = _distRelFuncIdx;
56 distLinkedFuncIdx_.resize(1, _distRelFuncIdx[0]);
57 distEvalCache_.resize(funcCtrlPt_[_distRelFuncIdx[0]].size(), 0);
60 distLinkedArcIdx_ = func2Arc_[_distRelFuncIdx[0]];
63 distLinkedFuncIdx_.resize(1, _distRelFuncIdx[0]);
64 distEvalCache_.resize(funcCtrlPt_[_distRelFuncIdx[0]].size(), 0);
67 distLinkedArcIdx_ = func2Arc_[_distRelFuncIdx[0]];
79 ParamFuncsDist::operator=(_other);
84 void ParamFuncsSpline0Dist::precomputeDist()
86 if (distCfMode_ == TDM::NONE)
91 const size_t& func0Idx = distLinkedFuncIdx_[0];
92 const size_t ctrlPtSize = funcCtrlPt_[func0Idx].size() - 1;
93 distEvalCache_[0] = 0;
94 for (
size_t funcCtrlPtIdx = 0; funcCtrlPtIdx < ctrlPtSize; ++funcCtrlPtIdx)
96 funcsArcEval_ = ctrlPtVal(func0Idx, funcCtrlPtIdx + 1, CtrlPtDim::ARC);
97 funcEvalArcCacheIdxUnder_[distLinkedArcIdx_] = funcCtrlPtIdx;
98 distEvalCache_[funcCtrlPtIdx + 1] = computeS();
100 setEvalArc(funcsArcBegin_, EvalArcGuarantee::AT_BEGIN);
103 double ParamFuncsSpline0Dist::computeS()
const 105 return (this->*computeSFuncPtr_)();
107 double ParamFuncsSpline0Dist::computeS_V()
const 109 const size_t& funcIdx = distLinkedFuncIdx_[0];
111 funcEvalCache_[funcIdx][funcEvalArcCacheIdxUnder_[func2Arc_[funcIdx]]];
112 return distEvalCache_[funcEvalArcCacheIdxUnder_[distLinkedArcIdx_]] +
113 computeDeltaS_V_AV(funcsArcEval_ - cacheData.
arc, cacheData.
val, computeFuncDiff1(funcIdx));
116 double ParamFuncsSpline0Dist::computeS_AV()
const 118 const size_t& funcIdx = distLinkedFuncIdx_[0];
120 funcEvalCache_[funcIdx][funcEvalArcCacheIdxUnder_[func2Arc_[funcIdx]]];
121 return distEvalCache_[funcEvalArcCacheIdxUnder_[distLinkedArcIdx_]] +
122 computeDeltaS_V_AV(funcsArcEval_ - cacheData.
arc, computeFuncInt1(funcIdx), cacheData.
val);
125 void ParamFuncsSpline0Dist::computeS2TLattice(
const double& _arc0,
const double& _ds, vector<double>& _tLattice)
127 setEvalArc(_arc0, EvalArcGuarantee::NONE);
128 size_t iEnd = distEvalCache_.back() / _ds;
129 if (((
double)iEnd < distEvalCache_.back() / _ds))
134 _tLattice.reserve(iEnd + 2);
135 const int idxBeforeStart =
static_cast<int>(computeS() / _ds);
137 setEvalDist(_ds * (idxBeforeStart), EvalArcGuarantee::AFTER_LAST);
138 _tLattice.emplace_back(fmin(funcsArcEval_, funcsArcEnd_));
139 for (
size_t i = idxBeforeStart + 1; i < iEnd; ++i)
141 setEvalDist(_ds * (i), EvalArcGuarantee::AFTER_LAST);
142 _tLattice.emplace_back(
143 fmin(fmax(funcsArcEval_, nextafterf(_tLattice.back(), FLT_MAX)), nextafterf(funcsArcEnd_, -FLT_MAX)));
145 if (_tLattice.back() < funcsArcEnd_)
147 _tLattice.emplace_back(funcsArcEnd_);
149 setEvalArc(funcsArcBegin_, EvalArcGuarantee::AT_BEGIN);
152 void ParamFuncsSpline0Dist::computeS2TLattice(
const vector<double>& _sLattice, vector<double>& _tLattice)
154 const size_t slSize = _sLattice.size();
156 _tLattice.reserve(_sLattice.size());
161 setEvalDist(_sLattice[i], EvalArcGuarantee::NONE);
162 while ((funcsArcEval_ < funcsArcEnd_) && (i + 1 < slSize))
164 _tLattice.emplace_back(funcsArcEval_);
165 setEvalDist(_sLattice[++i], EvalArcGuarantee::AFTER_LAST);
168 _tLattice.emplace_back(funcsArcEnd_);
169 setEvalArc(funcsArcBegin_, EvalArcGuarantee::AT_BEGIN);
171 void ParamFuncsSpline0Dist::setEvalDist(
const double& _funcsDistEval,
const EvalArcGuarantee& _evalArcGuarantee)
173 setEvalArc(computeTImpl(_funcsDistEval, _evalArcGuarantee), _evalArcGuarantee);
176 double ParamFuncsSpline0Dist::computeT(
const double& _s,
const EvalArcGuarantee& _evalArcGuarantee)
178 size_t& arcIdx = funcEvalArcCacheIdxUnder_[distLinkedArcIdx_];
180 const size_t cacheCtrlPtIdxRestore = arcIdx;
181 const size_t cacheArcEvalRestore = funcsArcEval_;
183 double resultT = computeTImpl(_s, _evalArcGuarantee);
185 arcIdx = cacheCtrlPtIdxRestore;
186 funcsArcEval_ = cacheArcEvalRestore;
191 double ParamFuncsSpline0Dist::computeTImpl(
const double& _s,
const EvalArcGuarantee& _evalArcGuarantee)
194 size_t& arcCacheIdx = funcEvalArcCacheIdxUnder_[distLinkedArcIdx_];
195 const size_t ctrlPtSize = funcCtrlPt_[distLinkedFuncIdx_[0]].size();
197 switch (_evalArcGuarantee)
199 case eag::AFTER_LAST:
200 while (distEvalCache_[arcCacheIdx] <= _s)
202 if (++arcCacheIdx >= ctrlPtSize)
213 arcCacheIdx = funcCtrlPt_[distLinkedFuncIdx_[0]].size() - 1;
216 arcCacheIdx = distance(distEvalCache_.begin(), upper_bound(distEvalCache_.begin(), distEvalCache_.end(), _s)) - 1;
218 case eag::BEFORE_LAST:
219 while (distEvalCache_[arcCacheIdx] > _s)
221 if (arcCacheIdx == 0)
229 funcsArcEval_ = ctrlPtVal(distLinkedFuncIdx_[0], arcCacheIdx, CtrlPtDim::ARC);
230 const double ds = _s - distEvalCache_[arcCacheIdx];
231 const double retVal = funcsArcEval_ + (this->*computeDs2DtPtr_)(ds);
234 double ParamFuncsSpline0Dist::computeT_V(
const double& _ds)
const 236 const size_t& funcIdx = distLinkedFuncIdx_[0];
237 return computeDeltaT_V_AV(_ds, computeFuncVal(funcIdx), computeFuncDiff1(funcIdx));
239 double ParamFuncsSpline0Dist::computeT_AV(
const double& _ds)
const 241 const size_t& funcIdx = distLinkedFuncIdx_[0];
242 return computeDeltaT_V_AV(_ds, computeFuncInt1(funcIdx), computeFuncVal(funcIdx));
245 double ParamFuncsSpline0Dist::computeDeltaS_V_AV(
const double& _dt,
const double& _v0,
const double& _av)
247 const double dtAbs = fabs(_dt);
248 if (dtAbs < 10 * FLT_MIN)
252 const double vAbs = fabs(_v0);
253 if (fabs(_av) < 10 * FLT_MIN)
257 const double v1 = _v0 + _av * dtAbs;
260 return fabs(_v0 + v1) * _dt / 2.;
269 double dt1 = -_v0 / _av;
270 return retSign * (vAbs * dt1 + fabs(v1) * (dtAbs - dt1)) / 2.;
273 double ParamFuncsSpline0Dist::computeDeltaT_V_AV(
const double& _ds,
const double& _v0,
const double& _av)
275 double v0 = _v0, av = _av;
281 if (fabs(av) < 10 * FLT_MIN)
291 const double v0v0 = v0 * v0;
293 double delta = v0v0 + 2. * av * fabs(_ds);
296 return retSign * (+v0 + sqrt(-delta)) / av;
300 return retSign * (+v0 - sqrt(delta)) / av;
TraveledDistCfMode distCfMode_
Closed form distance computation mode.
TraveledDistCfMode
Required type of traveled distance computation relative to the parametric function.
double computeS_V() const
Computes distance on a piecewise linear function describing the center linear velocity.
void setDistCfMode(TraveledDistCfMode _distCfMode, const std::vector< std::size_t > &_distRelFuncIdx) override
double computeT_V(const double &_ds) const
Computes arc parametrization on a piecewise linear function describing the center linear velocity at ...
Helper function needed to upgrade c++ 2011.
double computeT_AV(const double &_ds) const
Computes arc parametrization on a piecewise linear function describing the center linear acceleration...
EvalArcGuarantee
Flags if any guarantees about evaluation arc relative to last evaluation arc are present.
agent base center linear velocity is parametric function
agent base center linear acceleration is parametric function
ParamFuncsSpline0Dist::TraveledDistCfMode TDM
EvalArcGuarantee
Flags if any guarantees about evaluation arc relative to last evaluation arc are present.
Extends manipulation of parametric functions collection with closed-form arc length (distance) comput...
constexpr int signum(T x, std::false_type is_signed)
ParamFuncsSpline0Dist()=default
double computeS_AV() const
Computes distance on a piecewise linear function describing the center linear acceleration.
std::vector< std::size_t > distRelFuncIdx_