From 57fa3e44f475dfc39c24df59786ea0786d121dfa Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Wed, 21 Sep 2022 20:23:30 +0530 Subject: [PATCH] [Sketcher] [planegcs] Evaluate lower degree B-spline factors --- src/Mod/Sketcher/App/planegcs/Geo.cpp | 18 +++++++++--------- src/Mod/Sketcher/App/planegcs/Geo.h | 7 +++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Mod/Sketcher/App/planegcs/Geo.cpp b/src/Mod/Sketcher/App/planegcs/Geo.cpp index 74dbc6a7d0..acf1442d81 100644 --- a/src/Mod/Sketcher/App/planegcs/Geo.cpp +++ b/src/Mod/Sketcher/App/planegcs/Geo.cpp @@ -712,7 +712,7 @@ BSpline* BSpline::Copy() return crv; } -double BSpline::getLinCombFactor(double x, size_t k, size_t i) +double BSpline::getLinCombFactor(double x, size_t k, size_t i, size_t p) { // Adapted to C++ from the python implementation in the Wikipedia page for de Boor algorithm // https://en.wikipedia.org/wiki/De_Boor%27s_algorithm. @@ -727,23 +727,23 @@ double BSpline::getLinCombFactor(double x, size_t k, size_t i) if (flattenedknots.empty()) setupFlattenedKnots(); - std::vector d(degree + 1, 0.0); + std::vector d(p + 1, 0.0); // Ensure this is within range - int idxOfPole = static_cast(i) + degree - static_cast(k); - if (idxOfPole < 0 || idxOfPole > degree) + int idxOfPole = static_cast(i) + p - static_cast(k); + if (idxOfPole < 0 || idxOfPole > static_cast(p)) return 0.0; d[idxOfPole] = 1.0; - for (size_t r = 1; static_cast(r) < degree + 1; ++r) { - for (size_t j = degree; j > r - 1; --j) { + for (size_t r = 1; static_cast(r) < p + 1; ++r) { + for (size_t j = p; j > r - 1; --j) { double alpha = - (x - flattenedknots[j + k - degree]) / - (flattenedknots[j + 1 + k - r] - flattenedknots[j + k - degree]); + (x - flattenedknots[j + k - p]) / + (flattenedknots[j + 1 + k - r] - flattenedknots[j + k - p]); d[j] = (1.0 - alpha) * d[j-1] + alpha * d[j]; } } - return d[degree]; + return d[p]; } void BSpline::setupFlattenedKnots() diff --git a/src/Mod/Sketcher/App/planegcs/Geo.h b/src/Mod/Sketcher/App/planegcs/Geo.h index 13ad0d4969..8de749312a 100644 --- a/src/Mod/Sketcher/App/planegcs/Geo.h +++ b/src/Mod/Sketcher/App/planegcs/Geo.h @@ -300,10 +300,13 @@ namespace GCS void ReconstructOnNewPvec (VEC_pD &pvec, int &cnt) override; BSpline* Copy() override; /// finds the value B_i(x) such that spline(x) = sum(poles[i] * B_i(x)) - /// i is index of control point /// x is the point at which combination is needed /// k is the range in `flattenedknots` that contains x - double getLinCombFactor(double x, size_t k, size_t i); + /// i is index of control point + /// p is the degree + double getLinCombFactor(double x, size_t k, size_t i, size_t p); + inline double getLinCombFactor(double x, size_t k, size_t i) + { return getLinCombFactor(x, k, i, degree); } void setupFlattenedKnots(); };