mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-05 03:43:52 +00:00
performance tree-grow: fix cos(lat) factor in longitude quantization; add wind-cache to wind-field-tracked-race used by tree-grow;
This commit is contained in:
1 parent
7664592889
commit
3bd6a0f797
2 files changed
+33
-4
No files matched your search
+18
-1
@@ -10,7 +10,8 @@ public class TimedPositionImpl implements TimedPosition {
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -675796846985362731L;
|
||||
|
||||
private transient int hashCode;
|
||||
|
||||
TimePoint timePoint;
|
||||
Position position;
|
||||
|
||||
@@ -29,4 +30,20 @@ public class TimedPositionImpl implements TimedPosition {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
TimedPosition that = (TimedPosition) other;
|
||||
return (this.position.equals(that.getPosition())&&(this.timePoint.equals(that.getTimePoint())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode( ) {
|
||||
if ( hashCode == 0 ) {
|
||||
hashCode = 17;
|
||||
hashCode = 37 * hashCode + ( timePoint != null ? timePoint.hashCode( ) : 0 );
|
||||
hashCode = 37 * hashCode + ( position != null ? position.hashCode( ) : 0 );
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
}
|
||||
+15
-3
@@ -1,5 +1,7 @@
|
||||
package com.sap.sailing.simulator.windfield.impl;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.DegreePosition;
|
||||
@@ -8,6 +10,7 @@ import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
import com.sap.sailing.domain.tracking.Wind;
|
||||
import com.sap.sailing.simulator.TimedPosition;
|
||||
import com.sap.sailing.simulator.impl.TimedPositionImpl;
|
||||
import com.sap.sailing.simulator.windfield.WindFieldGenerator;
|
||||
|
||||
/**
|
||||
@@ -24,10 +27,12 @@ public class WindFieldTrackedRaceImpl extends WindFieldGeneratorImpl implements
|
||||
private static final double EPSILON_DISTANCE_METER = 20;
|
||||
private static final long EPSILON_TIME_MILLIS = 5000;
|
||||
private TrackedRace race;
|
||||
private final ConcurrentHashMap<TimedPosition, Wind> cache;
|
||||
|
||||
public WindFieldTrackedRaceImpl(TrackedRace race) {
|
||||
super(null, null);
|
||||
this.race = race;
|
||||
this.cache = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,12 +40,19 @@ public class WindFieldTrackedRaceImpl extends WindFieldGeneratorImpl implements
|
||||
Position pos = timedPosition.getPosition();
|
||||
double epsLat = (new MeterDistance(EPSILON_DISTANCE_METER)).getCentralAngleDeg();
|
||||
double qLat = Math.floor(pos.getLatDeg() / epsLat) * epsLat;
|
||||
double epsLng = epsLat / Math.cos(pos.getLatDeg());
|
||||
double epsLng = epsLat / Math.cos(qLat * Math.PI / 180.0);
|
||||
double qLng = Math.floor(pos.getLngDeg() / epsLng) * epsLng;
|
||||
TimePoint time = timedPosition.getTimePoint();
|
||||
long epsTime = EPSILON_TIME_MILLIS;
|
||||
long qTime = (long) (Math.floor(time.asMillis() / epsTime) * epsTime);
|
||||
return this.race.getWind(new DegreePosition(qLat, qLng), new MillisecondsTimePoint(qTime));
|
||||
TimePoint qTime = new MillisecondsTimePoint((long) (Math.floor(time.asMillis() / epsTime) * epsTime));
|
||||
Position qPosition = new DegreePosition(qLat, qLng);
|
||||
TimedPosition qTimedPosition = new TimedPositionImpl(qTime, qPosition);
|
||||
Wind wind = cache.get(qTimedPosition);
|
||||
if (wind == null) {
|
||||
wind = this.race.getWind(qPosition, qTime);
|
||||
cache.put(qTimedPosition, wind);
|
||||
}
|
||||
return wind;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user