protected boolean updateForBufferDimensions(Projection proj){
  int currentRotBufferWidth=rotBufferWidth;
  int currentRotBufferHeight=rotBufferHeight;
  Point2D center=proj.getCenter();
  Point2D ul=proj.getUpperLeft();
  Point2D lr=proj.getLowerRight();
  Geo centerGeo=new Geo(center.getY(),center.getX());
  Geo ulGeo=new Geo(ul.getY(),ul.getX());
  Geo lrGeo=new Geo(lr.getY(),lr.getX());
  double dist=Math.max(centerGeo.distance(ulGeo),centerGeo.distance(lrGeo));
  Geo N=Geo.offset(centerGeo,dist,0);
  Geo S=Geo.offset(centerGeo,dist,Math.PI);
  Geo E=Geo.offset(centerGeo,dist,Math.PI / 2.0);
  Geo W=Geo.offset(centerGeo,dist,-Math.PI / 2);
  Point2D newUL=new Point2D.Double(W.getLongitude(),N.getLatitude());
  Point2D newLR=new Point2D.Double(E.getLongitude(),S.getLatitude());
  Point2D newULPix=proj.forward(newUL);
  Point2D newLRPix=proj.forward(newLR);
  int reqRotBufferHeight=(int)Math.abs(newLRPix.getY() - newULPix.getY());
  int reqRotBufferWidth=(int)Math.abs(newLRPix.getX() - newULPix.getX());
  boolean needNewHeightImage=reqRotBufferHeight > currentRotBufferHeight || reqRotBufferHeight < .9 * currentRotBufferHeight;
  boolean needNewWidthImage=reqRotBufferWidth > currentRotBufferWidth || currentRotBufferWidth < .9 * currentRotBufferWidth;
  boolean bufferImageResized=false;
  if (needNewHeightImage || needNewWidthImage) {
    this.rotImage=new BufferedImage(reqRotBufferWidth,reqRotBufferHeight,BufferedImage.TYPE_INT_ARGB);
    rotBufferWidth=reqRotBufferWidth;
    rotBufferHeight=reqRotBufferHeight;
    bufferImageResized=true;
  }
  rotProjection=projectionFactory.makeProjection(proj.getClass(),center,proj.getScale(),rotBufferWidth,rotBufferHeight);
  this.rotCenter=rotProjection.forward(center);
  this.rotXOffset=(rotProjection.getWidth() - proj.getWidth()) / 2;
  this.rotYOffset=(rotProjection.getHeight() - proj.getHeight()) / 2;
  return bufferImageResized;
}

protected boolean updateForBufferDimensions ( Projection proj ) { int currentRotBufferWidth = rotBufferWidth ; int currentRotBufferHeight = rotBufferHeight ; Point2D center = proj . getCenter ( ) ; Point2D ul = proj . getUpperLeft ( ) ; Point2D lr = proj . getLowerRight ( ) ; Geo centerGeo = new Geo ( center . getY ( ) , center . getX ( ) ) ; Geo ulGeo = new Geo ( ul . getY ( ) , ul . getX ( ) ) ; Geo lrGeo = new Geo ( lr . getY ( ) , lr . getX ( ) ) ; double dist = Math . max ( centerGeo . distance ( ulGeo ) , centerGeo . distance ( lrGeo ) ) ; Geo N = Geo . offset ( centerGeo , dist , 0 ) ; Geo S = Geo . offset ( centerGeo , dist , Math . PI ) ; Geo E = Geo . offset ( centerGeo , dist , Math . PI / 2.0 ) ; Geo W = Geo . offset ( centerGeo , dist , - Math . PI / 2 ) ; Point2D newUL = new Point2D . Double ( W . getLongitude ( ) , N . getLatitude ( ) ) ; Point2D newLR = new Point2D . Double ( E . getLongitude ( ) , S . getLatitude ( ) ) ; Point2D newULPix = proj . forward ( newUL ) ; Point2D newLRPix = proj . forward ( newLR ) ; int reqRotBufferHeight = ( int ) Math . abs ( newLRPix . getY ( ) - newULPix . getY ( ) ) ; int reqRotBufferWidth = ( int ) Math . abs ( newLRPix . getX ( ) - newULPix . getX ( ) ) ; boolean needNewHeightImage = reqRotBufferHeight > currentRotBufferHeight || reqRotBufferHeight < .9 * currentRotBufferHeight ; boolean needNewWidthImage = reqRotBufferWidth > currentRotBufferWidth || currentRotBufferWidth < .9 * currentRotBufferWidth ; boolean bufferImageResized = false ; if ( needNewHeightImage || needNewWidthImage ) { this . rotImage = new BufferedImage ( reqRotBufferWidth , reqRotBufferHeight , BufferedImage . TYPE_INT_ARGB ) ; rotBufferWidth = reqRotBufferWidth ; rotBufferHeight = reqRotBufferHeight ; bufferImageResized = true ; } rotProjection = projectionFactory . makeProjection ( proj . getClass ( ) , center , proj . getScale ( ) , rotBufferWidth , rotBufferHeight ) ; this . rotCenter = rotProjection . forward ( center ) ; this . rotXOffset = ( rotProjection . getWidth ( ) - proj . getWidth ( ) ) / 2 ; this . rotYOffset = ( rotProjection . getHeight ( ) - proj . getHeight ( ) ) / 2 ; return bufferImageResized ; }
we ' re going to try to do buffering with a image that will cover all of the corners when the map is rotated . we ' ll measure the ground distance from the center of the projection / map to each corner , and take the longest to create a bounding circle . the nsew of that bounding circle ( as a bounding box ) makes up the buffered image pixel bounds , and the inverse projected coordinates of that box should be returned as upper left and lower right coordinates when those methods are called . the projection of that box should be the same as the current projection , except for the new width and height . because the height and width are different for the buffered image , we ' re going to have to translate it before it is rotated . we can probably just tack on an additional translate to the rot . that difference will be 1 / 2 the difference of the height and width between the rot image and the original projection ( mapbean dimensions ) .
