|
|
cfceb0 |
using System;
|
|
|
cfceb0 |
using System.Collections.Generic;
|
|
|
b82ef4 |
using Assistance.Drawing;
|
|
|
cfceb0 |
|
|
|
cfceb0 |
namespace Assistance {
|
|
|
cfceb0 |
public class Guideline {
|
|
|
b82ef4 |
public static readonly Pen pen = new Pen("Light Gray");
|
|
|
b82ef4 |
public static readonly Pen penActive = new Pen("Deep Sky Blue");
|
|
|
cfceb0 |
public static readonly double snapLenght = 20.0;
|
|
|
cfceb0 |
public static readonly double snapScale = 1.0;
|
|
|
589f9a |
public static readonly double maxLenght = 2.0*snapLenght*snapScale;
|
|
|
cfceb0 |
|
|
|
589f9a |
public virtual Track.WayPoint transformPoint(Track.WayPoint point)
|
|
|
589f9a |
{ return point; }
|
|
|
cfceb0 |
|
|
|
b82ef4 |
public virtual void draw(Cairo.Context context, bool active) { }
|
|
|
cfceb0 |
|
|
|
589f9a |
public void draw(Cairo.Context context)
|
|
|
589f9a |
{ draw(context, false); }
|
|
|
cfceb0 |
|
|
|
cfceb0 |
public double calcTrackWeight(Track track) {
|
|
|
d13872 |
if (track.points.Count < 1)
|
|
|
cfceb0 |
return double.PositiveInfinity;
|
|
|
cfceb0 |
double sumWeight = 0.0;
|
|
|
cfceb0 |
double sumLength = 0.0;
|
|
|
cfceb0 |
double sumDeviation = 0.0;
|
|
|
cfceb0 |
|
|
|
589f9a |
Point prev = track.points[0].point.position;
|
|
|
589f9a |
foreach(Track.WayPoint wp in track.points) {
|
|
|
589f9a |
Point p = wp.point.position;
|
|
|
d13872 |
double length = (p - prev).len();
|
|
|
cfceb0 |
sumLength += length;
|
|
|
cfceb0 |
|
|
|
d13872 |
double midStepLength = sumLength - 0.5*length;
|
|
|
d13872 |
if (midStepLength > Geometry.precision) {
|
|
|
d13872 |
double weight = length*Geometry.logNormalDistribuitionUnscaled(midStepLength, snapLenght, snapScale);
|
|
|
d13872 |
sumWeight += weight;
|
|
|
cfceb0 |
|
|
|
589f9a |
Track.WayPoint nwp = transformPoint(wp);
|
|
|
589f9a |
double deviation = (nwp.point.position - p).len();
|
|
|
d13872 |
sumDeviation += weight*deviation;
|
|
|
d13872 |
}
|
|
|
d13872 |
prev = p;
|
|
|
cfceb0 |
}
|
|
|
d13872 |
if (sumWeight < Geometry.precision)
|
|
|
d13872 |
return double.PositiveInfinity;
|
|
|
cfceb0 |
return sumDeviation/sumWeight;
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|
|
|
cfceb0 |
public static Guideline findBest(List<guideline> guidelines, Track track) {</guideline>
|
|
|
cfceb0 |
double bestWeight = double.PositiveInfinity;
|
|
|
cfceb0 |
Guideline best = null;
|
|
|
cfceb0 |
foreach(Guideline guideline in guidelines) {
|
|
|
cfceb0 |
double weight = guideline.calcTrackWeight(track);
|
|
|
cfceb0 |
if (weight < bestWeight) {
|
|
|
cfceb0 |
bestWeight = weight;
|
|
|
cfceb0 |
best = guideline;
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
return best;
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|