Blame mono/Assistance/Geometry.cs

cfceb0
using System;
77c1c7
using System.Drawing;
77c1c7
using System.Drawing.Imaging;
77c1c7
using System.Collections.Generic;
cfceb0
cfceb0
namespace Assistance {
cfceb0
	public static class Geometry {
77c1c7
		public delegate Point TransformFunc(Point p);
77c1c7
d13872
		public static readonly double precision = 1e-8;
cfceb0
		public static readonly double sqrt2Pi = Math.Sqrt(2.0*Math.PI);
cfceb0
		
cfceb0
		public static double logNormalDistribuitionUnscaled(double x, double x0, double w) {
cfceb0
			return Math.Exp(-0.5*Math.Pow(Math.Log(x/x0)/w, 2.0))/x;
cfceb0
		}
cfceb0
		
cfceb0
		public static double logNormalDistribuition(double x, double x0, double w) {
cfceb0
			return logNormalDistribuition(x, x0, w)/(w*sqrt2Pi);
cfceb0
		}
cfceb0
		
cfceb0
		public static void truncateInfiniteLine(Rectangle bounds, ref Point p0, ref Point p1) {
cfceb0
			if (p0.isEqual(p1)) return;
cfceb0
			Point d = p0 - p1;
cfceb0
			if (Math.Abs(d.x)*bounds.height > bounds.width*Math.Abs(d.y)) {
cfceb0
				// horizontal
cfceb0
				double k = d.y/d.x;
cfceb0
				p1 = new Point(bounds.x1, p0.y + k*(bounds.x1 - p0.x));
cfceb0
				p0 = new Point(bounds.x0, p0.y + k*(bounds.x0 - p0.x));
cfceb0
			} else {
cfceb0
				// vertical
cfceb0
				double k = d.x/d.y;
cfceb0
				p1 = new Point(p0.x + k*(bounds.y1 - p0.y), bounds.y1);
cfceb0
				p0 = new Point(p0.x + k*(bounds.y0 - p0.y), bounds.y0);
cfceb0
			}
cfceb0
		}
77c1c7
		
77c1c7
		public static Point noTransform(Point point) {
77c1c7
			return point;
77c1c7
		}
77c1c7
		
77c1c7
		public static Point transform(List<transformfunc> funcs, Point point) {</transformfunc>
77c1c7
			Point p = point;
77c1c7
			foreach(TransformFunc func in funcs)
77c1c7
				p = func(p);
77c1c7
			return p;
77c1c7
		}
77c1c7
77c1c7
		public static Point splinePoint(Point p0, Point p1, Point t0, Point t1, double l) {
77c1c7
			return p0*(( 2.0*l - 3.0)*l*l + 1.0)
77c1c7
			     + p1*((-2.0*l + 3.0)*l*l      )
77c1c7
			     + t0*((     l - 2.0)*l*l + l  )
77c1c7
			     + t1*((     l - 1.0)*l*l      );
77c1c7
        }
cfceb0
	}
cfceb0
}