gpt4 book ai didi

org.geotools.resources.XMath类的使用及代码示例

转载 作者:知者 更新时间:2024-03-23 03:33:05 27 4
gpt4 key购买 nike

本文整理了Java中org.geotools.resources.XMath类的一些代码示例,展示了XMath类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMath类的具体详情如下:
包路径:org.geotools.resources.XMath
类名称:XMath

XMath介绍

[英]Simple mathematical functions.
[中]简单的数学函数。

代码示例

代码示例来源:origin: org.geotools/gt-coverage

/**
 * Returns a {@code double} value for the specified number. If {@code direction}
 * is non-zero, then this method will returns the closest representable number of type
 * {@code type} before or after the double value.
 *
 * @param type      The range element class. {@code number} must be
 *                  an instance of this class (this will not be checked).
 * @param number    The number to transform to a {@code double} value.
 * @param direction -1 to return the previous representable number,
 *                  +1 to return the next representable number, or
 *                   0 to return the number with no change.
 */
private static double doubleValue(final Class<?>        type,
                 final Comparable number,
                 final int     direction)
{
  assert (direction >= -1) && (direction <= +1) : direction;
  return org.geotools.resources.XMath.rool(type, ((Number)number).doubleValue(), direction);
}

代码示例来源:origin: org.geotools/gt2-widgets-swing

/**
 * Initialise l'itrateur.
 *
 * @param minimum           Valeur minimale de la premire graduation.
 * @param maximum           Valeur limite des graduations. La dernire
 *                          graduation n'aura pas ncessairement cette valeur.
 * @param visualLength      Longueur visuelle de l'axe sur laquelle tracer la graduation.
 *                          Cette longueur doit tre exprime en pixels ou en points.
 * @param visualTickSpacing Espace  laisser visuellement entre deux marques de graduation.
 *                          Cet espace doit tre exprim en pixels ou en points (1/72 de pouce).
 */
protected void init(final double minimum,
          final double maximum,
          final float  visualLength,
          final float  visualTickSpacing)
{
  final double logMin = XMath.log10(minimum);
  final double logMax = XMath.log10(maximum);
  super.init(logMin, logMax, visualLength, visualTickSpacing);
  scale  = (maximum-minimum) / (logMax-logMin);
  offset = minimum - scale*logMin;
}

代码示例来源:origin: org.geotools/gt2-metadata

/**
 * Try to remove at least {@code n} fraction digits in the string representation of
 * the specified value. This method try small changes to {@code value}, by adding or
 * substracting a maximum of 4 ulps. If there is no small change that remove at least
 * {@code n} fraction digits, then the value is returned unchanged. This method is
 * used for hiding rounding errors, like in conversions from radians to degrees.
 *
 * <P>Example: {@code XMath.fixRoundingError(-61.500000000000014, 12)} returns
 * {@code -61.5}.
 *
 * @param  value The value to fix.
 * @param  n The minimum amount of fraction digits.
 * @return The fixed value, or the unchanged {@code value} if there is no small change
 *         that remove at least {@code n} fraction digits.
 */
public static double fixRoundingError(final double value, int n) {
  double lower = value;
  double upper = value;
  n = countFractionDigits(value) - n;
  if (n > 0) {
    for (int i=0; i<4; i++) {
      if (countFractionDigits(lower = previous(lower)) <= n) return lower;
      if (countFractionDigits(upper = next    (upper)) <= n) return upper;
    }
  }
  return value;
}

代码示例来源:origin: org.geotools/gt2-metadata

/**
 * Round the specified value, providing that the difference between the original value and
 * the rounded value is not greater than the specified amount of floating point units. This
 * method can be used for hiding floating point error likes 2.9999999996.
 *
 * @param  value The value to round.
 * @param  flu The amount of floating point units.
 * @return The rounded value, of {@code value} if it was not close enough to an integer.
 */
public static double round(final double value, int flu) {
  final double target = Math.rint(value);
  if (value != target) {
    final boolean pos = (value < target);
    double candidate = value;
    while (--flu >= 0) {
      candidate = pos ? next(candidate) : previous(candidate);
      if (candidate == target) {
        return target;
      }
    }
  }
  return value;
}

代码示例来源:origin: org.geotools/gt-metadata

