Simulator/src/view/MapPanel.java
/**
	 * Calculates the parameters needed for the user specified zoom. It ensures
	 * that the users specified ratio is respected, while making sure that the
	 * maximum dimensions are used.
	 * 
	 * @param xStart
	 *            Top left x coordinate.
	 * @param yStart
	 *            Top left y coordinate.
	 * @param xEnd
	 *            Bottom right x coordinate.
	 * @param yEnd
	 *            Bottom right y coordinate.
	 * @param mapWidth
	 *            The width of the map.
	 */
Calculates the parameters needed for the user specified zoom. It ensures
that the users specified ratio is respected, while making sure that the
maximum dimensions are used.

@param xStart
Top left x coordinate.
@param yStart
Top left y coordinate.
@param xEnd
Bottom right x coordinate.
@param yEnd
Bottom right y coordinate.
@param mapWidth
The width of the map.
Calculates the parameters needed for the user specified zoom . It ensures that the users specified ratio is respected while making sure that the maximum dimensions are used . @param xStart Top left x coordinate . @param yStart Top left y coordinate . @param xEnd Bottom right x coordinate . @param yEnd Bottom right y coordinate . @param mapWidth The width of the map .
public void zoom(int xStart, int yStart, int xEnd, int yEnd, double mapWidth) {
		if (xStart == 0 && yStart == 0 && xEnd == getWidth() && yEnd == getHeight()) {
			offsetX = 0;
			offsetY = 0;
			maxX = 0;
			maxY = 0;
		}
		double height = getHeight();
		double width = getWidth();
		double newHeight = yEnd - yStart;
		double newWidth = xEnd - xStart;
		double pixRatio = height / width;
		double newPixRatio = newHeight / newWidth;
		double oldPixelRatio = pixelRatio;
		if (pixRatio < newPixRatio) {
			pixelRatio = pixelRatio * (height / newHeight);
			newHeight = height;
			newWidth = newHeight * (1 / newPixRatio);
		}
		else {
			pixelRatio = pixelRatio * (width / newWidth);
			newWidth = width;
			newHeight = newWidth * newPixRatio;
		}
		offsetX = (int) (Math.max(0, offsetX + xStart) * (pixelRatio / oldPixelRatio));
		offsetY = (int) (Math.max(0, offsetY + yStart) * (pixelRatio / oldPixelRatio));
		maxX = (int) newWidth;
		maxY = (int) newHeight;
		repaint();
	}
public void zoom ( int xStart , int yStart , int xEnd , int yEnd , double mapWidth ) { if ( xStart == 0 && yStart == 0 && xEnd == getWidth ( ) && yEnd == getHeight ( ) ) { offsetX = 0 ; offsetY = 0 ; maxX = 0 ; maxY = 0 ; } double height = getHeight ( ) ; double width = getWidth ( ) ; double newHeight = yEnd - yStart ; double newWidth = xEnd - xStart ; double pixRatio = height / width ; double newPixRatio = newHeight / newWidth ; double oldPixelRatio = pixelRatio ; if ( pixRatio < newPixRatio ) { pixelRatio = pixelRatio * ( height / newHeight ) ; newHeight = height ; newWidth = newHeight * ( 1 / newPixRatio ) ; } else { pixelRatio = pixelRatio * ( width / newWidth ) ; newWidth = width ; newHeight = newWidth * newPixRatio ; } offsetX = ( int ) ( Math . max ( 0 , offsetX + xStart ) * ( pixelRatio / oldPixelRatio ) ) ; offsetY = ( int ) ( Math . max ( 0 , offsetY + yStart ) * ( pixelRatio / oldPixelRatio ) ) ; maxX = ( int ) newWidth ; maxY = ( int ) newHeight ; repaint ( ) ; }
Calculates the parameters needed for the user specified zoom.
Calculates the parameters needed for the user specified zoom .
// check for defaults // old height > newHeight // old width > newWidth