Skip to content

Commit c2cb237

Browse files
committed
Made Bezier code slightly more easy to read
1 parent 72ca3c8 commit c2cb237

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/DrawingCallback.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,27 @@ void DrawingCallback::line_to(Vector2d to)
9595
pen = to;
9696
}
9797

98+
// Quadric Bezier curve
9899
void DrawingCallback::curve_to(Vector2d c1, Vector2d to)
99100
{
100101
for (unsigned long idx = 1;idx <= fn;idx++) {
101102
const double a = idx * (1.0 / (double)fn);
102-
const double x = pen[0] * t(a, 2) + c1[0] * 2 * t(a, 1) * a + to[0] * a * a;
103-
const double y = pen[1] * t(a, 2) + c1[1] * 2 * t(a, 1) * a + to[1] * a * a;
104-
add_vertex(Vector2d(x, y));
103+
add_vertex(pen * pow(1-a, 2) +
104+
c1 * 2 * pow(1-a, 1) * a +
105+
to * pow(a, 2));
105106
}
106107
pen = to;
107108
}
108109

110+
// Cubic Bezier curve
109111
void DrawingCallback::curve_to(Vector2d c1, Vector2d c2, Vector2d to)
110112
{
111113
for (unsigned long idx = 1;idx <= fn;idx++) {
112114
const double a = idx * (1.0 / (double)fn);
113-
const double x = pen[0] * t(a, 3) + c1[0] * 3 * t(a, 2) * a + c2[0] * 3 * t(a, 1) * a * a + to[0] * a * a * a;
114-
const double y = pen[1] * t(a, 3) + c1[1] * 3 * t(a, 2) * a + c2[1] * 3 * t(a, 1) * a * a + to[1] * a * a * a;
115-
add_vertex(Vector2d(x, y));
115+
add_vertex(pen * pow(1-a, 3) +
116+
c1 * 3 * pow(1-a, 2) * a +
117+
c2 * 3 * pow(1-a, 1) * pow(a, 2) +
118+
to * pow(a, 3));
116119
}
117120
pen = to;
118121
}

src/DrawingCallback.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,4 @@ class DrawingCallback {
5656
std::vector<const class Geometry *> polygons;
5757

5858
void add_vertex(Vector2d v);
59-
60-
inline double t(double t, int exp) const {
61-
return pow(1.0 - t, exp);
62-
}
6359
};

0 commit comments

Comments
 (0)