Skip to content

Commit 98a2579

Browse files
committed
Add the early stopping in _twin_spline_decompose
Take the right half of the spline as another standard when finding the optimal t. Because if the right half of the spline is also within the tolerance, the right half of the spline will be the last curve segment. Thus, in this case, there is no need to find better t, which aims to prevent more line segments from being generated in the future. I have modified the implementation of font-edit to use fixed-point arithmetic and used it 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 flexibly update - Average number of _de_casteljau calls per point: 4.53 flexibly update - Average points per character: 16.30 flexibly update (early stopping)- Average number of _de_casteljau calls per point: 4.23 flexibly update (early stopping)- Average points per character: 16.18
1 parent 01bb810 commit 98a2579

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/spline.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void _twin_spline_decompose(twin_path_t *path,
9797

9898
while (!is_flat(spline, tolerance_squared)) {
9999
twin_dfixed_t hi = TWIN_SFIXED_ONE * TWIN_SFIXED_ONE, lo = 0,
100-
t_optimal = 0, t, max_distance = 0, distance;
100+
t_optimal = 0, t, max_distance = 0, left_dist, right_dist;
101101
twin_spline_t left, right;
102102

103103
while (true) {
@@ -107,14 +107,15 @@ static void _twin_spline_decompose(twin_path_t *path,
107107

108108
_de_casteljau(spline, t, &left, &right);
109109

110-
distance = _twin_spline_distance_squared(&left);
111-
if (distance < max_distance)
112-
break;
110+
left_dist = _twin_spline_distance_squared(&left);
111+
right_dist = _twin_spline_distance_squared(&right);
113112

114113
/* The left segment is close enough to fit the original spline. */
115-
if (distance <= tolerance_squared) {
116-
max_distance = distance;
114+
if (left_dist <= tolerance_squared) {
115+
max_distance = left_dist;
117116
t_optimal = t;
117+
if (right_dist <= tolerance_squared)
118+
break;
118119
/*
119120
* Try to find a better point such that the line segment
120121
* connecting it to the previous point can fit the spline, while

0 commit comments

Comments
 (0)