Java Rectangle interpolate(Rectangle r1, Rectangle r2, float f)

Here you can find the source of interpolate(Rectangle r1, Rectangle r2, float f)

Description

interpolate

License

Open Source License

Declaration

public static Rectangle interpolate(Rectangle r1, Rectangle r2, float f) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Breakout Cave Survey Visualizer//www  .j  a  v a 2  s .  c om
 *
 * Copyright (C) 2014 James Edwards
 *
 * jedwards8 at fastmail dot fm
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *******************************************************************************/

import java.awt.Rectangle;

public class Main {
    public static Rectangle interpolate(Rectangle r1, Rectangle r2, float f) {
        Rectangle out = new Rectangle();
        interpolate(r1, r2, f, out);
        return out;
    }

    public static void interpolate(Rectangle r1, Rectangle r2, float f, Rectangle out) {
        if (r1.x + r1.width == r2.x + r2.width) {
            int right = r1.x + r1.width;
            out.x = Math.round(r1.x * (1f - f) + r2.x * f);
            out.width = right - out.x;
        } else {
            out.x = Math.round(r1.x * (1f - f) + r2.x * f);
            out.width = Math.round(r1.width * (1f - f) + r2.width * f);
        }
        if (r1.y + r1.height == r2.y + r2.height) {
            int bottom = r1.y + r1.height;
            out.y = Math.round(r1.y * (1f - f) + r2.y * f);
            out.height = bottom - out.y;
        } else {
            out.y = Math.round(r1.y * (1f - f) + r2.y * f);
            out.height = Math.round(r1.height * (1f - f) + r2.height * f);
        }
    }
}

Related

  1. getRect(byte[] data, int i)
  2. getRectangleProperty(Map p, Object key, Rectangle defaultValue)
  3. getRectLE(byte[] data, int i)
  4. getSubArea(Shape retangulo, int divisorx, int divisory, int offsetx, int offsety)
  5. inflateRectangle(Rectangle r, int x, int y)
  6. mergeRects(Set prev, Set current)
  7. normalizeRect(Rectangle rect)
  8. randomRectangle(int minW, int maxW, int minH, int maxH)
  9. randomSquare(int minW, int maxW)