double worldAspectRatio = wyDiff / wxDiff;
double worldAspectRatio = Math.abs(wyDiff / wxDiff);
	public void setWorlds(double wx1, double wy1, double wx2, double wy2,		double px1, double py1, double px2, double py2,		int units, boolean allowDistortion)		throws MapyrusException	{		if (mOutputFormat == null)			throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.NO_OUTPUT));				double wxDiff = Math.abs(wx2 - wx1);		double wyDiff = Math.abs(wy2 - wy1);		double wxMid, wyMid;		if (px2 == 0 && py2 == 0)		{			/*			 * Use whole page.			 */			px2 = mOutputFormat.getPageWidth();			py2 = mOutputFormat.getPageHeight();		}		double pxDiff = px2 - px1;		double pyDiff = py2 - py1;		if (pxDiff <= 0.0 || pyDiff <= 0.0)			throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.INVALID_PAGE_RANGE));		if (wxDiff == 0.0 || wyDiff == 0.0)			throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.ZERO_WORLD_RANGE));		double worldAspectRatio = wyDiff / wxDiff;		double pageAspectRatio = pxDiff / pyDiff;		if (!allowDistortion)		{			/*			 * Expand world coordinate range in either X or Y axis so			 * it has same aspect ratio as area on page.			 */			if (worldAspectRatio > pageAspectRatio)			{				/*				 * World coordinate range is taller than page coordinate				 * system.  Expand X axis range to compensate:				 *				 *  PAGE    WORLDS    EXPANDED WORLDS				 *  +---+   +---+     +-+---+-+				 *  |   |   |   |     |<|   |>|				 *  |___|   |   |  => |<|   |>|				 *          |   |     |<|   |>|				 *          +---+     +-+---+-+				 */				wxMid = (wx1 + wx2) / 2.0;				wx1 = wxMid - (wxDiff / 2.0) * (worldAspectRatio / pageAspectRatio);				wx2 = wxMid + (wxDiff / 2.0) * (worldAspectRatio / pageAspectRatio);			}			else if (worldAspectRatio < pageAspectRatio)			{				/*				 * World coordinate range is wider than page coordinate system.				 * Expand Y axis range.				 */				wyMid = (wy1 + wy2) / 2.0;				wy1 = wyMid - (wyDiff / 2.0) * (pageAspectRatio / worldAspectRatio);				wy2 = wyMid + (wyDiff / 2.0) * (pageAspectRatio / worldAspectRatio);			}		}		/*		 * Expand world coordinate range so that it fills whole page.		 */		wxDiff = Math.abs(wx2 - wx1);		wyDiff = Math.abs(wy2 - wy1);		wx1 -= wxDiff / pxDiff * px1;		wx2 += wxDiff / pxDiff * (mOutputFormat.getPageWidth() - px2);		wy1 -= wyDiff / pyDiff * py1;		wy2 += wyDiff / pyDiff * (mOutputFormat.getPageHeight() - py2);		/*		 * Setup CTM from world coordinates to page coordinates.		 */		mWorldCtm = new AffineTransform();		mWorldCtm.scale(mOutputFormat.getPageWidth() / (wx2 - wx1),			mOutputFormat.getPageHeight() / (wy2 - wy1));		mWorldCtm.translate(-wx1, -wy1);		mWorldExtents = new Rectangle2D.Double(Math.min(wx1, wx2),			Math.min(wy1, wy2),			Math.abs(wx2 - wx1), Math.abs(wy2 - wy1));		mWorldUnits = units;	}