Android Open Source - DiceInDark Overlap Tester From Project Back to project page DiceInDark .
License The source code is released under:
GNU General Public License
If you think the Android project DiceInDark listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.example.framework.math;
/ * f r o m w w w . j a v a 2 s . c o m * /
public class OverlapTester {
public static boolean overlapCircles(Circle c1, Circle c2) {
float distance = c1.center.distSquared(c2.center);
float radiusSum = c1.radius + c2.radius;
return distance <= radiusSum * radiusSum;
}
public static boolean overlapRectangles(Rectangle r1, Rectangle r2) {
if (r1.lowerLeft.x < r2.lowerLeft.x + r2.width &&
r1.lowerLeft.x + r1.width > r2.lowerLeft.x &&
r1.lowerLeft.y < r2.lowerLeft.y + r2.height &&
r1.lowerLeft.y + r1.height > r2.lowerLeft.y)
return true;
else
return false;
}
public static boolean overlapCircleRectangle(Circle c, Rectangle r) {
float closestX = c.center.x;
float closestY = c.center.y;
if (c.center.x < r.lowerLeft.x) {
closestX = r.lowerLeft.x;
}
else if (c.center.x > r.lowerLeft.x + r.width) {
closestX = r.lowerLeft.x + r.width;
}
if (c.center.y < r.lowerLeft.y) {
closestY = r.lowerLeft.y;
}
else if (c.center.y > r.lowerLeft.y + r.height) {
closestY = r.lowerLeft.y + r.height;
}
return c.center.distSquared(closestX, closestY) < c.radius * c.radius;
}
public static boolean pointInCircle(Circle c, Vector2 p) {
return c.center.distSquared(p) < c.radius * c.radius;
}
public static boolean pointInCircle(Circle c, float x, float y) {
return c.center.distSquared(x, y) < c.radius * c.radius;
}
public static boolean pointInRectangle(Rectangle r, Vector2 p) {
return r.lowerLeft.x <= p.x && r.lowerLeft.x + r.width >= p.x &&
r.lowerLeft.y <= p.y && r.lowerLeft.y + r.height >= p.y;
}
public static boolean pointInRectangle(Rectangle r, float x, float y) {
return r.lowerLeft.x <= x && r.lowerLeft.x + r.width >= x &&
r.lowerLeft.y <= y && r.lowerLeft.y + r.height >= y;
}
public static boolean onTopOfRectangles(Rectangle top, Rectangle bottom){
if (top.lowerLeft.y >bottom.lowerLeft.y)
return true;
else return false;
}
}
Java Source Code List com.example.diceindark.Assets.java com.example.diceindark.DiceInDark.java com.example.diceindark.DiceRender.java com.example.diceindark.DiceScreen.java com.example.diceindark.Die.java com.example.diceindark.MainMenuScreen.java com.example.framework.AndroidFileIO.java com.example.framework.Audio.java com.example.framework.FileIO.java com.example.framework.GameObject.java com.example.framework.Game.java com.example.framework.Graphics.java com.example.framework.Input.java com.example.framework.Pixmap.java com.example.framework.Pool.java com.example.framework.Screen.java com.example.framework.Sound.java com.example.framework.gl.Animation.java com.example.framework.gl.BindableVertices.java com.example.framework.gl.Camera2D.java com.example.framework.gl.Font.java com.example.framework.gl.SpriteBatcher.java com.example.framework.gl.TextureRegion.java com.example.framework.gl.Texture.java com.example.framework.gl.Vertices.java com.example.framework.impl.AccelerometerHandler.java com.example.framework.impl.AndroidAudio.java com.example.framework.impl.AndroidGraphics.java com.example.framework.impl.AndroidInput.java com.example.framework.impl.AndroidPixmap.java com.example.framework.impl.AndroidSound.java com.example.framework.impl.GLGame.java com.example.framework.impl.GLGraphics.java com.example.framework.impl.GLScreen.java com.example.framework.impl.GestureHandler.java com.example.framework.impl.KeyboardHandler.java com.example.framework.impl.TouchHandler.java com.example.framework.math.Circle.java com.example.framework.math.OverlapTester.java com.example.framework.math.Rectangle.java com.example.framework.math.Vector2.java com.plovergames.diceindark.Assets.java com.plovergames.diceindark.DiceInDark.java com.plovergames.diceindark.DiceRender.java com.plovergames.diceindark.DiceScreen.java com.plovergames.diceindark.Die.java com.plovergames.diceindark.MainMenuScreen.java com.plovergames.framework.AndroidFileIO.java com.plovergames.framework.Audio.java com.plovergames.framework.FileIO.java com.plovergames.framework.GameObject.java com.plovergames.framework.Game.java com.plovergames.framework.Graphics.java com.plovergames.framework.Input.java com.plovergames.framework.Pixmap.java com.plovergames.framework.Pool.java com.plovergames.framework.Screen.java com.plovergames.framework.Sound.java com.plovergames.framework.gl.Animation.java com.plovergames.framework.gl.BindableVertices.java com.plovergames.framework.gl.Camera2D.java com.plovergames.framework.gl.Font.java com.plovergames.framework.gl.SpriteBatcher.java com.plovergames.framework.gl.TextureRegion.java com.plovergames.framework.gl.Texture.java com.plovergames.framework.gl.Vertices.java com.plovergames.framework.impl.AccelerometerHandler.java com.plovergames.framework.impl.AndroidAudio.java com.plovergames.framework.impl.AndroidGraphics.java com.plovergames.framework.impl.AndroidInput.java com.plovergames.framework.impl.AndroidPixmap.java com.plovergames.framework.impl.AndroidSound.java com.plovergames.framework.impl.GLGame.java com.plovergames.framework.impl.GLGraphics.java com.plovergames.framework.impl.GLScreen.java com.plovergames.framework.impl.GestureHandler.java com.plovergames.framework.impl.TouchHandler.java com.plovergames.framework.math.Rectangle.java com.plovergames.framework.math.Vector2.java