This repository was archived by the owner on Sep 17, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathCollisions.java
More file actions
91 lines (74 loc) · 3.36 KB
/
Copy pathCollisions.java
File metadata and controls
91 lines (74 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package Gprocessing.physics;
import Gprocessing.util.Utils;
public class Collisions {
/**
* Checks if a set of X and Y coordinates are inside of a circle.
* @param inX X position of point to check
* @param inY Y position of point to check
* @param circleX X position of circle
* @param circleY Y position of circle
* @param radius Radius of circle
* @return Returns true if the point is inside the circle, otherwise returns false.
*/
public static boolean inCircle(float inX, float inY, float circleX, float circleY, float radius) {
return Utils.dist(inX, inY, circleX, circleY) < radius * 2;
}
/**
* Checks if a set of X and Y coordinates are inside of a circle.
* @param in Vector2 containing coordinates of point to check
* @param circleX X position of circle
* @param circleY Y position of circle
* @param radius Radius of circle
* @return Returns true if the point is inside the circle, otherwise returns false.
*/
public static boolean inCircle(Vector2 in, float circleX, float circleY, float radius) {
return Utils.dist(in.x, in.y, circleX, circleY) < radius * 2;
}
/**
* Checks if a set of X and Y coordinates are inside of a circle.
* @param in Vector2 containing coordinates of point to check
* @param circle Vector2 containing coordinates of the circle
* @param radius Radius of circle
* @return Returns true if the point is inside the circle, otherwise returns false.
*/
public static boolean inCircle(Vector2 in, Vector2 circle, float radius) {
return Utils.dist(in.x, in.y, circle.x, circle.y) < radius * 2;
}
/**
* Checks if a set of X and Y coordinates are inside of a rectangle.
* @param inX X position of point to check
* @param inY Y position of point to check
* @param rectX X position of rectangle
* @param rectY Y position of rectangle
* @param rectWidth Width of rectangle
* @param rectHeight Height of rectangle
* @return Returns true if the point is inside the rectangle, otherwise returns false.
*/
public static boolean inRect(float inX, float inY, float rectX, float rectY, float rectWidth, float rectHeight) {
return inX >= rectX && inX <= (rectY + rectWidth) && inY >= rectY && inY <= (rectY + rectHeight);
}
/**
* Checks if a set of X and Y coordinates are inside of a rectangle.
* @param in Vector2 containing coordinates of point to check
* @param rectX X position of rectangle
* @param rectY Y position of rectangle
* @param rectWidth Width of rectangle
* @param rectHeight Height of rectangle
* @return Returns true if the point is inside the rectangle, otherwise returns false.
*/
public static boolean inRect(Vector2 in, float rectX, float rectY, float rectWidth, float rectHeight) {
return in.x >= rectX && in.x <= (rectY + rectWidth) && in.y >= rectY && in.y <= (rectY + rectHeight);
}
/**
* Checks if a rectangle is completely inside of another rectangle.
* @param t1
* @param t2
* @return
*/
public static boolean rectInRect(Transform t1, Transform t2) {
return t1.position.x < t2.scale.x &&
t1.scale.x > t2.position.x &&
t1.position.y < t2.scale.y &&
t1.scale.y > t2.position.y;
}
}