Example usage for java.lang Float POSITIVE_INFINITY

List of usage examples for java.lang Float POSITIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Float POSITIVE_INFINITY.

Prototype

float POSITIVE_INFINITY

To view the source code for java.lang Float POSITIVE_INFINITY.

Click Source Link

Document

A constant holding the positive infinity of type float .

Usage

From source file:at.knowcenter.wag.egov.egiz.pdf.PDFPage.java

public static float findMinX(Pos[] coordinates) {
    float min = Float.POSITIVE_INFINITY;
    for (int i = 0; i < coordinates.length; i++) {
        if (coordinates[i].x < min) {
            min = coordinates[i].x;/*from   w ww . j ava 2  s  .c o  m*/
        }
    }
    return min;
}

From source file:org.proteosuite.FastScatterPlot.java

/**
 * Calculates the Y data range./*  w  ww. j  a va  2s  .  co  m*/
 *
 * @param data  the data.
 *
 * @return The range.
 */
private Range calculateYDataRange(float[][] data) {

    Range result = null;

    if (data != null) {
        float lowest = Float.POSITIVE_INFINITY;
        float highest = Float.NEGATIVE_INFINITY;
        for (int i = 0; i < data[0].length; i++) {
            float v = data[1][i];
            if (v < lowest) {
                lowest = v;
            }
            if (v > highest) {
                highest = v;
            }
        }
        if (lowest <= highest) {
            result = new Range(lowest, highest);
        }
    }
    return result;

}

From source file:org.apache.drill.exec.fn.impl.TestMathFunctionsWithNanInf.java

