Blame mono/EllipseTruncate/Point.cs

4ef489
using System;
4ef489
4ef489
namespace EllipseTruncate {
4ef489
	public struct Point {
4ef489
		public double x;
4ef489
		public double y;
4ef489
4ef489
		public Point(double x, double y) {
4ef489
			this.x = x;
4ef489
			this.y = y;
4ef489
		}
4ef489
4ef489
		public static Point operator+ (Point a, Point b)
4ef489
			{ return new Point(a.x + b.x, a.y + b.y); }
4ef489
		public static Point operator- (Point a, Point b)
4ef489
			{ return new Point(a.x - b.x, a.y - b.y); }
4ef489
		public static double operator* (Point b, Point a)
4ef489
			{ return a.x*b.x + a.y*b.y; }
4ef489
		public static Point operator* (Point a, double b)
4ef489
			{ return new Point(a.x*b, a.y*b); }
4ef489
		public static Point operator* (double b, Point a)
4ef489
			{ return a*b; }
4ef489
		public static Point operator/ (Point a, double b)
4ef489
			{ return new Point(a.x/b, a.y/b); }
4ef489
4ef489
		public bool isEqual(Point other)
4ef489
			{ return (this - other).lenSqr() <= Geometry.precisionSqr; }
4ef489
		public double lenSqr()
4ef489
			{ return x*x + y*y; }
4ef489
		public double len()
4ef489
			{ return Math.Sqrt(lenSqr()); }
4ef489
4ef489
		public Point normalize() {
4ef489
			double l = len();
4ef489
			return l > Geometry.precision ? this/l : this;
4ef489
		}
4ef489
4ef489
		public Point rotate90()
4ef489
			{ return new Point(-y, x); }
4ef489
4ef489
		public Point rotate180()
4ef489
			{ return new Point(-x, -y); }
4ef489
4ef489
		public Point rotate270()
4ef489
			{ return new Point(y, -x); }
4ef489
4ef489
		public Point rotate(double angle) {
4ef489
			double s = Math.Sin(angle);
4ef489
			double c = Math.Cos(angle);
4ef489
			return new Point(c*x - s*y, s*x + c*y);
4ef489
		}
4ef489
		
4ef489
		public double atan()
4ef489
			{ return Math.Atan2(y, x); }
4ef489
	}
4ef489
}
4ef489