DefaultViewport implements Viewport { @Override public void zoom(Rectangle2D modelBounds) { final double viewportWidth = viewBounds.width; final double viewportHeight = viewBounds.height; final double zoomFactor = Math.min(viewportWidth / modelBounds.getWidth(), viewportHeight / modelBounds.getHeight()); if (zoomFactor > 0.0) { setZoomFactor(zoomFactor, modelBounds.getCenterX(), modelBounds.getCenterY()); } } DefaultViewport();  DefaultViewport(Rectangle viewBounds);  DefaultViewport(boolean modelYAxisDown);  DefaultViewport(Rectangle viewBounds, boolean modelYAxisDown); @Override boolean isModelYAxisDown(); @Override void setModelYAxisDown(boolean modelYAxisDown); @Override Rectangle getViewBounds(); @Override void setViewBounds(Rectangle viewBounds); @Override AffineTransform getViewToModelTransform(); @Override AffineTransform getModelToViewTransform(); @Override double getOrientation(); @Override void setOrientation(double orientation); @Override double getOffsetX(); @Override double getOffsetY(); @Override void setOffset(double offsetX, double offsetY); @Override void moveViewDelta(double deltaX, double deltaY); @Override double getZoomFactor(); @Override void setZoomFactor(double zoomFactor); @Override void zoom(Rectangle2D modelBounds); @Override void setZoomFactor(double zoomFactor, double modelCenterX, double modelCenterY); @Override void addListener(ViewportListener listener); @Override void removeListener(ViewportListener listener); @Override ViewportListener[] getListeners(); @Override void setTransform(Viewport other); @Override String toString(); @SuppressWarnings({"CloneDoesntDeclareCloneNotSupportedException"}) @Override Viewport clone();  }
@Test public void testRelativeZoomWithAffineTransform() { Point2D vc; final Point2D v0 = p(0, 0); Point2D u0; AffineTransform v2u = new AffineTransform(); v2u.translate(10, 10); u0 = t(v2u, v0); assertEquals(1.0, v2u.getScaleX(), 1.0e-10); assertEquals(1.0, v2u.getScaleY(), 1.0e-10); assertEquals(p(10, 10), u0); vc = p(15, 10); assertEquals(p(25.0, 20.0), t(v2u, vc)); zoom(v2u, vc, 2.0); assertEquals(p(25.0, 20.0), t(v2u, vc)); assertEquals(2.0, v2u.getScaleX(), 1.0e-10); assertEquals(2.0, v2u.getScaleY(), 1.0e-10); assertEquals(p(-5.0, 0.0), t(v2u, v0)); zoom(v2u, vc, 0.5); assertEquals(p(25.0, 20.0), t(v2u, vc)); assertEquals(0.5, v2u.getScaleX(), 1.0e-10); assertEquals(0.5, v2u.getScaleY(), 1.0e-10); assertEquals(p(17.5, 15.0), t(v2u, v0)); vc = p(50, 25); assertEquals(p(42.5, 27.5), t(v2u, vc)); zoom(v2u, vc, 1.2); assertEquals(p(42.5, 27.5), t(v2u, vc)); assertEquals(1.2, v2u.getScaleX(), 1.0e-10); assertEquals(1.2, v2u.getScaleY(), 1.0e-10); assertEquals(p(-17.5, -2.5), t(v2u, v0)); zoom(v2u, vc, 0.8); assertEquals(p(42.5, 27.5), t(v2u, vc)); assertEquals(0.8, v2u.getScaleX(), 1.0e-10); assertEquals(0.8, v2u.getScaleY(), 1.0e-10); assertEquals(p(2.5, 7.5), t(v2u, v0)); }