mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-09 22:01:02 +00:00
wrote up a few TODOs regarding preparing for a second tracking adapter; added missing BearingCluster class
This commit is contained in:
1 parent
98d38e87b7
commit
1dc9f89e70
2 files changed
+50
No files matched your search
+40
@@ -0,0 +1,40 @@
|
||||
package com.sap.sailing.domain.tracking.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sailing.domain.base.Bearing;
|
||||
import com.sap.sailing.domain.base.impl.DegreeBearingImpl;
|
||||
|
||||
/**
|
||||
* Contains a number of {@link Bearing} objects and maintains the average bearing. For a given {@link Bearing} it
|
||||
* can determine the difference to this cluster's average bearing.
|
||||
*
|
||||
* @author Axel Uhl (d043530)
|
||||
*
|
||||
*/
|
||||
public class BearingCluster {
|
||||
private final List<Bearing> bearings;
|
||||
private double sumDegrees;
|
||||
|
||||
public BearingCluster() {
|
||||
bearings = new ArrayList<Bearing>();
|
||||
sumDegrees = 0.0;
|
||||
}
|
||||
|
||||
public void add(Bearing bearing) {
|
||||
bearings.add(bearing);
|
||||
sumDegrees += bearing.getDegrees();
|
||||
}
|
||||
|
||||
public Bearing getAverage() {
|
||||
return new DegreeBearingImpl(sumDegrees / bearings.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is no bearing stored in this cluster yet, 0.0 is returned.
|
||||
*/
|
||||
public double getDifferenceFromAverage(Bearing bearing) {
|
||||
return Math.abs(sumDegrees / bearings.size() - bearing.getDegrees());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user