@Test
public void testCastfloat4Function() throws Exception {
    String table_name = "nan_test.json";
    String json = "{\"nan_col\":NaN, \"inf_col\":Infinity}";
    String query = String.format(
            "select castfloat4(nan_col) as nan_col, castfloat4(inf_col) as inf_col from dfs.`%s`", table_name);
    String[] columns = { "nan_col", "inf_col" };
    Object[] values = { Float.NaN, Float.POSITIVE_INFINITY };
    evalTest(table_name, json, query, columns, values);
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#compareTo(java.lang.Number, java.lang.Number)}.
 *///from w w  w.ja v  a2s. co m
@SuppressWarnings("unchecked")
@Test
public void testCompareToNumberNumber() {
    assertEquals("null", (Object) 0, compareTo(null, null));
    assertEquals("null", (Object) 1, compareTo(1, null));
    assertEquals("null", (Object) 1, compareTo(-1, null));
    assertEquals("null", (Object) 1, compareTo(Float.NEGATIVE_INFINITY, null));
    assertEquals("null", (Object) (-1), compareTo(null, 1));
    assertEquals("null", (Object) (-1), compareTo(null, -1));
    assertEquals("null", (Object) (-1), compareTo(null, Double.NEGATIVE_INFINITY));
    assertEquals("Infinity", (Object) 0, compareTo(Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY));
    assertEquals("Infinity", (Object) 0, compareTo(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    assertEquals("NaN", (Object) 1, compareTo(Float.NaN, null));
    assertEquals("NaN", (Object) 1, compareTo(Float.NaN, 1));
    assertEquals("NaN", (Object) 1, compareTo(Float.NaN, -1));
    assertEquals("NaN", (Object) 1, compareTo(Float.NaN, Double.POSITIVE_INFINITY));
    assertEquals("NaN", (Object) 0, compareTo(Float.NaN, Double.NaN));
    assertEquals("NaN", (Object) (-1), compareTo(null, Double.NaN));
    assertEquals("NaN", (Object) (-1), compareTo(1, Double.NaN));
    assertEquals("NaN", (Object) (-1), compareTo(-1, Double.NaN));
    assertEquals("NaN", (Object) (-1), compareTo(Float.NEGATIVE_INFINITY, Double.NaN));
    assertEquals("NaN", (Object) 0, compareTo(Double.NaN, Float.NaN));
    for (Class<?> type : NUMBERS) {
        Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
        try {
            Number n = null;
            if (ClassUtils.isPrimitiveWrapper(type)) {
                n = (Number) wrapper.getField("MAX_VALUE").get(null);
            } else {
                n = INFINITY_DOUBLE.pow(2);
                if (BigInteger.class.equals(type))
                    n = ((BigDecimal) n).toBigInteger();
            }
            assertEquals("equals: " + type.getSimpleName(), 0, compareTo(n, new BigDecimal(n.toString())));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:org.loklak.objects.MessageEntry.java

public JSONObject toJSON(final UserEntry user, final boolean calculatedData, final int iflinkexceedslength,
        final String urlstub) {
    JSONObject m = new JSONObject(true);

    // tweet data
    m.put(AbstractObjectEntry.TIMESTAMP_FIELDNAME, utcFormatter.print(getTimestamp().getTime()));
    m.put("created_at", utcFormatter.print(getCreatedAt().getTime()));
    if (this.on != null)
        m.put("on", utcFormatter.print(this.on.getTime()));
    if (this.to != null)
        m.put("to", utcFormatter.print(this.to.getTime()));
    m.put("screen_name", this.screen_name);
    if (this.retweet_from != null && this.retweet_from.length() > 0)
        m.put("retweet_from", this.retweet_from);
    m.put("text", this.getText(iflinkexceedslength, urlstub)); // the tweet; the cleanup is a helper function which cleans mistakes from the past in scraping
    if (this.status_id_url != null)
        m.put("link", this.status_id_url.toExternalForm());
    m.put("id_str", this.id_str);
    if (this.canonical_id != null)
        m.put("canonical_id", this.canonical_id);
    if (this.parent != null)
        m.put("parent", this.parent);
    m.put("source_type", this.source_type.toString());
    m.put("provider_type", this.provider_type.name());
    if (this.provider_hash != null && this.provider_hash.length() > 0)
        m.put("provider_hash", this.provider_hash);
    m.put("retweet_count", this.retweet_count);
    m.put("favourites_count", this.favourites_count); // there is a slight inconsistency here in the plural naming but thats how it is noted in the twitter api
    m.put("place_name", this.place_name);
    m.put("place_id", this.place_id);

    // add statistic/calculated data
    if (calculatedData) {

        // location data
        if (this.place_context != null)
            m.put("place_context", this.place_context.name());
        if (this.place_country != null && this.place_country.length() == 2) {
            m.put("place_country", DAO.geoNames.getCountryName(this.place_country));
            m.put("place_country_code", this.place_country);
            m.put("place_country_center", DAO.geoNames.getCountryCenter(this.place_country));
        }//from   w w  w .  j a v  a 2 s .c o m

        // add optional location data. This is written even if calculatedData == false if the source is from REPORT to prevent that it is lost
        if (this.location_point != null && this.location_point.length == 2 && this.location_mark != null
                && this.location_mark.length == 2) {
            // reference for this format: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-geo-point-type.html#_lat_lon_as_array_5
            m.put("location_point", this.location_point); // [longitude, latitude]
            m.put("location_radius", this.location_radius);
            m.put("location_mark", this.location_mark);
            m.put("location_source", this.location_source.name());
        }

        // redundant data for enhanced navigation with aggregations
        m.put("hosts", this.hosts);
        m.put("hosts_count", this.hosts.length);
        m.put("links", this.links);
        m.put("links_count", this.links.length);
        m.put("images", this.images);
        m.put("images_count", this.images.size());
        m.put("audio", this.audio);
        m.put("audio_count", this.audio.size());
        m.put("videos", this.videos);
        m.put("videos_count", this.videos.size());
        m.put("mentions", this.mentions);
        m.put("mentions_count", this.mentions.length);
        m.put("hashtags", this.hashtags);
        m.put("hashtags_count", this.hashtags.length);

        // text classifier
        if (this.classifier != null) {
            for (Map.Entry<Context, Classification<String, Category>> c : this.classifier.entrySet()) {
                assert c.getValue() != null;
                if (c.getValue().getCategory() == Classifier.Category.NONE)
                    continue; // we don't store non-existing classifications
                m.put("classifier_" + c.getKey().name(), c.getValue().getCategory());
                m.put("classifier_" + c.getKey().name() + "_probability",
                        c.getValue().getProbability() == Float.POSITIVE_INFINITY ? Float.MAX_VALUE
                                : c.getValue().getProbability());
            }
        }

        // experimental, for ranking
        m.put("without_l_len", this.without_l_len);
        m.put("without_lu_len", this.without_lu_len);
        m.put("without_luh_len", this.without_luh_len);
    }

    // add user
    if (user != null)
        m.put("user", user.toJSON());
    return m;
}

From source file:org.evosuite.junit.naming.variables.ExplanatoryNamingTestVisitor.java

/**
 * <p>/*ww w.  j  a v  a 2s . c o  m*/
 * getNumberString
 * </p>
 *
 * @param value
 *            a {@link java.lang.Object} object.
 * @return a {@link java.lang.String} object.
 */
public static String getStringForPrimitiveValue(Object value) {
    assert (value != null);
    if (value.getClass().equals(char.class) || value.getClass().equals(Character.class)) {
        if (CharUtils.isAsciiNumeric((Character) value))
            return "Numeric";
        else if (CharUtils.isAsciiAlpha((Character) value))
            return "Alpha";
        else
            return "NotAlphanumeric";
    } else if (value.getClass().equals(String.class)) {
        return ((String) value).isEmpty() ? "EmptyString" : "NonEmptyString";
    } else if (value.getClass().equals(float.class) || value.getClass().equals(Float.class)) {
        if (value.toString().equals("" + Float.NaN))
            return "NaN";
        else if (value.toString().equals("" + Float.NEGATIVE_INFINITY))
            return "NegativeInf";
        else if (value.toString().equals("" + Float.POSITIVE_INFINITY))
            return "PositiveInf";
        else
            return (((Float) value) < 0F) ? "Negative" : (((Float) value) == 0F) ? "Zero" : "Positive";
    } else if (value.getClass().equals(double.class) || value.getClass().equals(Double.class)) {
        if (value.toString().equals("" + Double.NaN))
            return "NaN";
        else if (value.toString().equals("" + Double.NEGATIVE_INFINITY))
            return "NegativeInf";
        else if (value.toString().equals("" + Double.POSITIVE_INFINITY))
            return "PositiveInf";
        else
            return (((Double) value) < 0.0) ? "Negative" : (((Double) value) == 0.0) ? "Zero" : "Positive";
    } else if (value.getClass().equals(long.class) || value.getClass().equals(Long.class)) {
        return (((Long) value) < 0) ? "Negative" : (((Long) value) == 0) ? "Zero" : "Positive";
    } else if (value.getClass().equals(byte.class) || value.getClass().equals(Byte.class)) {
        return (((Byte) value) < 0) ? "Negative" : (((Byte) value) == 0) ? "Zero" : "Positive";
    } else if (value.getClass().equals(short.class) || value.getClass().equals(Short.class)) {
        return (((Short) value) < 0) ? "Negative" : (((Short) value) == 0) ? "Zero" : "Positive";
    } else if (value.getClass().equals(int.class) || value.getClass().equals(Integer.class)) {
        int val = ((Integer) value).intValue();
        if (val == Integer.MAX_VALUE)
            return "MaxInt";
        else if (val == Integer.MIN_VALUE)
            return "MinInt";
        else
            return (((Integer) value) < 0) ? "Negative" : (((Integer) value) == 0) ? "Zero" : "Positive";
    } else if (value.getClass().isEnum() || value instanceof Enum) {
        return "EnumValue";
    } else if (value.getClass().equals(Boolean.class)) {
        return capitalize(Boolean.toString((Boolean) value));
    } else {
        // This should not happen
        assert (false);
        return value.toString();
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#contains(java.lang.Object, java.lang.Number, java.lang.Number)}.
 *///  w  w  w  .ja va2  s .  c  o m
@SuppressWarnings("unchecked")
@Test
public void testContains() {
    assertEquals("null", false, contains(null, null, null));
    assertEquals("null", false, contains(null, 0, null));
    assertEquals("null", false, contains(null, null, 10));
    assertEquals("null", false, contains(null, 0, 10));
    assertEquals("null: from", true, contains(0, null, 10));
    assertEquals("null: from: overflow", false, contains(11, null, 10));
    assertEquals("null: to", true, contains(0, 0, null));
    assertEquals("null: to", true, contains(11, 10, null));
    assertEquals("null: to: less", false, contains(1, 10, null));
    assertEquals("fraction: Double", true, contains(Math.PI, 0, 10));
    assertEquals("fraction: Float", true, contains(Float.MIN_VALUE, 0, 10));
    assertEquals("NaN", false, contains(Float.NaN, -Float.MAX_VALUE, Float.MAX_VALUE));
    assertEquals("NaN", false, contains(Float.NaN, null, Float.POSITIVE_INFINITY));
    assertEquals("NaN", true, contains(Float.NaN, Float.NaN, Float.POSITIVE_INFINITY));
    assertEquals("NaN", true, contains(Float.NaN, null, Float.NaN));
    assertEquals("NaN", true, contains(Float.NaN, Double.NaN, Float.NaN));
    assertEquals("-Infinity: from", true, contains(1, Float.NEGATIVE_INFINITY, null));
    assertEquals("-Infinity: to", false, contains(1, null, Float.NEGATIVE_INFINITY));
    assertEquals("Infinity: from", false, contains(1, Float.POSITIVE_INFINITY, null));
    assertEquals("Infinity: to", true, contains(1, null, Float.POSITIVE_INFINITY));
    assertEquals("Infinity: only", false, contains(1, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    assertEquals("Infinity: only", true,
            contains(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    assertEquals("Infinity: only", true,
            contains(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    for (Class<?> type : NUMBERS) {
        Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
        Object o = null;
        try {
            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                o = wrapper.getField("MAX_VALUE").get(null);
            } else {
                o = INFINITY_DOUBLE.pow(2);
                if (BigInteger.class.equals(type))
                    o = ((BigDecimal) o).toBigInteger();
            }
            assertEquals("Infinity: all: " + type.getSimpleName(), true,
                    contains(o, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:gdsc.smlm.results.TraceManager.java

/**
 * Find the earliest forerunner spot (from pastIndex to currentIndex) that is within the distance threshold of the
 * given spot. In the event that multiple forerunner spots from the same frame are within the distance, assign the
 * closest spot./* ww w .  j a  v  a 2 s.com*/
 * 
 * @param index
 *            The index of the spot
 * @param pastIndex
 *            The index of the earliest forerunner spot
 * @param currentIndex
 *            The index of the first spot in the same frame (i.e. end of forerunner spots)
 * @return
 */
private int findForerunner(final int index, final int pastIndex, final int currentIndex) {
    Localisation spot = localisations[index];
    // Check that the next farthest spot is above the exclusion distance
    float nextMinD = Float.POSITIVE_INFINITY;
    int currentT;
    if (traceMode == TraceMode.EARLIEST_FORERUNNER) {
        currentT = endLocalisations[pastIndex].t;
        for (int i = pastIndex; i < currentIndex; i++) {
            final float d2 = spot.distance2(endLocalisations[i]);
            if (d2 <= dThresh2) {
                minD = d2;
                int trace = endLocalisations[i].trace;

                // Search all remaining spots that end in this time frame and pick the closest
                int nextIndex = endIndex[endLocalisations[i].endT + 1];
                for (int ii = i + 1; ii < nextIndex; ii++) {
                    final float dd2 = spot.distance2(endLocalisations[ii]);
                    if (dd2 < minD) {
                        nextMinD = minD;
                        minD = dd2;
                        trace = endLocalisations[ii].trace;
                    }
                }

                return (nextMinD > dExclusion2) ? trace : 0;
            }
            // If the same frame
            else if (currentT == endLocalisations[i].t) {
                // Store the minimum distance to the next spot in the same frame
                if (d2 < nextMinD) {
                    nextMinD = d2;
                }
            } else {
                // New time frame so reset the distance to the next spot in the same frame
                nextMinD = d2;
            }
            currentT = endLocalisations[i].t;
        }
    } else if (traceMode == TraceMode.LATEST_FORERUNNER) {
        currentT = endLocalisations[currentIndex].t;
        for (int i = currentIndex; i-- > pastIndex;) {
            final float d2 = spot.distance2(endLocalisations[i]);
            if (d2 <= dThresh2) {
                minD = d2;
                int trace = endLocalisations[i].trace;

                // Search all remaining spots in this time frame and pick the closest
                int previousIndex = endIndex[endLocalisations[i].endT];
                //int previousIndex = i;
                //// Look for the index for the previous time-frame
                //while (previousIndex > 0 && endLocalisations[previousIndex-1].t == endLocalisations[i].t)
                //   previousIndex--;
                //if (previousIndex != endIndex[endLocalisations[i].endT])
                //{
                //   System.out.printf("Error when tracing: %d != %d\n", previousIndex,
                //         endIndex[endLocalisations[i].endT]);
                //}
                for (int ii = i; ii-- > previousIndex;) {
                    final float dd2 = spot.distance2(endLocalisations[ii]);
                    if (dd2 < minD) {
                        nextMinD = minD;
                        minD = dd2;
                        trace = endLocalisations[ii].trace;
                    }
                }

                return (nextMinD > dExclusion2) ? trace : 0;
            }
            // If the same frame
            else if (currentT == endLocalisations[i].t) {
                // Store the minimum distance to the next spot in the same frame
                if (d2 < nextMinD) {
                    nextMinD = d2;
                }
            } else {
                // New time frame so reset the distance to the next spot in the same frame
                nextMinD = d2;
            }
            currentT = endLocalisations[i].t;
        }
    } else
    // traceMode == TraceMode.Complete
    {
        // Find the closest spot
        minD = dThresh2;
        int minI = -1;
        for (int i = pastIndex; i < currentIndex; i++) {
            final float d2 = spot.distance2(endLocalisations[i]);
            if (d2 <= minD) {
                minD = d2;
                minI = i;
            }
        }

        if (minI == -1)
            return 0;

        if (dExclusion2 > 0) {
            // Check all spots in the same frame
            int previousIndex = endIndex[endLocalisations[minI].endT];
            int nextIndex = endIndex[endLocalisations[minI].endT + 1];

            for (int i = previousIndex; i < nextIndex; i++) {
                if (i == minI)
                    continue;
                final float d2 = spot.distance2(endLocalisations[i]);
                if (d2 <= nextMinD) {
                    nextMinD = d2;
                }
            }
        }

        return (nextMinD > dExclusion2) ? endLocalisations[minI].trace : 0;
    }
    return 0;
}

From source file:gdsc.smlm.fitting.Gaussian2DFitter.java

/**
 * Sets the constraints for the fitted parameters. This functions set the lower bounds of the background and
 * signal to zero.// w ww .  ja  va  2 s  .co m
 * 
 * @param maxx
 *            The x range of the data
 * @param maxy
 *            The y range of the data
 * @param npeaks
 *            The number of peaks
 * @param params
 *            The estimated parameters
 * @param y
 *            The data
 * @param ySize
 *            The size of the data
 * @param paramsPerPeak
 *            The number of parameters per peak
 */
private void setConstraints(final int maxx, final int maxy, final int npeaks, final double[] params,
        final double[] y, final int ySize, final int paramsPerPeak) {
    // Create appropriate bounds for the parameters
    double[] lower = new double[params.length];
    double[] upper = new double[lower.length];
    Arrays.fill(lower, Float.NEGATIVE_INFINITY);
    Arrays.fill(upper, Float.POSITIVE_INFINITY);
    lower[Gaussian2DFunction.BACKGROUND] = 0;
    for (int i = 0, j = 0; i < npeaks; i++, j += paramsPerPeak) {
        lower[j + Gaussian2DFunction.SIGNAL] = 0;
    }
    solver.setConstraints(lower, upper);
}

From source file:gdsc.smlm.results.TraceManager.java

/**
 * Find the earliest forerunner spot (from pastIndex to currentIndex) that is within the distance threshold of the
 * given spot. In the event that multiple forerunner spots from the same frame are within the distance, assign the
 * closest spot.//from   w  w w . jav  a  2  s  . c o  m
 * <p>
 * Do not assigned to the specified trace to ignore.
 * 
 * @param index
 *            The index of the spot
 * @param pastIndex
 *            The index of the earliest forerunner spot
 * @param currentIndex
 *            The index of the first spot in the same frame (i.e. end of forerunner spots)
 * @param ignoreCount
 *            The count of traces to ignore
 * @param ignore
 *            The traces to ignore
 * @return
 */
private int findAlternativeForerunner(final int index, final int pastIndex, final int currentIndex,
        final int ignoreCount, final int[] ignore) {
    Localisation spot = localisations[index];

    // Check that the next farthest spot is above the exclusion distance.
    // Note: It is assumed that the spots to ignore have already been assigned following the 
    // exclusion distance rules. So it should be impossible for any ignore spots to be closer than 
    // the exclusion distance (otherwise they could not be assigned and ignored).   
    float nextMinD = Float.POSITIVE_INFINITY;
    int currentT;

    if (traceMode == TraceMode.EARLIEST_FORERUNNER) {
        currentT = endLocalisations[pastIndex].t;
        for (int i = pastIndex; i < currentIndex; i++) {
            if (ignore(i, ignoreCount, ignore))
                continue;

            final float d2 = spot.distance2(endLocalisations[i]);
            if (d2 <= dThresh2) {
                minD = d2;
                int trace = endLocalisations[i].trace;

                // Search all remaining spots in this time frame and pick the closest
                int nextIndex = endIndex[endLocalisations[i].endT + 1];
                //               int nextIndex = i;
                //               // Look for the index for the next time-frame
                //               for (int tt = endLocalisations[i].endT + 1; tt < endIndex.length; tt++)
                //               {
                //                  nextIndex = endIndex[tt];
                //                  if (nextIndex != i)
                //                     break;
                //               }
                for (int ii = i + 1; ii < nextIndex; ii++) {
                    if (ignore(ii, ignoreCount, ignore))
                        continue;

                    final float dd2 = spot.distance2(endLocalisations[ii]);
                    if (dd2 < minD) {
                        nextMinD = minD;
                        minD = dd2;
                        trace = endLocalisations[ii].trace;
                    }
                }

                return (nextMinD > dExclusion2) ? trace : 0;
            }
            // If the same frame
            else if (currentT == endLocalisations[i].t) {
                // Store the minimum distance to the next spot in the same frame
                if (d2 < nextMinD) {
                    nextMinD = d2;
                }
            } else {
                // New time frame so reset the distance to the next spot in the same frame
                nextMinD = d2;
            }
            currentT = endLocalisations[i].t;
        }
    } else if (traceMode == TraceMode.LATEST_FORERUNNER) {
        currentT = endLocalisations[currentIndex].t;
        for (int i = currentIndex; i-- > pastIndex;) {
            if (ignore(i, ignoreCount, ignore))
                continue;

            final float d2 = spot.distance2(endLocalisations[i]);
            if (d2 <= dThresh2) {
                minD = d2;
                int trace = endLocalisations[i].trace;

                // Search all remaining spots in this time frame and pick the closest
                int previousIndex = endIndex[endLocalisations[i].endT];
                //int previousIndex = i;
                //// Look for the index for the previous time-frame
                //while (previousIndex > 0 && endLocalisations[previousIndex-1].t == endLocalisations[i].t)
                //   previousIndex--;
                //if (previousIndex != endIndex[endLocalisations[i].endT])
                //{
                //   System.out.printf("Error when tracing: %d != %d\n", previousIndex,
                //         endIndex[endLocalisations[i].endT]);
                //}
                for (int ii = i; ii-- > previousIndex;) {
                    if (ignore(ii, ignoreCount, ignore))
                        continue;

                    final float dd2 = spot.distance2(endLocalisations[ii]);
                    if (dd2 < minD) {
                        nextMinD = minD;
                        minD = dd2;
                        trace = endLocalisations[ii].trace;
                    }
                }

                return (nextMinD > dExclusion2) ? trace : 0;
            }
            // If the same frame
            else if (currentT == endLocalisations[i].t) {
                // Store the minimum distance to the next spot in the same frame
                if (d2 < nextMinD) {
                    nextMinD = d2;
                }
            } else {
                // New time frame so reset the distance to the next spot in the same frame
                nextMinD = d2;
            }
            currentT = endLocalisations[i].t;
        }
    } else
    // traceMode == TraceMode.Complete
    {
        // Find the closest spot
        minD = dThresh2;
        int minI = -1;
        for (int i = pastIndex; i < currentIndex; i++) {
            if (ignore(i, ignoreCount, ignore))
                continue;

            final float d2 = spot.distance2(endLocalisations[i]);
            if (d2 <= minD) {
                minD = d2;
                minI = i;
            }
        }

        if (minI == -1)
            return 0;

        if (dExclusion2 > 0) {
            // Check all spots in the same frame
            int previousIndex = endIndex[endLocalisations[minI].endT];
            int nextIndex = endIndex[endLocalisations[minI].endT + 1];

            for (int i = previousIndex; i < nextIndex; i++) {
                if (i == minI)
                    continue;
                if (ignore(i, ignoreCount, ignore))
                    continue;

                final float d2 = spot.distance2(endLocalisations[i]);
                if (d2 <= nextMinD) {
                    nextMinD = d2;
                }
            }
        }

        return (nextMinD > dExclusion2) ? endLocalisations[minI].trace : 0;
    }
    return 0;
}