/** * Given a point in x,y coordinate space, find the x,y index in the coordinate system. * If outside the range, the closest point is returned, eg, 0 or n-1 depending on if the coordinate is too small or too large. * * @param x_coord position in x coordinate space. * @param y_coord position in y coordinate space. * @param result put result in here, may be null * @return int[2], 0=x,1=y indices in the coordinate system of the point. */ @Override public int[] findXYindexFromCoordBounded(double x_coord, double y_coord, int[] result) { if (result == null) result = new int[2]; if ((horizXaxis instanceof CoordinateAxis1D) && (horizYaxis instanceof CoordinateAxis1D)) { result[0] = ((CoordinateAxis1D) horizXaxis).findCoordElementBounded(x_coord); result[1] = ((CoordinateAxis1D) horizYaxis).findCoordElementBounded(y_coord); return result; } else if ((horizXaxis instanceof CoordinateAxis2D) && (horizYaxis instanceof CoordinateAxis2D)) { if (g2d == null) g2d = new GridCoordinate2D((CoordinateAxis2D) horizYaxis, (CoordinateAxis2D) horizXaxis); int[] result2 = new int[2]; g2d.findCoordElement(y_coord, x_coord, result2); // returns best guess result[0] = result2[1]; result[1] = result2[0]; return result; } // cant happen throw new IllegalStateException("GridCoordSystem.findXYindexFromCoord"); }
/** * Given a point in x,y coordinate space, find the x,y index in the coordinate system. * If outside the range, the closest point is returned, eg, 0 or n-1 depending on if the coordinate is too small or too large. * * @param x_coord position in x coordinate space. * @param y_coord position in y coordinate space. * @param result put result in here, may be null * @return int[2], 0=x,1=y indices in the coordinate system of the point. */ @Override public int[] findXYindexFromCoordBounded(double x_coord, double y_coord, int[] result) { if (result == null) result = new int[2]; if ((horizXaxis instanceof CoordinateAxis1D) && (horizYaxis instanceof CoordinateAxis1D)) { result[0] = ((CoordinateAxis1D) horizXaxis).findCoordElementBounded(x_coord); result[1] = ((CoordinateAxis1D) horizYaxis).findCoordElementBounded(y_coord); return result; } else if ((horizXaxis instanceof CoordinateAxis2D) && (horizYaxis instanceof CoordinateAxis2D)) { if (g2d == null) g2d = new GridCoordinate2D((CoordinateAxis2D) horizYaxis, (CoordinateAxis2D) horizXaxis); int[] result2 = new int[2]; g2d.findCoordElement(y_coord, x_coord, result2); // returns best guess result[0] = result2[1]; result[1] = result2[0]; return result; } // cant happen throw new IllegalStateException("GridCoordSystem.findXYindexFromCoord"); }
/** * Given a point in x,y coordinate space, find the x,y index in the coordinate system. * If outside the range, the closest point is returned, eg, 0 or n-1 depending on if the coordinate is too small or too large. * * @param x_coord position in x coordinate space. * @param y_coord position in y coordinate space. * @param result put result in here, may be null * @return int[2], 0=x,1=y indices in the coordinate system of the point. */ @Override public int[] findXYindexFromCoordBounded(double x_coord, double y_coord, int[] result) { if (result == null) result = new int[2]; if ((horizXaxis instanceof CoordinateAxis1D) && (horizYaxis instanceof CoordinateAxis1D)) { result[0] = ((CoordinateAxis1D) horizXaxis).findCoordElementBounded(x_coord); result[1] = ((CoordinateAxis1D) horizYaxis).findCoordElementBounded(y_coord); return result; } else if ((horizXaxis instanceof CoordinateAxis2D) && (horizYaxis instanceof CoordinateAxis2D)) { if (g2d == null) g2d = new GridCoordinate2D((CoordinateAxis2D) horizYaxis, (CoordinateAxis2D) horizXaxis); int[] result2 = new int[2]; g2d.findCoordElement(y_coord, x_coord, result2); // returns best guess result[0] = result2[1]; result[1] = result2[0]; return result; } // cant happen throw new IllegalStateException("GridCoordSystem.findXYindexFromCoord"); }
int index = bounded ? axis1D.findCoordElementBounded(v) : axis1D.findCoordElement(v); System.out.printf(" %5.1f, index= %2d %n", v, index); if (expect != null) { if (expect[i] != index) index = bounded ? axis1D.findCoordElementBounded(v) : axis1D.findCoordElement(v); for (int i = 0; i < vals.length; i++) { double v = vals[i]; int index = bounded ? axis1D.findCoordElementBounded(v) : axis1D.findCoordElement(v); System.out.printf("%2d, ", index);
CoordinateAxis1D yaxis1 = (CoordinateAxis1D) yaxis; int minxIndex = xaxis1.findCoordElementBounded(minx); int minyIndex = yaxis1.findCoordElementBounded(miny); int maxxIndex = xaxis1.findCoordElementBounded(maxx); int maxyIndex = yaxis1.findCoordElementBounded(maxy);
CoordinateAxis1D yaxis1 = (CoordinateAxis1D) yaxis; int minxIndex = xaxis1.findCoordElementBounded(minx); int minyIndex = yaxis1.findCoordElementBounded(miny); int maxxIndex = xaxis1.findCoordElementBounded(maxx); int maxyIndex = yaxis1.findCoordElementBounded(maxy);
CoordinateAxis1D yaxis1 = (CoordinateAxis1D) yaxis; int minxIndex = xaxis1.findCoordElementBounded(minx); int minyIndex = yaxis1.findCoordElementBounded(miny); int maxxIndex = xaxis1.findCoordElementBounded(maxx); int maxyIndex = yaxis1.findCoordElementBounded(maxy);