Commit 766565d
committed
Find optimal shift value to decompose the spline
De Casteljau's algorithm is a common approach to rendering spline. There
are many studies that aim to improve the spline. Here, we only consider
three metrics to evaluate which method is more suitable. The first
metric is the number of generated points when rendering a curve. The
second metric is the number of '_de_casteljau' function calls. The third
metric is the computation cost of the '_de_casteljau' function.
In order to generate fewer points when rendering a curve, we first apply
a flexible update 't' that employs the bisection method to identify the
positions that are best suited for curve fitting. Most of these points
have maximum curvature on the segment. When we try to find the point at
which curvature is as maximum as possible, we will reduce the scope of
the unhandled segment of spline. Therefore, we can generate fewer points
while rendering an unhandled segment of spline. However, the drawback of
this method is the high cost of finding points and the high cost of the
bisection method.
Next, to solve the drawback mentioned above, we apply a flexible update
't' with early stopping, which aims to stop the call of the
'_de_casteljau' function. However, the improvement is little.
Based on the previous experiments, we can see that the root of the
problem is that there is a must to call '_de_casteljau' function twice
to generate a point even in the original setting, which has the most
fewer numbers of call '_de_casteljau'.
The ideal method is that the rendering process only needs to call
'_de_casteljau' once to generate a point. To achieve this goal, we
reduce the initial 't' from 0.5 to 0.25 because the average number of
'_de_casteljau' calls per point is 1.99. This means that the first call
of the function '_de_casteljau' is redundant. In the experiment, we can
see that the average points per character of the original method that
shift 2 is almost the same with the original method.
Experiment :
Use font-edit as the evaluation testbed to do experiments as follows:
Original - Average number of _de_casteljau calls per point: 1.99
Original - Average points per character: 18.89
Original (shift2) - Average number of _de_casteljau calls per point: 1.51
Original (shift2) - Average points per character: 18.98
Flexible - Average number of _de_casteljau calls per point: 4.53
Flexible - Average points per character: 16.30
Flexible (shift2) - Average number of _de_casteljau calls per point: 4.40
Flexible (shift2) - Average points per character: 21.16
Flexible (early stopping) - Average number of _de_casteljau calls per point: 4.23
Flexible (early stopping) - Average points per character: 16.18
Flexible (early stopping) (shift2) - Average number of _de_casteljau calls per point: 3.99
Flexible (early stopping) (shift2) - Average points per character: 21.09
After considering the computation cost of the '_de_casteljau' function
and the increase in average number of _de_casteljau calls per point, we
abandon the method flexible update 't' with the bisection method. Then,
Choose to apply the original method with shift 2 finally.
Take t = 0.25 for example (3/4) * A + (1/4) * B
Original: A + (B - A) >> 4
We can directly use (B - A) to get the coefficients 1/4 and 3/4.
Bisection: we need to multiply (B - A) with 0.25.
Also, the bisection has many possible values of t rather than the
original method. When using the original method, the '_de_casteljau'
function can all use shift operations because the t is always the power
of 2.1 parent 98a2579 commit 766565d
1 file changed
+26
-57
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 23 | + | |
| 24 | + | |
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
| 28 | + | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
34 | | - | |
| 32 | + | |
35 | 33 | | |
36 | 34 | | |
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
46 | 44 | | |
47 | 45 | | |
48 | 46 | | |
| |||
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | | - | |
| 65 | + | |
68 | 66 | | |
69 | | - | |
70 | | - | |
| 67 | + | |
| 68 | + | |
71 | 69 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
75 | 73 | | |
76 | 74 | | |
77 | 75 | | |
| |||
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
97 | | - | |
| 95 | + | |
98 | 96 | | |
99 | | - | |
100 | | - | |
101 | 97 | | |
102 | 98 | | |
103 | 99 | | |
104 | | - | |
105 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
106 | 104 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 105 | + | |
| 106 | + | |
136 | 107 | | |
137 | 108 | | |
138 | | - | |
139 | | - | |
140 | 109 | | |
141 | 110 | | |
142 | 111 | | |
| |||
0 commit comments