Debian Codegraph @

avogadro/rendering/beziergeometry.cpp

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #include "beziergeometry.h"
7
8 namespace Avogadro::Rendering {
9
10 BezierGeometry::BezierGeometry() : CurveGeometry() {}
11
12 Vector3f BezierGeometry::computeCurvePoint(
13 float t, const std::list<Point*>& points) const
14 {
15 Vector3f h = Vector3f::Ones();
16 float u = 1.0f - t;
17 float n1 = points.size();
18 float w = 1.0f / n1;
19 float k = 0.0f;
20 Vector3f Q(w, w, w);
21 for (const auto& p : points) {
22 for (size_t i = 0; i < 3; ++i) {
23 h[i] = h[i] * t * (n1 - k) * w;
24 h[i] = h[i] / (k * u * w + h[i]);
25 Q[i] = (1.0f - h[i]) * Q[i] + h[i] * p->pos[i];
26 }
27 k += 1.0f;
28 }
29 return Q;
30 }
31
32 } // namespace Avogadro::Rendering