ui/src/main/java/ucar/nc2/ui/widget/ScaledPanel.java
private AffineTransform calcTransform(Rectangle2D screen, Bounds world) {
    // scale to limiting dimension
    double xs = screen.getWidth() / (world.getRight() - world.getLeft());
    double ys = screen.getHeight() / (world.getLower() - world.getUpper());

    AffineTransform cat = new AffineTransform();
    cat.setToScale(xs, ys);
    cat.translate(-world.getLeft(), -world.getUpper());

    if (debugTransform) {
      System.out.println("TPanel calcTransform = ");
      System.out.println("  screen = " + screen);
      System.out.println("  world = " + world);

      System.out.println("  transform = " + cat.getScaleX() + " " + cat.getShearX() + " " + cat.getTranslateX());
      System.out.println("              " + cat.getShearY() + " " + cat.getScaleY() + " " + cat.getTranslateY());

      Point2D src = new Point2D.Double(world.getLeft(), world.getUpper());
      Point2D dst = new Point2D.Double(0.0, 0.0);

      System.out.println("  upper left pt = " + src);
      System.out.println("  transform = " + cat.transform(src, dst));

      src = new Point2D.Double(world.getRight(), world.getLower());
      System.out.println("  lower right pt = " + src);
      System.out.println("  transform = " + cat.transform(src, dst));
    }
    return cat;
  }
private AffineTransform calcTransform(Rectangle2D screen, Bounds world) {
    // scale to limiting dimension
    double xs = screen.getWidth() / (world.getRight() - world.getLeft());
    double ys = screen.getHeight() / (world.getLower() - world.getUpper());

    AffineTransform cat = new AffineTransform();
    cat.setToScale(xs, ys);
    cat.translate(-world.getLeft(), -world.getUpper());

    if (debugTransform) {
      System.out.println("TPanel calcTransform = ");
      System.out.println("  screen = " + screen);
      System.out.println("  world = " + world);

      System.out.println("  transform = " + cat.getScaleX() + " " + cat.getShearX() + " " + cat.getTranslateX());
      System.out.println("              " + cat.getShearY() + " " + cat.getScaleY() + " " + cat.getTranslateY());

      Point2D src = new Point2D.Double(world.getLeft(), world.getUpper());
      Point2D dst = new Point2D.Double(0.0, 0.0);

      System.out.println("  upper left pt = " + src);
      System.out.println("  transform = " + cat.transform(src, dst));

      src = new Point2D.Double(world.getRight(), world.getLower());
      System.out.println("  lower right pt = " + src);
      System.out.println("  transform = " + cat.transform(src, dst));
    }
    return cat;
  }
map world coords to screen coords.

@param world  world coordinate rectangle
@param screen screen coordinate rectangle
@return AffineTransform for converting world to screen.