109 {
111 int balance_index;
112 int16_t balance_count;
113 int16_t r_index;
115 int32_t dist;
116 double sq_dist;
117 double mean;
118 double total;
119 double factor;
120
121 int16_t half_pitch = pitch / 2 - 1;
122 uint32_t lead_flag;
123
124 if (half_pitch > 31) {
125 half_pitch = 31;
126 } else if (half_pitch < 0) {
127 half_pitch = 0;
128 }
129 lead_flag = 1 << half_pitch;
130
131 back_balance = cutpts[
x - 1 - array_origin].back_balance << 1;
132 back_balance &= lead_flag + (lead_flag - 1);
133 if (projection->pile_count(
x) > zero_count) {
134 back_balance |= 1;
135 }
136 fwd_balance = cutpts[
x - 1 - array_origin].fwd_balance >> 1;
137 if (projection->pile_count(
x + half_pitch) > zero_count) {
138 fwd_balance |= lead_flag;
139 }
140
142 cost = FLT_MAX;
143 pred = nullptr;
146 region_index = 0;
148 for (
index =
x - pitch - pitch_error;
index <=
x - pitch + pitch_error;
index++) {
149 if (
index >= array_origin) {
150 segpt = &cutpts[
index - array_origin];
151 dist =
x - segpt->xpos;
152 if (!segpt->terminal && segpt->fake_count < INT16_MAX) {
153 balance_count = 0;
156 lead_flag = back_balance ^ segpt->fwd_balance;
157 balance_count = 0;
158 while (lead_flag != 0) {
159 balance_count++;
160 lead_flag &= lead_flag - 1;
161 }
162 } else {
163 for (balance_index = 0;
index + balance_index <
x - balance_index; balance_index++) {
164 balance_count += (projection->pile_count(
index + balance_index) <= zero_count) ^
165 (projection->pile_count(
x - balance_index) <= zero_count);
166 }
167 }
168 balance_count =
170 }
171 r_index = segpt->region_index + 1;
172 total = segpt->mean_sum + dist;
173 balance_count += offset;
174 sq_dist = dist * dist + segpt->sq_sum + balance_count * balance_count;
175 mean = total / r_index;
176 factor = mean - pitch;
177 factor *= factor;
178 factor += sq_dist / (r_index)-mean * mean;
180 cost = factor;
181 pred = segpt;
182 mean_sum = total;
183 sq_sum = sq_dist;
185 mid_cuts = segpt->mid_cuts + mid_cut;
186 region_index = r_index;
187 }
188 }
189 }
190 }
191}
double textord_balance_factor
bool textord_fast_pitch_test