-
Notifications
You must be signed in to change notification settings - Fork 35
/
Displacement1d.java
53 lines (40 loc) · 1.24 KB
/
Displacement1d.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
42
43
44
45
46
47
48
49
50
51
52
53
package com.team254.lib.geometry;
import com.team254.lib.util.Util;
import java.text.DecimalFormat;
public class Displacement1d implements State<Displacement1d> {
protected final double displacement_;
public Displacement1d() {
displacement_ = 0.0;
}
public Displacement1d(double displacement) {
displacement_ = displacement;
}
public double x() {
return displacement_;
}
@Override
public Displacement1d interpolate(final Displacement1d other, double x) {
return new Displacement1d(Util.interpolate(displacement_, other.displacement_, x));
}
@Override
public double distance(final Displacement1d other) {
return Math.abs(x() - other.x());
}
@Override
public boolean equals(final Object other) {
if (!(other instanceof Displacement1d)) {
return false;
}
return Util.epsilonEquals(x(), ((Displacement1d) other).x());
}
@Override
public String toString() {
final DecimalFormat fmt = new DecimalFormat("#0.000");
return fmt.format("(" + x() + ")");
}
@Override
public String toCSV() {
final DecimalFormat fmt = new DecimalFormat("#0.000");
return fmt.format(x());
}
}