public static Window getRectangleAroundPoint ( Window activeRegion , double x , double y ) { double minx = activeRegion . getRectangle ( ) . getBounds2D ( ) . getMinX ( ) ; double ewres = activeRegion . getWEResolution ( ) ; double snapx = minx + ( Math . round ( ( x - minx ) / ewres ) * ewres ) ; double miny = activeRegion . getRectangle ( ) . getBounds2D ( ) . getMinY ( ) ; double nsres = activeRegion . getNSResolution ( ) ; double snapy = miny + ( Math . round ( ( y - miny ) / nsres ) * nsres ) ; double xmin = 0.0 ; double xmax = 0.0 ; double ymin = 0.0 ; double ymax = 0.0 ; if ( x >= snapx ) { xmin = snapx ; xmax = xmin + ewres ; } else { xmax = snapx ; xmin = xmax - ewres ; } if ( y <= snapy ) { ymax = snapy ; ymin = ymax - nsres ; } else { ymin = snapy ; ymax = ymin + nsres ; } // why do I have to put ymin, Rectangle requires the upper left // corner?????!!!! Is it a BUG // in the Rectangle2D class? or docu? // Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, ewres, nsres); return new Window ( xmin , xmax , ymin , ymax , 1 , 1 ) ; }
return the rectangle of the cell of the active region that surrounds the given coordinates