get Collision Bounds between two Rect - Android Graphics

Android examples for Graphics:Rectangle

Description

get Collision Bounds between two Rect

Demo Code


//package com.java2s;

import android.graphics.Rect;

public class Main {
    private static Rect getCollisionBounds(Rect rect1, Rect rect2) {
        int left = (int) Math.max(rect1.left, rect2.left);
        int top = (int) Math.max(rect1.top, rect2.top);
        int right = (int) Math.min(rect1.right, rect2.right);
        int bottom = (int) Math.min(rect1.bottom, rect2.bottom);
        return new Rect(left, top, right, bottom);
    }//w w w.  jav  a2  s  . c  o m
}

Related Tutorials