org.extex.typesetter
Class Badness

java.lang.Object
  extended by org.extex.typesetter.Badness

public final class Badness
extends java.lang.Object

This class provides some static methods to deal with badness values.

Version:
$Revision$
Author:
Gerd Neugebauer

Field Summary
static int EJECT_PENALTY
          The constant EJECT_PENALTY contains the penalty which forces a line break.
static int INF_BAD
          The constant INF_BAD contains the value for infinite badness.
static int INF_PENALTY
          The constant INF_BAD contains the value for infinite penalty.
 
Method Summary
static int badness(long total, long sum)
          Compute the badness.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EJECT_PENALTY

public static final int EJECT_PENALTY
The constant EJECT_PENALTY contains the penalty which forces a line break. This is an equivalent to -∞.

See Also:
Constant Field Values

INF_BAD

public static final int INF_BAD
The constant INF_BAD contains the value for infinite badness. This is an equivalent to ∞.

See Also:
"TTP [108]", Constant Field Values

INF_PENALTY

public static final int INF_PENALTY
The constant INF_BAD contains the value for infinite penalty. This is an equivalent to ∞.

See Also:
Constant Field Values
Method Detail

badness

public static int badness(long total,
                          long sum)
Compute the badness.

108. The next subroutine is used to compute the badness of glue, when a total t is supposed to be made from amounts that sum to s. According to The TeXbook, the badness of this situation is 100(t/s)3; however, badness is simply a heuristic, so we need not squeeze out the last drop of accuracy when computing it. All we really want is an approximation that has similar properties.

The actual method used to compute the badness is easier to read from the program than to describe in words. It produces an integer value that is a reasonably close approximation to 100(t/s)3, and all implementations of TeX should use precisely this method. Any badness of 213 or more is treated as infinitely bad, and represented by 10000.

It is not difficult to prove that

badness(t+1,s) ≥ badness(t,s) ≥ badness(t,s+1).

The badness function defined here is capable of computing at most 1095 distinct values, but that is plenty.

 define inf_bad=10000 {infinitely bad value}
 
   function badness(t,s:scaled): halfword; {compute badness, given t ≥ 0}
    var r: integer; {approximation to αt/s, where α3 ≈ 100⋅218}
  begin if t=0 then badness ← 0
    else if s ≤ 0 then badness ← inf_bad
     else begin if t ≤ 7230584 then r ← (t * 297) div s {2973 = 99.94 × 218}
      else if s ≥ 1663497 then r ← t div (s div 297)
       else r ← t;
     if r>1290 then badness ← inf_bad {12903<231<12913}
      else badness ← (r*r*r+'400000) div '1000000;
     end ; {that was r3/218, rounded to the nearest integer}
  end ;
 

Parameters:
total - total given total >= 0
sum - sum
Returns:
the computed badness
See Also:
"TTP [108]"