private int toInteger(double value) { return MathUtils.floorInt(value); }
private Map<Dimension, List<NodeContext>> buildTileDimensionMap(NodeContext[] outputNodeContexts) { final int mapSize = outputNodeContexts.length; Map<Dimension, List<NodeContext>> tileSizeMap = new HashMap<Dimension, List<NodeContext>>(mapSize); for (NodeContext outputNodeContext : outputNodeContexts) { Product targetProduct = outputNodeContext.getTargetProduct(); Dimension tileSize = targetProduct.getPreferredTileSize(); final int numXTiles = MathUtils.ceilInt(targetProduct.getSceneRasterWidth() / (double) tileSize.width); final int numYTiles = MathUtils.ceilInt(targetProduct.getSceneRasterHeight() / (double) tileSize.height); Dimension tileDim = new Dimension(numXTiles, numYTiles); List<NodeContext> nodeContextList = tileSizeMap.get(tileDim); if (nodeContextList == null) { nodeContextList = new ArrayList<NodeContext>(mapSize); tileSizeMap.put(tileDim, nodeContextList); } nodeContextList.add(outputNodeContext); } return tileSizeMap; }
public static double round(final double x, final double v) { return MathUtils.round(x, v); }
/** * First calls <code>Math.floor</code> with <code>x</code> and then crops the resulting value to the range * <code>min</code> to <code>max</code>. */ public static int floorAndCrop(final double x, final int min, final int max) { final int rx = floorInt(x); return crop(rx, min, max); // return (rx < min) ? min : (rx > max) ? max : rx; }
final List<Band> bandList = form.getBandList(currentView.getRaster().getName()); value = currentValue; final int firstBandIndex = MathUtils.floorInt(currentValue / (float) stepsPerTimespan); final int secondBandIndex = MathUtils.ceilInt(currentValue / (float) stepsPerTimespan); BandImageMultiLevelSource newSource = BandImageMultiLevelSource.create(bandList.get(secondBandIndex), ProgressMonitor.NULL);
public void testRounding() { assertEquals(1.0, MathUtils.computeRoundFactor(0.0, 100.0, 0), MathUtils.EPS); assertEquals(10.0, MathUtils.computeRoundFactor(0.0, 100.0, 1), MathUtils.EPS); assertEquals(100.0, MathUtils.computeRoundFactor(0.0, 100.0, 2), MathUtils.EPS); assertEquals(1000.0, MathUtils.computeRoundFactor(0.0, 100.0, 3), MathUtils.EPS); assertEquals(1000.0, MathUtils.computeRoundFactor(0.001, 0.002, 0), MathUtils.EPS); assertEquals(10000.0, MathUtils.computeRoundFactor(0.001, 0.002, 1), MathUtils.EPS); assertEquals(100000.0, MathUtils.computeRoundFactor(0.001, 0.002, 2), MathUtils.EPS); assertEquals(1000000.0, MathUtils.computeRoundFactor(0.001, 0.002, 3), MathUtils.EPS); assertEquals(10000000.0, MathUtils.computeRoundFactor(0.001, 0.002, 4), MathUtils.EPS); assertEquals(10.0, MathUtils.round(10.0, 1.0), MathUtils.EPS); assertEquals(10.0, MathUtils.round(10.0, 10.0), MathUtils.EPS); assertEquals(10.0, MathUtils.round(10.0, 100.0), MathUtils.EPS); assertEquals(10.0, MathUtils.round(10.0, 1000.0), MathUtils.EPS); assertEquals(10.0, MathUtils.round(10.1234567, 1.0), MathUtils.EPS); assertEquals(10.1, MathUtils.round(10.1234567, 10.0), MathUtils.EPS); assertEquals(10.12, MathUtils.round(10.1234567, 100.0), MathUtils.EPS); assertEquals(10.123, MathUtils.round(10.1234567, 1000.0), MathUtils.EPS); assertEquals(10.1235, MathUtils.round(10.1234567, 10000.0), MathUtils.EPS); assertEquals(10.12346, MathUtils.round(10.1234567, 100000.0), MathUtils.EPS); assertEquals(10.123457, MathUtils.round(10.1234567, 1000000.0), MathUtils.EPS); assertEquals(10.1234567, MathUtils.round(10.1234567, 10000000.0), MathUtils.EPS); }
/** * First calls <code>Math.round</code> with <code>x</code> and then crops the resulting value to the range * <code>min</code> to <code>max</code>. */ public static int roundAndCrop(final float x, final int min, final int max) { final int rx = Math.round(x); return crop(rx, min, max); // return (rx < min) ? min : (rx > max) ? max : rx; }
private static float interpolateSperical(float wx, float wy, float d00, float d10, float d01, float d11) { double r00 = Math.toRadians(d00); double s00 = Math.sin(r00); double c00 = Math.cos(r00); double r01 = Math.toRadians(d01); double s01 = Math.sin(r01); double c01 = Math.cos(r01); double r10 = Math.toRadians(d10); double s10 = Math.sin(r10); double c10 = Math.cos(r10); double r11 = Math.toRadians(d11); double s11 = Math.sin(r11); double c11 = Math.cos(r11); double sinAngle = MathUtils.interpolate2D(wx, wy, s00, s10, s01, s11); double cosAngle = MathUtils.interpolate2D(wx, wy, c00, c10, c01, c11); return (float) (MathUtils.RTOD * Math.atan2(sinAngle, cosAngle)); } }
static int getZoneIndex(float longitude) { final float zoneIndex = ((longitude + 180.0f) / 6.0f - 0.5f) + 1; return MathUtils.roundAndCrop(zoneIndex, MIN_UTM_ZONE, MAX_UTM_ZONE); }
private static boolean equalsLatLon(final GeoPos pos1, final GeoPos pos2, final float eps) { return MathUtils.equalValues(pos1.lat, pos2.lat, eps) && MathUtils.equalValues(pos1.lon, pos2.lon, eps); }
/** * @param sphereRadius the radius of the sphere * @param lambda1_deg the lambda angle of point one, in degree * @param phi1_deg the phi angle of point one, in degree * @param lambda2_deg the lambda angle of point two, in degree * @param phi2_deg the phi angle of point one, in degree * * @return the distance described by the two given points (lambda/phi) on the * top of sphere described by the given radius */ public final static double sphereDistanceDeg(final double sphereRadius, final double lambda1_deg, final double phi1_deg, final double lambda2_deg, final double phi2_deg) { final double conv = MathUtils.DTOR; return sphereDistance(sphereRadius, conv * lambda1_deg, conv * phi1_deg, conv * lambda2_deg, conv * phi2_deg); }
/** * Computes a rounding factor suitable for the given value range and number of significant digits. * * @param min the minimum value of the range * @param max the maximum value of the range * @param numDigits the number of significant digits, must be <code>>=0</code> * * @return the rounded value, always a power to the base 10 * * @see #round(float, float) */ public static float computeRoundFactor(final float min, final float max, final int numDigits) { return (float) computeRoundFactor((double) min, (double) max, numDigits); }
final double minValue = imageInfo.getColorPaletteDef().getMinDisplaySample(); final double maxValue = imageInfo.getColorPaletteDef().getMaxDisplaySample(); double roundFactor = MathUtils.computeRoundFactor(minValue, maxValue, 2); for (int i = 0; i < n; i++) { ColorPaletteDef.Point slider = getGradationCurvePointAt(i); labels[i] = String.valueOf(MathUtils.round(slider.getSample(), roundFactor)); labelWidths[i] = fontMetrics.stringWidth(labels[i]);
/** * First calls <code>Math.round</code> with <code>value</code> and then crops the resulting value to the range * <code>min</code> to <code>max</code>. * @param value the value to round and crop * @param min the minimum value of the crop range * @param max the maximum value of the crop range * * @return the rounded and cropped value */ public static long roundAndCrop(final double value, final long min, final long max) { final long rx = Math.round(value); return crop(rx, min, max); }
private float interpolate(int x0, int y0, float wx, float wy, float[] data, int latLon) { final float min = (latLon == LAT) ? LAT_MIN : LON_MIN; final float max = (latLon == LAT) ? LAT_MAX : LON_MAX; final int x1 = x0 + 1; final int y1 = y0 + 1; final float d00 = data[width * y0 + x0]; if (d00 >= min && d00 <= max) { final float d10 = data[width * y0 + x1]; if (d10 >= min && d10 <= max) { final float d01 = data[width * y1 + x0]; if (d01 >= min && d01 <= max) { final float d11 = data[width * y1 + x1]; if (d11 >= min && d11 <= max) { if (latLon == LAT) { return MathUtils.interpolate2D(wx, wy, d00, d10, d01, d11); } else { return GeoCodingFactory.interpolateLon(wx, wy, d00, d10, d01, d11); } } } } } return d00; }
private static Color computeColor(double sample, BorderSamplesAndColors boSaCo) { final double f = (sample - boSaCo.sample1) / (boSaCo.sample2 - boSaCo.sample1); final double r1 = boSaCo.color1.getRed(); final double r2 = boSaCo.color2.getRed(); final double g1 = boSaCo.color1.getGreen(); final double g2 = boSaCo.color2.getGreen(); final double b1 = boSaCo.color1.getBlue(); final double b2 = boSaCo.color2.getBlue(); final double a1 = boSaCo.color1.getAlpha(); final double a2 = boSaCo.color2.getAlpha(); final int red = (int) MathUtils.roundAndCrop(r1 + f * (r2 - r1), 0L, 255L); final int green = (int) MathUtils.roundAndCrop(g1 + f * (g2 - g1), 0L, 255L); final int blue = (int) MathUtils.roundAndCrop(b1 + f * (b2 - b1), 0L, 255L); final int alpha = (int) MathUtils.roundAndCrop(a1 + f * (a2 - a1), 0L, 255L); return new Color(red, green, blue, alpha); }
if (MathUtils.equalValues(pixelSize, 0.0f)) { pixelSize = 1.0f;
public void testSphereDistance_45degreeAcrossTheEquator() { final double meanEarthRadius_km = 6371.0; final double meanEarthDiameter_km = meanEarthRadius_km * 2; final double sphereOutline = meanEarthDiameter_km * Math.PI; final double lam1_rad = MathUtils.DTOR * 45.0; final double phi1_rad = MathUtils.DTOR * -5.0; final double lam2_rad = MathUtils.DTOR * 55.0; final double phi2_rad = MathUtils.DTOR * 5.0; // expected final double x1 = Math.cos(lam1_rad) * Math.cos(phi1_rad); final double y1 = Math.sin(lam1_rad) * Math.cos(phi1_rad); final double z1 = Math.sin(phi1_rad); final double x2 = Math.cos(lam2_rad) * Math.cos(phi2_rad); final double y2 = Math.sin(lam2_rad) * Math.cos(phi2_rad); final double z2 = Math.sin(phi2_rad); final double cosdelta = x1 * x2 + y1 * y2 + z1 * z2; final double expected = sphereOutline / 360 * (MathUtils.RTOD * Math.acos(cosdelta)); // method under test final double distance = MathUtils.sphereDistance(meanEarthRadius_km, lam1_rad, phi1_rad, lam2_rad, phi2_rad); assertEquals(expected, distance, 1.0e-11); }
public String[] createTickmarkTexts() { double roundFactor = MathUtils.computeRoundFactor(getMinValue(), getMaxValue(), 3); return createTickmarkTexts(getMinValue(), getMaxValue(), getNumMajorTicks(), roundFactor); }