Blame mono/Assistance/Guideline.cs

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;
0f2bf8
		public static readonly double maxLenght = 20.0*snapLenght*snapScale;
cfceb0
	
702257
		public virtual Track.Point transformPoint(Track.Point 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
			
702257
			Point prev = track.points[0].position;
702257
			foreach(Track.Point tp in track.points) {
702257
				Point p = tp.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
				
702257
					Track.Point ntp = transformPoint(tp);
702257
					double deviation = (ntp.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>
0f2bf8
			double bestWeight = 0.0;
cfceb0
			Guideline best = null;
cfceb0
			foreach(Guideline guideline in guidelines) {
cfceb0
				double weight = guideline.calcTrackWeight(track);
0f2bf8
				if (best == null || weight < bestWeight) {
cfceb0
					bestWeight = weight;
cfceb0
					best = guideline;
cfceb0
				}
cfceb0
			}
cfceb0
			return best;
cfceb0
		}
cfceb0
	}
cfceb0
}
cfceb0