if (amount<0) {
    do {
      value = previous(value);
    } while (++amount != 0);
  } else if (amount!=0) {
    do {
      value = next(value);
    } while (--amount != 0);
  if (amount<0) {
    do {
      vf = previous(vf);
    } while (++amount != 0);
  } else if (amount!=0) {
    do {
      vf = next(vf);
    } while (--amount != 0);
if (isInteger(type)) {
  return value + amount;

代码示例来源:origin: org.geotools/gt2-metadata

/**
 * Formats the specified number.
 */
private String format(final Number value) {
  if (numberFormat == null) {
    numberFormat = NumberFormat.getNumberInstance(locale);
    numberFormat.setMinimumFractionDigits(0);
  }
  int precision = 0;
  if (!XMath.isInteger(value.getClass())) {
    precision = PRECISION;
    final double v = Math.abs(value.doubleValue());
    if (v > 0) {
      final int digits = (int) XMath.log10(v);
      if (Math.abs(digits) >= PRECISION) {
        // TODO: Switch to exponential notation when a convenient API will be available in J2SE.
        return value.toString();
      }
      if (digits >= 0) {
        precision -= digits;
      }
      precision = Math.max(0, PRECISION - precision);
    }
  }
  numberFormat.setMaximumFractionDigits(precision);
  return numberFormat.format(value);
}

代码示例来源:origin: org.geotools/gt2-widgets-swing

/**
 * Set the type and the range of valid values.
 */
public void setValueRange(Class classe, final Range range) {
  String type    = null;
  String minimum = null;
  String maximum = null;
  if (classe != null) {
    while (classe.isArray()) {
      classe = classe.getComponentType();
    }
    classe = XMath.primitiveToWrapper(classe);
    boolean isInteger = false;
    if (XMath.isReal(classe) || (isInteger=XMath.isInteger(classe))==true) {
      type = Vocabulary.format(isInteger ? VocabularyKeys.SIGNED_INTEGER_$1
                        : VocabularyKeys.REAL_NUMBER_$1,
                  new Integer(XMath.getBitCount(classe)));
    } else {
      type = Utilities.getShortName(classe);
    }
  }
  if (range != null) {
    minimum = format(range.getMinValue());
    maximum = format(range.getMaxValue());
  }
  this.type   .setText(type);
  this.minimum.setText(minimum);
  this.maximum.setText(maximum);
}

代码示例来源:origin: org.geotools/gt2-coverage

/**
 * Returns a string representation of this category.
 * The returned string is implementation dependent.
 * It is usually provided for debugging purposes.
 */
public String toString() {
  final StringBuffer buffer = new StringBuffer(Utilities.getShortClassName(this));
  buffer.append("(\"");
  buffer.append(name);
  buffer.append("\":[");
  if (Double.isNaN(minimum) && Double.isNaN(maximum)) {
    buffer.append("NaN(");
    buffer.append(Math.round(inverse.minimum));
    buffer.append("...");
    buffer.append(Math.round(inverse.maximum));
    buffer.append(')');
  } else {
    if (XMath.isInteger(getRange().getElementClass())) {
      buffer.append(Math.round(minimum));
      buffer.append("...");
      buffer.append(Math.round(maximum)); // Inclusive
    } else {
      buffer.append(minimum);
      buffer.append(" ... ");
      buffer.append(maximum); // Inclusive
    }
  }
  buffer.append("])");
  return buffer.toString();
}

代码示例来源:origin: org.geotools/gt2-widgets-swing

final double factor = XMath.pow10((int)Math.floor(XMath.log10(increment)));
increment /= factor;
if (Double.isNaN(increment) || Double.isInfinite(increment) || increment==0) {

代码示例来源:origin: org.geotools/gt2-coverageio

/**
 * Returns the user object associated as an instance of the specified class. If the value
 * returned by {@link #getUserObject()} is not of the expected type, then this method will
 * tries to parse it as a string.
 *
 * @param  type The expected class.
 * @return The user object, or {@code null} if none.
 * @throws ClassCastException if the user object can not be casted to the specified type.
 *
 * @see #getUserObject()
 * @see #setUserObject
 */
protected Object /*T*/ getUserObject(Class/*<T>*/ type) throws ClassCastException {
  type = XMath.primitiveToWrapper(type);
  Object value = getUserObject();
  if (value instanceof CharSequence) {
    if (Number.class.isAssignableFrom(type)) {
      value = XMath.valueOf(type, value.toString());
    } else {
      final Class component = XMath.primitiveToWrapper(type.getComponentType());
      if (Double.class.equals(component)) {
        value = parseSequence(value.toString(), false, false);
      } else if (Integer.class.equals(component)) {
        value = parseSequence(value.toString(), false, true);
      }
    }
  }
  return value; // TODO: use type.cast with Java 5.
}

代码示例来源:origin: org.geotools/gt-metadata

/**
 * Finds the least float greater than <var>f</var>.
 * If {@code NaN}, returns same value.
 *
 * @todo Remove this method when we will be allowed to use Java 6.
 */
public static float next(final float f) {
  return next(f, true);
}

代码示例来源:origin: org.geotools/gt2-widgets-swing

final double normalize = 0.25 * XMath.hypot(tmp.x, tmp.y);
tmp.x /= normalize;
tmp.y /= normalize;
adjusting = 0;
switch (XMath.sgn(Math.rint(tmp.x))) {
  case -1: adjusting |= WEST; break;
  case +1: adjusting |= EAST; break;
switch (XMath.sgn(Math.rint(tmp.y))) {
  case -1: adjusting |= NORTH; break;
  case +1: adjusting |= SOUTH; break;

代码示例来源:origin: org.geotools/gt2-widgets-swing

/**
 * Returns the axis length. This is the distance between starting point (@link #getP1 P1})
 * and end point ({@link #getP2 P2}). This length is usually measured in pixels or points
 * (1/72 of inch).
 */
public synchronized double getLength() {
  return XMath.hypot(getX1()-getX2(), getY1()-getY2());
}

代码示例来源:origin: org.geotools/gt2-widgets-swing

/**
 * Returns the most specific superclass for all the cell values.
 */
public Class getColumnClass(final int index) {
  if (index==0 || unsigned) {
    return Integer.class;
  }
  return XMath.primitiveToWrapper(table[index-1].getClass().getComponentType());
}

代码示例来源:origin: org.geotools/gt2-coverageio

PadValuesMask(final double[] padValues) {
  doubleValues  = new double[padValues.length];
  floatValues   = new float [padValues.length];
  NaNs          = new float [padValues.length];
  for (int i=0; i<padValues.length; i++) {
    floatValues[i] = (float) (doubleValues[i] = padValues[i]);
    NaNs[i] = XMath.toNaN(i);
  }
}

代码示例来源:origin: org.geotools/gt2-metadata

/**
 * Compute 10 power <var>x</var>.
 */
public static double pow10(final double x) {
  final int ix = (int) x;
  if (ix == x) {
    return pow10(ix);
  } else {
    return Math.pow(10, x);
  }
}

代码示例来源:origin: org.geotools/gt2-metadata

value = Boolean.valueOf(property);
} else if (Number.class.isAssignableFrom(type)) try {
  value = XMath.valueOf(type, property);
} catch (NumberFormatException e) {
  unexpectedException(e);

代码示例来源:origin: org.geotools/gt2-metadata

if (amount<0) {
    do {
      value = previous(value);
    } while (++amount != 0);
  } else if (amount!=0) {
    do {
      value = next(value);
    } while (--amount != 0);
  if (amount<0) {
    do {
      vf = previous(vf);
    } while (++amount != 0);
  } else if (amount!=0) {
    do {
      vf = next(vf);
    } while (--amount != 0);
if (isInteger(type)) {
  return value + amount;

代码示例来源:origin: org.geotools/gt-metadata

/**
 * Rounds the specified value, providing that the difference between the original value and
 * the rounded value is not greater than the specified amount of floating point units. This
 * method can be used for hiding floating point error likes 2.9999999996.
 *
 * @param  value The value to round.
 * @param  maxULP The maximal change allowed in ULPs (Unit in the Last Place).
 * @return The rounded value, of {@code value} if it was not close enough to an integer.
 */
public static double roundIfAlmostInteger(final double value, int maxULP) {
  final double target = Math.rint(value);
  if (value != target) {
    final boolean pos = (value < target);
    double candidate = value;
    while (--maxULP >= 0) {
      candidate = pos ? next(candidate) : previous(candidate);
      if (candidate == target) {
        return target;
      }
    }
  }
  return value;
}

代码示例来源:origin: org.geotools/gt2-coverage

final boolean adjustSamples = (XMath.isInteger(sType) && !XMath.isInteger(gType));
if ((adjustSamples ? gMinInc : sMinInc) != 0) {
  int swap = sMinInc;

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com