@Override public TrackFeature getCentroid() { TrackFeature centroid = new TrackFeature(name); centroid.setValue(_centroid); centroid.setWeight(_weight); return centroid; }
@Override public void add(TrackFeature feature) { ++_changes; Track newTrack = feature.getValue(); // add the track to the list of members if (null == _centroid) { _centroid = newTrack; _weight = feature.getWeight(); } else { // Weight according to how many are already there _centroid = _centroid.weightedAverage(newTrack, _weight, feature.getWeight()); _weight = _weight + feature.getWeight(); } }
@Override public String toString() { return (this.getName() + " : " + track.toString()); }
if (f instanceof TrackFeature) { TrackFeature tf = (TrackFeature) f; Track track = tf.getValue();
@Override public void remove (TrackFeature feature) { ++_changes; Track toRemove = feature.getValue(); //remove the track from the list of members double newWeight = _weight - feature.getWeight(); if (newWeight <= 0) { _centroid = null; _weight = 0.0; } else { _centroid = _centroid.weightedAverage(toRemove, _weight, -feature.getWeight()); _weight = newWeight; } }