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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
package tim.prune.function.comparesegments;
import tim.prune.data.DataPoint;
import tim.prune.data.Timestamp;
/**
* The result of intersecting a point from one segment
* with the lines from another segment
*/
public class IntersectionResult implements Comparable<IntersectionResult>
{
private static class ResultPoint
{
private final DataPoint _point;
private final Timestamp _timestamp;
private final double _distance;
private final double _speed;
private ResultPoint(DataPoint inPoint, Timestamp inTimestamp, double inDistance, double inSpeed) {
_point = inPoint;
_timestamp = inTimestamp;
_distance = inDistance;
_speed = inSpeed;
}
}
private final ResultPoint _firstPoint;
private final ResultPoint _secondPoint;
public IntersectionResult(DataPoint inFirstPoint, DataPoint inSecondPoint,
Timestamp inFirstTimestamp, Timestamp inSecondTimestamp,
double inFirstDistanceRadians, double inSecondDistanceRadians,
double inFirstSpeed, double inSecondSpeed)
{
_firstPoint = new ResultPoint(inFirstPoint, inFirstTimestamp, inFirstDistanceRadians, inFirstSpeed);
_secondPoint = new ResultPoint(inSecondPoint, inSecondTimestamp, inSecondDistanceRadians, inSecondSpeed);
}
private IntersectionResult(ResultPoint inFirstPoint, ResultPoint inSecondPoint)
{
_firstPoint = inFirstPoint;
_secondPoint = inSecondPoint;
}
/** Reverse the meaning of the two segments, creating an opposite result */
IntersectionResult reverse() {
return new IntersectionResult(_secondPoint, _firstPoint);
}
public DataPoint getFirstPoint() {
return _firstPoint._point;
}
public DataPoint getSecondPoint() {
return _secondPoint._point;
}
public long getFirstDurationSeconds(IntersectionResult inOther) {
return _firstPoint._timestamp.getSecondsSince(inOther._firstPoint._timestamp);
}
public long getSecondDurationSeconds(IntersectionResult inOther) {
return _secondPoint._timestamp.getSecondsSince(inOther._secondPoint._timestamp);
}
public double getFirstDistanceRadians(IntersectionResult inOther) {
return _firstPoint._distance - inOther._firstPoint._distance;
}
public double getSecondDistanceRadians(IntersectionResult inOther) {
return _secondPoint._distance - inOther._secondPoint._distance;
}
public double getDeltaSpeedRadiansPerSec() {
return _secondPoint._speed - _firstPoint._speed;
}
public int compareTo(IntersectionResult inOther)
{
if (inOther == null || _firstPoint._timestamp.isBefore(inOther._firstPoint._timestamp)) {
return -1;
}
if (inOther._firstPoint._timestamp.isBefore(_firstPoint._timestamp)) {
return 1;
}
int distCompare = Double.compare(_firstPoint._distance, inOther._firstPoint._distance);
if (distCompare != 0) {
return distCompare;
}
if (_secondPoint._timestamp.isBefore(inOther._secondPoint._timestamp)) {
return -1;
}
if (inOther._secondPoint._timestamp.isBefore(_secondPoint._timestamp)) {
return 1;
}
return Double.compare(_secondPoint._distance, inOther._secondPoint._distance);
}
}
|