/*   Copyright 2013-2014 Miguel Vicente Linares
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.miviclin.droidengine2ddemos.util;

import com.miviclin.droidengine2d.graphics.material.Material;
import com.miviclin.droidengine2d.util.Transform;

public class Rectangle<M extends Material> {

	private Transform transform;
	private M material;

	public Rectangle(Transform transform, M material) {
		super();
		this.transform = transform;
		this.material = material;
	}

	public Transform getTransform() {
		return transform;
	}

	public M getMaterial() {
		return material;
	}

	public boolean contains(float x, float y) {
		float width = transform.getScale().getX();
		float height = transform.getScale().getY();
		float halfWidth = width / 2;
		float halfHeight = height / 2;
		float left = transform.getPosition().getX() - halfWidth;
		float bottom = transform.getPosition().getY() - halfHeight;
		float right = left + width;
		float top = bottom + height;
		boolean containsX = (left <= x) && (x <= right);
		boolean containsY = (bottom <= y) && (y <= top);
		return (containsX && containsY);
	}
}

@@ -1625,11 +1625,1117 @@
 nsY);%0A%09%7D
+%0A%0A%09public boolean intersects(Rectangle%3C?%3E rectangle) %7B%0A%09%09float width = transform.getScale().getX();%0A%09%09float height = transform.getScale().getY();%0A%09%09float halfWidth = width / 2;%0A%09%09float halfHeight = height / 2;%0A%09%09float left = transform.getPosition().getX() - halfWidth;%0A%09%09float bottom = transform.getPosition().getY() - halfHeight;%0A%09%09float right = left + width;%0A%09%09float top = bottom + height;%0A%0A%09%09float otherWidth = transform.getScale().getX();%0A%09%09float otherHeight = transform.getScale().getY();%0A%09%09float otherHalfWidth = otherWidth / 2;%0A%09%09float otherHalfHeight = otherHeight / 2;%0A%09%09float otherLeft = transform.getPosition().getX() - otherHalfWidth;%0A%09%09float otherBottom = transform.getPosition().getY() - otherHalfHeight;%0A%09%09float otherRight = otherLeft + otherWidth;%0A%09%09float otherTop = otherBottom + otherHeight;%0A%0A%09%09boolean intersectsX = ((otherLeft %3C= right) && (otherLeft %3E= left)) %7C%7C%0A%09%09%09%09((otherRight %3E= left) && (otherRight %3C= right));%0A%0A%09%09boolean intersectsY = ((otherBottom %3C= top) && (otherBottom %3E= bottom)) %7C%7C%0A%09%09%09%09((otherTop %3E= bottom) && (otherTop %3C= top));%0A%0A%09%09return (intersectsX && intersectsY);%0A%09%7D
 %0A%7D%0A

Add Rectangle.intersects(Rectangle)