final int mid = middle(stick, x1, x2);  if (mid == 0) {
final int yMid = middle(stick, x1, x2); if (yMid == 0) {
    private static void patchSection (Stick stick,                                      List<GlyphSection> patches,                                      GlyphLag lag,                                      int minPointNb,                                      StickSection section,                                      StickSection sct,                                      int direction)    {        Run lineRun; // Run of staff line in contact        Run run; // Run to be extended        int yBegin; // y value at beginning of the extension        Line startTg = new VerticalLine(); // Tangent at runs starts        Line stopTg = new VerticalLine(); // Tangent at runs stops        Line axis = null; // Middle axis        int x1; // left and right abscissas        int x2; // left and right abscissas        double x; // Middle abscissa        if (direction > 0) { // Going downwards            run = sct.getLastRun();            lineRun = section.getFirstRun();            yBegin = section.getFirstPos();        } else {            run = sct.getFirstRun();            lineRun = section.getLastRun();            yBegin = section.getLastPos();        }        int length = run.getLength(); // Length of this contact run        // Use line portion instead if shorter        if (lineRun.getLength() < length) {            if (logger.isDebugEnabled()) {                logger.debug("line shorter than external contact");            }            startTg.include(lineRun.getStart(), yBegin);            stopTg.include(lineRun.getStop(), yBegin);            x1 = lineRun.getStart();            x2 = lineRun.getStop();            length = lineRun.getLength();        } else {            x1 = run.getStart();            x2 = run.getStop();        }        x = (double) (x1 + x2) / 2;        // Compute the y position where our patch should stop        final int mid = middle(stick, x1, x2);        if (mid == 0) {            logger.warning("Cannot find line");            return;        }        final int yPast = mid + direction; // y value, past the last one        // Try to compute on a total of minPointNb points        if ((startTg.getPointNb() + sct.getRunNb()) >= minPointNb) {            int y = yBegin;            while (startTg.getPointNb() < minPointNb) {                y -= direction;                Run r = sct.getRunAt(y);                startTg.include(r.getStart(), y);                stopTg.include(r.getStop(), y);            }        }        // Check whether we have enough runs to compute extension axis        if (startTg.getPointNb() >= minPointNb) {            // Check that we don't diverge (convergence to the line is OK)            if (((stopTg.getSlope() - startTg.getSlope()) * direction) > constants.maxDeltaSlope                    .getValue()) {                axis = startTg.include(stopTg); // Merge the two sides                startTg = stopTg = null;            }        } else {            // No way to compute an axis, just use straight direction            axis = startTg = stopTg = null;        }        // Extend the section, using whatever line(s) we have :        // With startTg & stopTg : we use both directions        // With just axis, we use a constant length in the axis direction        // With nothing, we use a constant length in the y direction        GlyphSection newSct = null;        // Sanity check        if (((yPast - yBegin) * direction) <= 0) {            logger.debug("Weird relative positions yBegin=" + yBegin                         + " yPast=" + yPast + " dir=" + direction);            logger.debug("patchSection line=" + section);            logger.debug("patchSection contact=" + sct);        } else {            for (int y = yBegin; y != yPast; y += direction) {                int start;                if (startTg != null) {                    start = startTg.xAt(y);                    length = stopTg.xAt(y) - start + 1;                    if (length <= 0) { // We have decreased to nothing                        break;                    }                } else {                    if (axis != null) {                        x = axis.xAt((double) y);                    }                    start = (int) Math.rint(x - ((double) length / 2) + 0.5);                }                //Run newRun = new Run(start, length, Picture.FOREGROUND); // TBD                Run newRun = new Run(start, length, 127); // TBD for the 127 value of course                if (newSct == null) {                    newSct = lag.createSection(y, newRun);                    // Make the proper junction                    if (direction > 0) {                        StickSection.addEdge(sct, newSct);                    } else {                        StickSection.addEdge(newSct, sct);                    }                    patches.add(newSct);                } else {                    // extend newSct in proper direction                    if (direction > 0) {                        newSct.append(newRun);                    } else {                        newSct.prepend(newRun);                    }                }            }            // Update potential lagviews on the lag            if (newSct != null) {                for (DigraphView graphView : lag.getViews()) {                    GlyphLagView lagView = (GlyphLagView) graphView;                    lagView.addSectionView(newSct);                }            }        }    }