/** * First get rid of any rounding errors before passing the value to {@link Math#round(double)}; * * @param val * to be rounded * @return the {@link Math#round(double)} of the cleaned value. */ private final double round( double val ) { val = removeImprecisions( val ); return Math.round( val ); }
/** * First get rid of any rounding errors before passing the value to {@link Math#ceil(double)}; * * @param val * to be ceiled * @return the {@link Math#ceil(double)} of the cleaned value. */ private final double ceil( double val ) { val = removeImprecisions( val ); return Math.ceil( val ); }
/** * First get rid of any rounding errors before passing the value to {@link Math#floor(double)}; * * @param val * to be floored * @return the {@link Math#floor(double)} of the cleaned value. */ private final double floor( double val ) { val = removeImprecisions( val ); return Math.floor( val ); }
/** * Return the raster coordinate denoted by the given world coordinate. This method is CENTER and OUTER aware. * * @param worldX * x position in the world coordinate system, for which raster coordinates should be calculated. * @param worldY * y position in the world coordinate system, for which raster coordinates should be calculated. * @return the raster coordinate which the given world coordinate maps to. */ public double[] getRasterCoordinateUnrounded( double worldX, double worldY ) { double[] incoming = new double[] { worldX, worldY }; double[] result = new double[2]; invTransform.transform( incoming, 0, result, 0, 1 ); result[0] = removeImprecisions( result[0] ); result[1] = removeImprecisions( result[1] ); if ( location == CENTER ) { // add 0.5, because the world origin has a center offset of 0.5 result[0] += 0.5; result[1] += 0.5; } return result; }
/** * Return the world coordinate denoted by the given raster position. This method is CENTER and OUTER aware. * * @param rasterX * x position in the raster for which world coordinates should be calculated. * @param rasterY * y position in the raster for which world coordinates should be calculated. * @return the world coordinate which the given raster coordinate maps to. */ public double[] getWorldCoordinate( double rasterX, double rasterY ) { double[] result = new double[2]; double[] input = new double[] { rasterX, rasterY }; if ( location == CENTER ) { // if the origin is located on the center of the pixel raster coordinates should be substracted 0.5, or // world coordinates must be subtracted half a resolution. input[0] -= 0.5; input[1] -= 0.5; } transform.transform( input, 0, result, 0, 1 ); // get rid of rounding errors result[0] = removeImprecisions( result[0] ); result[1] = removeImprecisions( result[1] ); return result; }