/* Last edited on 2013-03-23 17:32:20 by stolfilocal */ /* Representation for a word candidate made out of character boxes. */ package minetto.utils; import java.lang.Math; import java.lang.Float; import java.util.Arrays; import minetto.utils.WordCandElem; public final class WordCand { /* === REPRESENTATION =========================================== */ public WordCandElem[] els; /* Characters in word. */ public double score; /* Log of true/false probability ratio. */ /* The probabilities are computed assuming that the box coordinates {.xmin,.xmax,.ymin,.ymax} and the guessed {y} coordinates of the reference points have the same quantization error variance {V}, namely that of a uniform {[-1/2 _ +1/2]} distribution. */ /* === CONSTRUCTORS =========================================== */ /* ---------------------------------------------------------------------- Creates a new word candidate with the elements in {els} (if not null) followed by the single element {L} (if not null). The probabilties {.ptrue,.pfalse} and the score are left undefined. */ public WordCand (WordCandElem[] els, WordCandElem L) { int nel = (els == null ? 0 : els.length); if (L != null) { nel++; } this.els = (els == null ? new WordCandElem[nel] : java.util.Arrays.copyOf(els, nel)); this.els[nel-1] = L; this.score = Double.NaN; } /* === PUBLIC METHODS =============================================== */ /* ---------------------------------------------------------------------- Compute the enclosing bounding box: */ public int[][] bounding_box() { assert this.els.length > 0; int[][] box = null; for (int iel = 0; iel < this.els.length; iel++) { WordCandElem Li = this.els[iel]; if (iel == 0) { box = new int[][]{{ Li.box[0][0], Li.box[0][1] }, { Li.box[1][0], Li.box[1][1] }}; } else { for (int iax = 0; iax < 2; iax++) { if (box[iax][0] > Li.box[iax][0]) { box[iax][0] = Li.box[iax][0]; } if (box[iax][1] < Li.box[iax][1]) { box[iax][1] = Li.box[iax][1]; } } } } return box; } }