File: SegmentSummary.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (70 lines) | stat: -rw-r--r-- 1,656 bytes parent folder | download | duplicates (4)
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
package tim.prune.function.comparesegments;

import tim.prune.data.DataPoint;
import tim.prune.data.Timestamp;

/**
 * Hold a running summary of the current segment and its validity for the comparison function
 */
public class SegmentSummary
{
	private boolean _valid = true;
	private int _pointCount = 0;
	private final int _startIndex;
	private final Timestamp _startTimestamp;
	private DataPoint _latestPoint = null;
	private double _totalRadians = 0.0;


	SegmentSummary(int inStartIndex, DataPoint inPoint)
	{
		_startIndex = inStartIndex;
		_startTimestamp = inPoint == null ? null : inPoint.getTimestamp();
		addPoint(inPoint);
	}

	/** Add a point to the segment */
	public void addPoint(DataPoint inPoint)
	{
		if (inPoint == null || !inPoint.isValid() || !inPoint.hasTimestamp())
		{
			_valid = false;
			return;
		}
		if (_latestPoint != null)
		{
			_totalRadians += DataPoint.calculateRadiansBetween(_latestPoint, inPoint);
			_valid = _valid && !inPoint.getTimestamp().isBefore(_latestPoint.getTimestamp());
		}
		_latestPoint = inPoint;
		_pointCount++;
	}

	public boolean isValid() {
		return _valid && _pointCount > 1;
	}

	public int getPointCount() {
		return _pointCount;
	}

	public int getStartIndex() {
		return _startIndex;
	}

	public Timestamp getStartTimestamp() {
		return _startTimestamp;
	}

	public long getDurationInSeconds()
	{
		if (_latestPoint != null && _latestPoint.hasTimestamp()) {
			return _latestPoint.getTimestamp().getSecondsSince(_startTimestamp);
		}
		return 0L;
	}

	public double getDistanceInRadians() {
		return _totalRadians;
	}
}