### Question:
SubscenePixelLocator extends AbstractPixelLocator { @Override public boolean getPixelLocation(double lon, double lat, Point2D p) { if (lon == cachedLon && lat == cachedLat) { p.setLocation(cachedPoint); return true; } final int w = getLatSource().getWidth(); final int h = getLatSource().getHeight(); final double cosineFactor = Math.cos(lat * DEG_TO_RAD); int bestX = 0; int bestY = 0; double minDelta = Double.MAX_VALUE; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if (getLatSource().isFillValue(x, y)) { continue; } if (getLonSource().isFillValue(x, y)) { continue; } final double sourceLat = getLat(x, y) + 90.0; final double sourceLon = getLon(x, y) + 180.0; final double delta = (sourceLat - (lat + 90.0)) * (sourceLat - (lat + 90.0)) + (sourceLon - (lon + 180.0)) * (sourceLon - (lon + 180.0)) * cosineFactor; if (delta < minDelta) { bestX = x; bestY = y; minDelta = delta; } } } p.setLocation(bestX, bestY); cachedLat = lat; cachedLon = lon; cachedPoint = p; return true; } private  SubscenePixelLocator(SampleSource lonSource, SampleSource latSource); @Override boolean getPixelLocation(double lon, double lat, Point2D p);  }### Answer:
@Test public void testGetPixelLocation() { final Point2D.Double pixelLocation = new Point2D.Double(); assertTrue(locator.getPixelLocation(10, 20, pixelLocation)); assertEquals(0.0, pixelLocation.getX(), 1e-8); assertEquals(0.0, pixelLocation.getY(), 1e-8); assertTrue(locator.getPixelLocation(11, 21, pixelLocation)); assertEquals(1.0, pixelLocation.getX(), 1e-8); assertEquals(1.0, pixelLocation.getY(), 1e-8); }
@Test public void testGetPixelLocation_cachedPoint() { final Point2D.Double pixelLocation = new Point2D.Double(); assertTrue(locator.getPixelLocation(10, 20, pixelLocation)); assertEquals(0.0, pixelLocation.getX(), 1e-8); assertEquals(0.0, pixelLocation.getY(), 1e-8); assertTrue(locator.getPixelLocation(10, 20, pixelLocation)); assertEquals(0.0, pixelLocation.getX(), 1e-8); assertEquals(0.0, pixelLocation.getY(), 1e-8); }