File: NearbyFactorMethod.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 (47 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (2)
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
package tim.prune.function.compress.methods;

import tim.prune.data.NumberUtils;
import tim.prune.function.compress.CompressionMethodType;
import tim.prune.function.compress.TrackDetails;

/** Compression of nearby points using a span factor parameter */
public class NearbyFactorMethod extends NearbyPointsMethod
{
	private final int _factor;

	public NearbyFactorMethod(int factor) {
		_factor = factor;
	}

	public NearbyFactorMethod(String inString) {
		_factor = NumberUtils.getIntOrZero(recogniseString(inString) ? inString.substring(4) : inString);
	}

	public CompressionMethodType getType() {
		return CompressionMethodType.NEARBY_WITH_FACTOR;
	}

	public String getParam() {
		return "" + Math.abs(_factor);
	}

	public String getSettingsString() {
		return getType().getKey() + _factor;
	}

	static boolean recogniseString(String inString) {
		return recogniseString(inString, CompressionMethodType.NEARBY_WITH_FACTOR);
	}

	/** @return the radian threshold based on the track's extents */
	protected double getRadianThreshold(TrackDetails inDetails)
	{
		// Parse parameter
		double param = _factor <= 0 ? 1.0 : (1.0 / _factor);
		if (param <= 0.0 || param >= 1.0) {
			// Parameter isn't valid, don't delete any
			return 0.0;
		}
		return inDetails.getMaxRadians() * param;
	}
}