Blame mono/Assistance/Point.cs

ebcc4f
using System;
ebcc4f
ebcc4f
namespace Assistance {
ebcc4f
	public struct Point {
ebcc4f
		public double x;
ebcc4f
		public double y;
ebcc4f
ebcc4f
		public Point(double x, double y) {
ebcc4f
			this.x = x;
ebcc4f
			this.y = y;
ebcc4f
		}
ebcc4f
b82ef4
		public static Point operator+ (Point a, Point b)
b82ef4
			{ return new Point(a.x + b.x, a.y + b.y); }
b82ef4
		public static Point operator- (Point a, Point b)
b82ef4
			{ return new Point(a.x - b.x, a.y - b.y); }
b82ef4
		public static Point operator* (Point a, double b)
b82ef4
			{ return new Point(a.x*b, a.y*b); }
b82ef4
		public static Point operator* (double b, Point a)
b82ef4
			{ return a*b; }
b82ef4
		public static Point operator/ (Point a, double b)
b82ef4
			{ return new Point(a.x/b, a.y/b); }
b82ef4
		public static double dot(Point a, Point b)
b82ef4
			{ return a.x*b.x + a.y*b.y; }
b82ef4
b82ef4
		public bool isEqual(Point other)
a62e15
			{ return (this - other).lenSqr() <= Geometry.precisionSqr; }
b82ef4
		public double lenSqr()
b82ef4
			{ return x*x + y*y; }
b82ef4
		public double len()
b82ef4
			{ return Math.Sqrt(lenSqr()); }
ebcc4f
ebcc4f
		public Point normalize() {
ebcc4f
			double l = len();
a62e15
			return l > Geometry.precision ? this/l : this;
ebcc4f
		}
ebcc4f
72b17c
		public Point rotate(double angle) {
72b17c
			double s = Math.Sin(angle);
72b17c
			double c = Math.Cos(angle);
72b17c
			return new Point(c*x - s*y, s*x + c*y);
72b17c
		}
ebcc4f
	}
ebcc4f
}
ebcc4f