Revision: 6178 http://sourceforge.net/p/jump-pilot/code/6178 Author: ma15569 Date: 2019-04-09 04:54:22 +0000 (Tue, 09 Apr 2019) Log Message: ----------- a) moved a method to MathUtil class b) updated generic raster algorithm class
Modified Paths: -------------- core/trunk/src/com/vividsolutions/jump/util/MathUtil.java core/trunk/src/org/openjump/core/rasterimage/algorithms/GenericRasterAlgorithm.java Modified: core/trunk/src/com/vividsolutions/jump/util/MathUtil.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/util/MathUtil.java 2019-04-09 04:49:36 UTC (rev 6177) +++ core/trunk/src/com/vividsolutions/jump/util/MathUtil.java 2019-04-09 04:54:22 UTC (rev 6178) @@ -1,4 +1,3 @@ - /* * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI * for visualizing and manipulating spatial features with geometry and attributes. @@ -33,7 +32,6 @@ package com.vividsolutions.jump.util; - /** * Additional math utilities. * @see Math @@ -40,7 +38,7 @@ */ public class MathUtil { public MathUtil() { - } + } public static double orderOfMagnitude(double x) { return base10Log(x); @@ -51,7 +49,8 @@ } public static int mostSignificantDigit(double x) { - return (int) (x / Math.pow(10, Math.floor(MathUtil.orderOfMagnitude(x)))); + return (int) (x / Math + .pow(10, Math.floor(MathUtil.orderOfMagnitude(x)))); } /** @@ -63,4 +62,23 @@ public static double avg(double a, double b) { return (a + b) / 2d; } + + /** + * round a double to <places> number + * for instance round(123.4567 , 2) -> 123.45 + * @param value + * @param places + * @return + */ + + public static double round(double value, int places) { + if (places < 0) { + throw new IllegalArgumentException(); + } + + final long factor = (long) Math.pow(10, places); + value = value * factor; + final long tmp = Math.round(value); + return (double) tmp / factor; + } } Modified: core/trunk/src/org/openjump/core/rasterimage/algorithms/GenericRasterAlgorithm.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/algorithms/GenericRasterAlgorithm.java 2019-04-09 04:49:36 UTC (rev 6177) +++ core/trunk/src/org/openjump/core/rasterimage/algorithms/GenericRasterAlgorithm.java 2019-04-09 04:54:22 UTC (rev 6178) @@ -29,6 +29,7 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jump.I18N; +import com.vividsolutions.jump.util.MathUtil; import com.vividsolutions.jump.workbench.JUMPWorkbench; import com.vividsolutions.jump.workbench.model.Category; import com.vividsolutions.jump.workbench.ui.Viewport; @@ -208,7 +209,7 @@ for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { final double value = ras.getSampleDouble(x, y, band); - raster.setSample(x, y, band, round(value, n)); + raster.setSample(x, y, band, MathUtil.round(value, n)); } } final RasterImageIO rasterImageIO = new RasterImageIO(); @@ -365,17 +366,6 @@ } - public double round(double value, int places) { - if (places < 0) { - throw new IllegalArgumentException(); - } - - final long factor = (long) Math.pow(10, places); - value = value * factor; - final long tmp = Math.round(value); - return (double) tmp / factor; - } - /** * Load a file into the workbench * @param inputFile _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel