private static void doOne(GridCoordinate2D g2d, double wantLat, double wantLon) { int[] result = new int[2]; if (g2d.findCoordElementForce(wantLat, wantLon, result)) System.out.printf("Brute (%f %f) == (%d %d) %n", wantLat, wantLon, result[0], result[1]); else { System.out.printf("Brute (%f %f) FAIL", wantLat, wantLon); return; } if (g2d.findCoordElement(wantLat, wantLon, result)) System.out.printf("(%f %f) == (%d %d) %n", wantLat, wantLon, result[0], result[1]); else System.out.printf("(%f %f) FAIL %n", wantLat, wantLon); System.out.printf("----------------------------------------%n"); }
/** * 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"); }
private static void doOne(GridCoordinate2D g2d, double wantLat, double wantLon) { int[] result = new int[2]; if (g2d.findCoordElementForce(wantLat, wantLon, result)) System.out.printf("Brute (%f %f) == (%d %d) %n", wantLat, wantLon, result[0], result[1]); else { System.out.printf("Brute (%f %f) FAIL", wantLat, wantLon); return; } if (g2d.findCoordElement(wantLat, wantLon, result)) System.out.printf("(%f %f) == (%d %d) %n", wantLat, wantLon, result[0], result[1]); else System.out.printf("(%f %f) FAIL %n", wantLat, wantLon); System.out.printf("----------------------------------------%n"); }
/** * 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"); }
private static void doOne(GridCoordinate2D g2d, double wantLat, double wantLon) { int[] result = new int[2]; if (g2d.findCoordElementForce(wantLat, wantLon, result)) System.out.printf("Brute (%f %f) == (%d %d) %n", wantLat, wantLon, result[0], result[1]); else { System.out.printf("Brute (%f %f) FAIL", wantLat, wantLon); return; } if (g2d.findCoordElement(wantLat, wantLon, result)) System.out.printf("(%f %f) == (%d %d) %n", wantLat, wantLon, result[0], result[1]); else System.out.printf("(%f %f) FAIL %n", wantLat, wantLon); System.out.printf("----------------------------------------%n"); }
/** * 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"); }
g2d = new GridCoordinate2D((CoordinateAxis2D) horizYaxis, (CoordinateAxis2D) horizXaxis); int[] result2 = new int[2]; boolean found = g2d.findCoordElement(y_coord, x_coord, result2); if (found) { result[0] = result2[1];
g2d = new GridCoordinate2D((CoordinateAxis2D) horizYaxis, (CoordinateAxis2D) horizXaxis); int[] result2 = new int[2]; boolean found = g2d.findCoordElement(y_coord, x_coord, result2); if (found) { result[0] = result2[1];
g2d = new GridCoordinate2D((CoordinateAxis2D) horizYaxis, (CoordinateAxis2D) horizXaxis); int[] result2 = new int[2]; boolean found = g2d.findCoordElement(y_coord, x_coord, result2); if (found) { result[0] = result2[1];