start = (int) Math.rint(x - ((double) length / 2));
start = (int) (0.5 + x - ((double) length / 2));
    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 BasicLine(); // Vertical tangent at runs starts        Line stopTg = new BasicLine();  // Vertical tangent at runs stops        Line axis = new BasicLine();    // Middle axis        int x1;                    // Left abscissa        int x2;                    // Right abscissa        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.isFineEnabled()) {                logger.fine("line shorter than external contact");            }            x1 = lineRun.getStart();            x2 = lineRun.getStop();            length = lineRun.getLength();            startTg.includePoint(x1, yBegin);            stopTg.includePoint(x2, yBegin);        } else {            x1 = run.getStart();            x2 = run.getStop();        }        x = (double) (x1 + x2) / 2;        if( logger.isFineEnabled()) {            logger.fine("x1=" + x1 + " x=" + x + " x2=" + x2);        }        ////axis.includePoint(x, yBegin);        // Compute the y position where our patch should stop        final int yMid = middle(stick, x1, x2);        if (yMid == 0) {            logger.warning("Cannot find line");            return;        }        final int yPast = yMid + direction; // y value, past the last one        // Try to compute tangents on a total of minPointNb points        if ((startTg.getNumberOfPoints() + sct.getRunNb()) >= minPointNb +1) {            int y = yBegin - direction; // Skip the run stuck to the line            while (startTg.getNumberOfPoints() < minPointNb) {                y -= direction;                Run r = sct.getRunAt(y);                if( logger.isFineEnabled()) {                    logger.fine("y=" + y +                                 " xl=" + r.getStart() +                                 " x=" + (double) (r.getStart() + r.getStop())/2 +                                 " xr=" + r.getStop());                }                startTg.includePoint(r.getStart(), y);                stopTg.includePoint(r.getStop(), y);                axis.includePoint((double) (r.getStart() + r.getStop())/2, y);            }        }        // Check whether we have enough runs to compute extension axis        if (startTg.getNumberOfPoints() >= minPointNb) {            if (logger.isFineEnabled()) {                logger.fine("startTg=" + startTg + " invertedSlope=" + startTg.getInvertedSlope());                logger.fine("axis=" + axis + " invertedSlope=" + axis.getInvertedSlope());                logger.fine("stopTg=" + stopTg + " invertedSlope=" + stopTg.getInvertedSlope());            }            // Check that we don't diverge (convergence to the line is OK)            if (((stopTg.getInvertedSlope() - startTg.getInvertedSlope())                 * direction) > constants.maxDeltaSlope.getValue()) {                /////axis = startTg.includeLine(stopTg); // Merge the two sides                startTg = stopTg = null;                if (logger.isFineEnabled()) {                    logger.fine("Merged. Axis=" + axis);                }            }        } 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.fine("Weird relative positions yBegin=" + yBegin                         + " yPast=" + yPast + " dir=" + direction);            logger.fine("patchSection line=" + section);            logger.fine("patchSection contact=" + sct);        } else {            for (int y = yBegin; y != yPast; y += direction) {                int start = -1;                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(y);                    }                    start = (int) Math.rint(x - ((double) length / 2));                }                if (logger.isFineEnabled()) {                    logger.fine("y=" + y + ", start=" + start + ", length=" + length);                }                //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);                    }                }                if (logger.isFineEnabled()) {                    logger.fine("newSct=" + newSct);                }            }            // Update potential lagviews on the lag            if (newSct != null) {                for (DigraphView graphView : lag.getViews()) {                    GlyphLagView lagView = (GlyphLagView) graphView;                    lagView.addSectionView(newSct);                }            }        }    }