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 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); }
private Color computeColor(double sample, double sample1, double sample2, Color color1, Color color2) { final double f = (sample - sample1) / (sample2 - sample1); final double r1 = color1.getRed(); final double r2 = color2.getRed(); final double g1 = color1.getGreen(); final double g2 = color2.getGreen(); final double b1 = color1.getBlue(); final double b2 = color2.getBlue(); final double a1 = color1.getAlpha(); final double a2 = 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); }
public void testRoundAndCropLong() { assertEquals(4L, MathUtils.roundAndCrop(4.3d, 1L, 7L)); assertEquals(5L, MathUtils.roundAndCrop(4.3d, 5L, 7L)); assertEquals(3L, MathUtils.roundAndCrop(4.3d, 1L, 3L)); }
public void testRoundAndCropInt() { assertEquals(4L, MathUtils.roundAndCrop(4.3f, 1, 7)); assertEquals(5L, MathUtils.roundAndCrop(4.3f, 5, 7)); assertEquals(3L, MathUtils.roundAndCrop(4.3f, 1, 3)); }
int yy = y1; for (int x = x1 + 1; x <= x2; x++) { int i = MathUtils.roundAndCrop((255.9f * (x - x1)) / (x2 - x1), 0, 255); int y = y1 + ((y2 - y1) * (gammaCurve[i] & 0xff)) / 256; g2d.drawLine(xx, yy, x, y);