protected Rectangle convertToDiagramBounds ( Rectangle2D modelBounds ) { double xCenter = modelBounds . getCenterX ( ) ; double yCenter = modelBounds . getCenterY ( ) ; double modelWidth = modelBounds . getWidth ( ) ; double modelHeight = modelBounds . getHeight ( ) ; double scale = rendererModel . getParameter ( Scale . class ) . getValue ( ) ; double zoom = rendererModel . getParameter ( ZoomFactor . class ) . getValue ( ) ; Point2d screenCoord = this . toScreenCoordinates ( xCenter , yCenter ) ; // special case for 0 or 1 atoms if ( modelWidth == 0 && modelHeight == 0 ) { return new Rectangle ( ( int ) screenCoord . x , ( int ) screenCoord . y , 0 , 0 ) ; } double margin = rendererModel . getParameter ( Margin . class ) . getValue ( ) ; int width = ( int ) ( ( scale * zoom * modelWidth ) + ( 2 * margin ) ) ; int height = ( int ) ( ( scale * zoom * modelHeight ) + ( 2 * margin ) ) ; int xCoord = ( int ) ( screenCoord . x - width / 2 ) ; int yCoord = ( int ) ( screenCoord . y - height / 2 ) ; return new Rectangle ( xCoord , yCoord , width , height ) ; }
Calculate the bounds of the diagram on screen given the current scale zoom and margin .