-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.java
41 lines (34 loc) · 1.07 KB
/
Particle.java
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
public class Particle {
private int index;
public double x, y;
public double radius;
public Particle(int index, double x, double y, double radius) {
this.index = index;
this.x = x;
this.y = y;
this.radius = radius;
}
public int getIndex() {
return index;
}
public double distanceTo(Particle p) {
double deltaX = this.x - p.x;
double deltaY = this.y - p.y;
return (Math.sqrt(deltaX * deltaX + deltaY * deltaY)) - (this.radius + p.radius);
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Particle))
return false;
Particle p = (Particle) o;
return p.x == this.x && p.y == this.y && p.index == this.index && p.radius == this.radius;
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append(String.format("%d: ", index)).append(String.format("r:%.3f x:%.3f y:%.3f", radius, x, y));
return str.toString();
}
}