count[UP] = count[DOWN] = 0;
Direction d = DOWN;
- Direction beamdir;
for (int i=0; i <stems_.size (); i++)
do {
Stem *s = stems_[i];
If dir is not determined: up (see stem::get_default_dir ())
*/
+ Direction beam_dir;
+ Direction neutral_dir = (int)paper_l ()->get_var ("stem_default_neutral_direction");
+
Dir_algorithm a = (Dir_algorithm)rint(paper_l ()->get_var ("beam_dir_algorithm"));
switch (a)
{
case MAJORITY:
- beamdir = (count[UP] >= count[DOWN]) ? UP : DOWN;
+ beam_dir = (count[UP] == count[DOWN]) ? neutral_dir
+ : (count[UP] > count[DOWN]) ? UP : DOWN;
break;
case MEAN:
// mean center distance
- beamdir = (total[UP] >= total[DOWN]) ? UP : DOWN;
+ beam_dir = (total[UP] == total[DOWN]) ? neutral_dir
+ : (total[UP] > total[DOWN]) ? UP : DOWN;
break;
default:
case MEDIAN:
// median center distance
- if (!count[DOWN])
- beamdir = UP;
- if (!count[UP])
- beamdir = DOWN;
+ if (!count[DOWN] || !count[UP])
+ {
+ beam_dir = (count[UP] == count[DOWN]) ? neutral_dir
+ : (count[UP] > count[DOWN]) ? UP : DOWN;
+ }
else
- beamdir = (total[UP] / count[UP] >= total[DOWN] / count[DOWN]) ? UP : DOWN;
+ {
+ beam_dir = (total[UP] / count[UP] == total[DOWN] / count[DOWN])
+ ? neutral_dir
+ : (total[UP] / count[UP] > total[DOWN] / count[DOWN]) ? UP : DOWN;
+ }
break;
}
- return beamdir;
+ return beam_dir;
}
void