List of usage examples for java.lang Double isNaN
public static boolean isNaN(double v)
From source file:com.ning.metrics.collector.util.Stats.java
/** * Average./*from www. java2 s . c o m*/ * * @return average */ @Managed @SuppressWarnings("unused") public double getSizeAvg() { double avg = sizeStats.getMean(); return Double.isNaN(avg) ? 0.0 : avg; }
From source file:de.biomedical_imaging.ij.nanotrackj.WalkerMethodEstimator.java
private double logGammaK(double k) { if (!Double.isNaN(logMapGammaK[(int) k])) { return logMapGammaK[(int) k]; }//from ww w .j a v a 2 s. com logMapGammaK[(int) k] = Gamma.logGamma(k); return logMapGammaK[(int) k]; }
From source file:beast.math.distributions.NormalDistribution.java
/** * A more accurate and faster implementation of the cdf (taken from function pnorm in the R statistical language) * This implementation has discrepancies depending on the programming language and system architecture * In Java, returned values become zero once z reaches -37.5193 exactly on the machine tested * In the other implementation, the returned value 0 at about z = -8 * In C, this 0 value is reached approximately z = -37.51938 * <p/>// w w w. jav a2 s . co m * Will later need to be optimised for BEAST * * @param x argument * @param log_p is p logged * @return cdf at x */ public static double standardCDF(double x, boolean log_p) { boolean i_tail = false; if (Double.isNaN(x)) { return Double.NaN; } double xden, xnum, temp, del, eps, xsq, y; int i; double p = x, cp = Double.NaN; boolean lower, upper; eps = DBL_EPSILON * 0.5; lower = !i_tail; upper = i_tail; y = Math.abs(x); if (y <= 0.67448975) { /* Normal.quantile(3/4, 1, 0) = 0.67448975 */ if (y > eps) { xsq = x * x; xnum = a[4] * xsq; xden = xsq; for (i = 0; i < 3; i++) { xnum = (xnum + a[i]) * xsq; xden = (xden + b[i]) * xsq; } } else { xnum = xden = 0.0; } temp = x * (xnum + a[3]) / (xden + b[3]); if (lower) { p = 0.5 + temp; } if (upper) { cp = 0.5 - temp; } if (log_p) { if (lower) { p = Math.log(p); } if (upper) { cp = Math.log(cp); } } } else if (y <= M_SQRT_32) { /* Evaluate pnorm for 0.67448975 = Normal.quantile(3/4, 1, 0) < |x| <= sqrt(32) ~= 5.657 */ xnum = c[8] * y; xden = y; for (i = 0; i < 7; i++) { xnum = (xnum + c[i]) * y; xden = (xden + d[i]) * y; } temp = (xnum + c[7]) / (xden + d[7]); //do_del(y); //swap_tail; //#define do_del(X) \ xsq = ((int) (y * CUTOFF)) * 1.0 / CUTOFF; del = (y - xsq) * (y + xsq); if (log_p) { p = (-xsq * xsq * 0.5) + (-del * 0.5) + Math.log(temp); if ((lower && x > 0.0) || (upper && x <= 0.0)) { cp = Math.log(1.0 - Math.exp(-xsq * xsq * 0.5) * Math.exp(-del * 0.5) * temp); } } else { p = Math.exp(-xsq * xsq * 0.5) * Math.exp(-del * 0.5) * temp; cp = 1.0 - p; } //#define swap_tail \ if (x > 0.0) { temp = p; if (lower) { p = cp; } cp = temp; } } /* else |x| > sqrt(32) = 5.657 : * the next two case differentiations were really for lower=T, log=F * Particularly *not* for log_p ! * Cody had (-37.5193 < x && x < 8.2924) ; R originally had y < 50 * Note that we do want symmetry(0), lower/upper -> hence use y */ else if (log_p || (lower && -37.5193 < x && x < 8.2924) || (upper && -8.2924 < x && x < 37.5193)) { /* Evaluate pnorm for x in (-37.5, -5.657) union (5.657, 37.5) */ xsq = 1.0 / (x * x); xnum = p_[5] * xsq; xden = xsq; for (i = 0; i < 4; i++) { xnum = (xnum + p_[i]) * xsq; xden = (xden + q[i]) * xsq; } temp = xsq * (xnum + p_[4]) / (xden + q[4]); temp = (M_1_SQRT_2PI - temp) / y; //do_del(x); xsq = ((int) (x * CUTOFF)) * 1.0 / CUTOFF; del = (x - xsq) * (x + xsq); if (log_p) { p = (-xsq * xsq * 0.5) + (-del * 0.5) + Math.log(temp); if ((lower && x > 0.0) || (upper && x <= 0.0)) { cp = Math.log(1.0 - Math.exp(-xsq * xsq * 0.5) * Math.exp(-del * 0.5) * temp); } } else { p = Math.exp(-xsq * xsq * 0.5) * Math.exp(-del * 0.5) * temp; cp = 1.0 - p; } //swap_tail; if (x > 0.0) { temp = p; if (lower) { p = cp; } cp = temp; } } else { /* no log_p , large x such that probs are 0 or 1 */ if (x > 0) { p = 1.0; cp = 0.0; } else { p = 0.0; cp = 1.0; } } return p; }
From source file:net.sf.eventgraphj.analysis.InverseDistanceCentralityScorer.java
/** * Calculates the score for the specified vertex. Returns {@code null} if * there are missing distances and such are not ignored by this instance. */// w w w. jav a 2 s . c om @Override public Double getVertexScore(V v) { Double value = this.output.get(v); if (value != null) { if (value < 0) { return null; } return value; } Map<V, Number> v_distances = new HashMap<V, Number>(this.distance.getDistanceMap(v)); if (this.ignore_self_distances) { v_distances.remove(v); } // if we don't ignore missing distances and there aren't enough // distances, output null (shortcut) if (!this.ignore_missing) { int num_dests = this.graph.getVertexCount() - (this.ignore_self_distances ? 1 : 0); if (v_distances.size() != num_dests) { this.output.put(v, -1.0); return null; } } Double sum = 0.0; int count = 0; for (V w : this.graph.getVertices()) { if (w.equals(v) && this.ignore_self_distances) { continue; } Number w_distance = v_distances.get(w); if (w_distance == null) { if (this.ignore_missing) { w_distance = Double.POSITIVE_INFINITY;// graph.getVertexCount(); } else { this.output.put(v, -1.0); return null; } } sum += 1 / w_distance.doubleValue(); count++; } value = sum; if (this.averaging && count > 0) { value /= count; } this.output.put(v, value); if (Double.isNaN(value)) { System.err.println(value); } // assert (!Double.isNaN(value)); return value; }
From source file:lirmm.inria.fr.math.OpenLongToDoubleHashMapTest.java
@Test public void testRemove2() { OpenLongToDoubleHashMap map = createFromJavaMap(); int mapSize = javaMap.size(); int count = 0; Set<Long> keysInMap = new HashSet<>(javaMap.keySet()); for (Map.Entry<Long, Double> mapEntry : javaMap.entrySet()) { keysInMap.remove(mapEntry.getKey()); map.remove(mapEntry.getKey());//from ww w . j av a2 s . co m Assert.assertEquals(--mapSize, map.size()); Assert.assertTrue(Double.isNaN(map.get(mapEntry.getKey()))); if (count++ > 5) { break; } } /* Ensure that put and get still work correctly after removals */ assertPutAndGet(map, mapSize, keysInMap); }
From source file:gda.plots.TurboXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself.//from w ww.ja v a 2 s . c om * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information etc). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param crosshairState * crosshair information for the plot ( <code>null</code> permitted). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int _item, CrosshairState crosshairState, int pass) { if (_item > 0) return; SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); try { int x0 = -1; // the x position in pixels of the previous point int y0 = -1; // the y position in pixels of the previous point int x1 = -1; // the x position in pixels of the current point int y1 = -1; // the y position in pixels of the current point int xmin = (int) dataArea.getMinX(); int xmax = (int) dataArea.getMaxX(); int ymin = (int) dataArea.getMinY(); int ymax = (int) dataArea.getMaxY(); GeneralPath path = null; /* * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear * maths */ double xl = 0., mx = Double.NaN, cx = 0.; if (domainAxis instanceof SimpleNumberAxis) { xl = domainAxis.getRange().getLowerBound(); mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl); cx = xmin; } double yl = 0., my = Double.NaN, cy = 0.; if (rangeAxis instanceof SimpleNumberAxis) { yl = rangeAxis.getRange().getLowerBound(); my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl); cy = ymax; } List<XYDataItem> list = sxys.getData(); boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my); Paint paint = sxys.getPaint(); Stroke stroke = sxys.getStroke(); Paint paint_symbol = sxys.getSymbolPaint(); Stroke stroke_symbol = new BasicStroke(); drawLines = sxys.isDrawLines(); boolean filled = sxys.getFilled(); Shape shape = sxys.getSymbol(); boolean drawMarkers = sxys.isDrawMarkers() & shape != null; int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */ if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) { Rectangle shapeBoundingBox = shape.getBounds(); tooltipThresholdCounts = (int) dataArea.getWidth() / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold); } java.util.Vector<ddouble> markerPositions = null; Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } boolean prevLineAdded = false; // In case the iterator does not work then use the TODO comment iterator use and why not always // comment variables synchronized (list) { Iterator<XYDataItem> iter = list.iterator(); /* * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The * variable addThis determines if the current point is to be added to the path If previous line was * added that the current must be even if off the screen - but in this case the flag prevLineAdded is * set false so that the next does not have to be added. */ for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) { XYDataItem dataitem = iter.next(); double x = dataitem.getX().doubleValue(); double y = dataitem.getY().doubleValue(); x = xValueTransformer.transformValue(x); x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation) : (int) ((x - xl) * mx + cx); y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) : (int) ((y - yl) * my + cy); boolean addThis = true; if (item == 0) { x0 = x1; y0 = y1; if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) { addThis = false; } } else { if (x1 == x0 && y1 == y0) { addThis = false; } if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin) || (y1 > ymax && y0 > ymax)) { if (prevLineAdded) { path = addPointToLine(path, orientation, x1, y1); } addThis = false; } } if (addThis) { /* * If the current point is to be added then ensure previous one is as well to prevent lines * not crossing the edge of the screen */ if (!prevLineAdded) { path = addPointToLine(path, orientation, x0, y0); } path = addPointToLine(path, orientation, x1, y1); prevLineAdded = true; } prevLineAdded = addThis; if (addThis && drawMarkers) { if (markerPositions == null) { markerPositions = new java.util.Vector<ddouble>(); } markerPositions.add(new ddouble(item, x1, y1)); if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) { drawMarkers = false; markerPositions = null; } } } if (path != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(path); } if (markerPositions != null) { if (drawMarkers) { g2.setPaint(paint_symbol); g2.setStroke(stroke_symbol); for (ddouble dd : markerPositions) { Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y); if (filled) { g2.fill(shape_item); } else { g2.draw(shape_item); } entityArea = shape_item; // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y); } } g2.setPaint(paint); g2.setStroke(stroke); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.illinois.cs.cogcomp.transliteration.CSPTransliteration.java
public static CSPModel LearnModel(List<Triple<String, String, Double>> examples, CSPModel model) { // odd notation... CSPExampleCounts counts = new CSPTransliteration().new CSPExampleCounts(); //CSPExampleCounts intCounts = new CSPExampleCounts(); counts.productionCounts = new SparseDoubleVector<>(); counts.segCounts = new SparseDoubleVector<>(); for (Triple<String, String, Double> example : examples) { CSPExampleCounts exampleCount = LearnModel(example.getFirst(), example.getSecond(), model); counts.productionCounts.put(example.getThird(), exampleCount.productionCounts); counts.segCounts.put(example.getThird(), exampleCount.segCounts); //intCounts.productionCounts += exampleCount.productionCounts.Sign(); //intCounts.segCounts += exampleCount.segCounts.Sign(); }/* w w w .j a v a2 s . c om*/ CSPModel result = (CSPModel) model.clone(); //normalize to get "joint" result.productionProbs = counts.productionCounts.divide(counts.productionCounts.PNorm(1)); InternDictionary<String> internTable = new InternDictionary<>(); SparseDoubleVector<Pair<Triple<String, String, String>, String>> oldProbs = null; if (model.underflowChecking) oldProbs = result.productionProbs; //now get production fallbacks result.productionProbs = CreateFallbackPair(result.productionProbs, internTable); //finally, make it conditional result.productionProbs = PSecondGivenFirst(result.productionProbs); if (model.underflowChecking) { //go through and ensure that Sum_X(P(Y|X)) == 1...or at least > 0! SparseDoubleVector<Triple<String, String, String>> sums = new SparseDoubleVector<>(); for (Pair<Triple<String, String, String>, String> key : model.productionProbs.keySet()) { Double value = model.productionProbs.get(key); Triple<String, String, String> ff = key.getFirst(); Double val = sums.get(ff); sums.put(ff, val + value); } List<Pair<Triple<String, String, String>, String>> restoreList = new ArrayList<>(); for (Pair<Triple<String, String, String>, String> key : model.productionProbs.keySet()) { Double value = model.productionProbs.get(key); if (value == 0 && sums.get(key.getFirst()) == 0) restoreList.add(key); } for (Pair<Triple<String, String, String>, String> pair : restoreList) { //model.productionProbs[pair] = oldProbs[pair]; model.productionProbs.put(pair, oldProbs.get(pair)); } } //get conditional segmentation probs if (model.segMode == CSPModel.SegMode.Count) result.segProbs = CreateFallback( PSegGivenFlatOccurence(counts.segCounts, examples, model.segContextSize), internTable); // counts.segCounts / counts.segCounts.PNorm(1); else if (model.segMode == CSPModel.SegMode.Entropy) { SparseDoubleVector<Triple<String, String, String>> totals = new SparseDoubleVector<>(); for (Pair<Triple<String, String, String>, String> key : result.productionProbs.keySet()) { Double value = result.productionProbs.get(key); //totals[pair.Key.x] -= pair.Value * Math.Log(pair.Value, 2); double logValue = value * Math.log(value); if (!Double.isNaN(logValue)) { Double lv = totals.get(key.getFirst()); totals.put(key.getFirst(), lv + logValue); } //totals[pair.Key.x] *= Math.Pow(pair.Value, pair.Value); } result.segProbs = totals.Exp(); //totals.Max(0.000001).Pow(-1); } //return the finished model return result; }
From source file:com.anhth12.lambda.app.speed.ALSSpeedModelManager.java
private double[] newVector(Solver solver, double value, float[] Xu, float[] Yi) { double[] newXu = null; if (Yi != null) { //Qui = Xu*(Yi)^t double currentValue = Xu == null ? 0.5 : VectorMath.dot(Xu, Yi); double targetQui = computeTargetQui(value, currentValue); if (!Double.isNaN(targetQui)) { float[] QuiYi = Yi.clone(); for (int i = 0; i < QuiYi.length; i++) { QuiYi[i] *= targetQui;/*from w w w. j ava 2s .c o m*/ } newXu = solver.solveFToD(Yi); } } return newXu; }
From source file:bide.core.par.TunePar.java
private double checkNormal(double tp, double d, double reset) { double newTp = tp; if (d >= accUpper | d < accLower) { newTp = tp * INV_OPT_ACC / NormalDistribution.quantile(d / 2, 0, 1); }/* w ww . j a va 2s. co m*/ if (Double.isNaN(newTp)) { if (tp == reset) { newTp = 2.38; } else { newTp = reset; } } if (tp < 0.001) { if (tp == reset) { newTp = 2.38; } else { newTp = reset; } } if (newTp > 10) { newTp = 2.38; } return newTp; }
From source file:com.stableapps.anglewraparounddemo.AngleWrapDemoMain.java
/** * Creates a sample chart./*from www. j a va2 s . c o m*/ * * @return a sample chart. */ private JFreeChart createChart() { final XYDataset direction = createAngleDataset(600); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); // configure the range axis to provide a fix set of TickUnits depending on size of chart NumberAxis rangeAxis = new NumberAxis() { /** * */ private static final long serialVersionUID = 1L; @Override public NumberTickUnit getTickUnit() { NumberTickUnit tickUnit = super.getTickUnit(); if (tickUnit.getSize() < 15) { return tickUnit; } else if (tickUnit.getSize() < 45) { return new NumberTickUnit(45); } else if (tickUnit.getSize() < 90) { return new NumberTickUnit(90); } else if (tickUnit.getSize() < 180) { return new NumberTickUnit(180); } else { return new NumberTickUnit(360); } } }; rangeAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(rangeAxis); final OverflowCondition overflowCondition = new OverflowCondition() { @Override public boolean isOverflow(double y0, double x0, double y1, double x1) { return Math.abs(y1 - y0) > 180; } }; XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { /** * */ private static final long serialVersionUID = 1L; double min = 0; double max = 360; LinearInterpolator interpolator = new LinearInterpolator(); @Override protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item == 0) { return; } // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } if (overflowCondition.isOverflow(y0, x0, y1, x1)) { boolean overflowAtMax = y1 < y0; if (overflowAtMax) { LinearFunction lf = interpolator.interpolate(new double[] { y0, y1 + (max - min) }, new double[] { x0, x1 }); double xmid = lf.value(max); drawPrimaryLine(state, g2, plot, x0, y0, xmid, max, pass, series, item, domainAxis, rangeAxis, dataArea); drawPrimaryLine(state, g2, plot, xmid, min, x1, y1, pass, series, item, domainAxis, rangeAxis, dataArea); } else { LinearFunction lf = interpolator.interpolate(new double[] { y1 - (max - min), y0 }, new double[] { x1, x0 }); double xmid = lf.value(min); drawPrimaryLine(state, g2, plot, x0, y0, xmid, min, pass, series, item, domainAxis, rangeAxis, dataArea); drawPrimaryLine(state, g2, plot, xmid, max, x1, y1, pass, series, item, domainAxis, rangeAxis, dataArea); } } else { drawPrimaryLine(state, g2, plot, x0, y0, x1, y1, pass, series, item, domainAxis, rangeAxis, dataArea); } } private void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, double x0, double y0, double x1, double y1, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } PlotOrientation orientation = plot.getOrientation(); boolean visible; if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } visible = LineUtilities.clipLine(state.workingLine, dataArea); if (visible) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } } @Override protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { // get the data point... State s = (State) state; try { double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(x1) && Double.isNaN(y1)) { s.setLastPointGood(false); return; } if (!s.isLastPointGood()) { ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1); s.seriesPath.moveTo(xy.getLeft(), xy.getRight()); s.setLastPointGood(true); return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); if (overflowCondition.isOverflow(y0, x0, y1, x1)) { boolean overflowAtMax = y1 < y0; if (overflowAtMax) { LinearFunction lf = interpolator.interpolate(new double[] { y0, y1 + (max - min) }, new double[] { x0, x1 }); double xmid = lf.value(max); ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, max); s.seriesPath.lineTo(xy.getLeft(), xy.getRight()); xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, min); s.seriesPath.moveTo(xy.getLeft(), xy.getRight()); xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1); s.seriesPath.lineTo(xy.getLeft(), xy.getRight()); } else { LinearFunction lf = interpolator.interpolate(new double[] { y1 - (max - min), y0 }, new double[] { x1, x0 }); double xmid = lf.value(min); ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, min); s.seriesPath.lineTo(xy.getLeft(), xy.getRight()); xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, max); s.seriesPath.moveTo(xy.getLeft(), xy.getRight()); xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1); s.seriesPath.lineTo(xy.getLeft(), xy.getRight()); } } else { ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1); s.seriesPath.lineTo(xy.getLeft(), xy.getRight()); } s.setLastPointGood(true); } finally { // if this is the last item, draw the path ... if (item == s.getLastItemIndex()) { // draw path drawFirstPassShape(g2, pass, series, item, s.seriesPath); } } } private ImmutablePair<Float, Float> translate(XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea, double x, double y) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); // update path to reflect latest point float xtrans = (float) transX1; float ytrans = (float) transY1; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { xtrans = (float) transY1; ytrans = (float) transX1; } return new ImmutablePair<>(xtrans, ytrans); } }; renderer.setDrawSeriesLineAsPath(true); plot.setRenderer(0, renderer); return chart; }