CoordinateConverter { public List<Vector> toLonLat(List<Vector> pixels) { return pixels.stream() .map(vector -> basis.multiply(vector).add(boundary.get(0))) .collect(Collectors.toList()); } CoordinateConverter(BufferedImage image, List<Vector> boundary);  CoordinateConverter(int width, int height, List<Vector> boundary); List<Vector> toPixels(List<Vector> lonLats); List<Vector> toLonLat(List<Vector> pixels);  }
@Test public void testToLonLat() { List<Vector> vectors = new ArrayList<>(); vectors.add(new BasicVector(new double[] {-30, 30})); vectors.add(new BasicVector(new double[] {30, 30})); vectors.add(new BasicVector(new double[] {30, -30})); vectors.add(new BasicVector(new double[] {-30, -30})); CoordinateConverter coordinateConverter = new CoordinateConverter(1024, 768, vectors); List<Vector> pixels = new LinkedList<>(); pixels.add(new BasicVector(new double[] {1024 / 3, 768 / 3})); pixels.add(new BasicVector(new double[] {2 * 1024 / 3, 768 / 3})); pixels.add(new BasicVector(new double[] {2 * 1024 / 3, 2 * 768 / 3})); pixels.add(new BasicVector(new double[] {1024 / 3, 2 * 768 / 3})); List<Vector> newLatLong = coordinateConverter.toLonLat(pixels); double xOneThird = 60.0 * (341.0 / 1024.0); double xTwoThirds = 60.0 * (682.0 / 1024.0); double yOneThird = 60.0 * (256.0 / 768.0); double yTwoThirds = 60.0 * (512.0 / 768.0); assertThat(newLatLong.get(0).get(0), Matchers.closeTo(-30 + xOneThird, 0.01)); assertThat(newLatLong.get(0).get(1), Matchers.closeTo(-30 + yTwoThirds, 0.01)); assertThat(newLatLong.get(1).get(0), Matchers.closeTo(-30 + xTwoThirds, 0.01)); assertThat(newLatLong.get(1).get(1), Matchers.closeTo(-30 + yTwoThirds, 0.01)); assertThat(newLatLong.get(2).get(0), Matchers.closeTo(-30 + xTwoThirds, 0.01)); assertThat(newLatLong.get(2).get(1), Matchers.closeTo(-30 + yOneThird, 0.01)); assertThat(newLatLong.get(3).get(0), Matchers.closeTo(-30 + xOneThird, 0.01)); assertThat(newLatLong.get(3).get(1), Matchers.closeTo(-30 + yOneThird, 0.01)); }