|
|
ebcc4f |
using System;
|
|
|
ebcc4f |
|
|
|
ebcc4f |
namespace Assistance {
|
|
|
ebcc4f |
public struct Point {
|
|
|
ebcc4f |
public static readonly double precision = 0.01;
|
|
|
ebcc4f |
|
|
|
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 |
|
|
|
ebcc4f |
public static Point operator+ (Point a, Point b) {
|
|
|
ebcc4f |
return new Point(a.x + b.x, a.y + b.y);
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public static Point operator- (Point a, Point b) {
|
|
|
ebcc4f |
return new Point(a.x - b.x, a.y - b.y);
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public static Point operator* (Point a, double b) {
|
|
|
ebcc4f |
return new Point(a.x*b, a.y*b);
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public static Point operator* (double b, Point a) {
|
|
|
ebcc4f |
return a*b;
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public static Point operator/ (Point a, double b) {
|
|
|
ebcc4f |
return new Point(a.x/b, a.y/b);
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public static double dot(Point a, Point b) {
|
|
|
ebcc4f |
return a.x*b.x + a.y*b.y;
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public bool isEqual(Point other) {
|
|
|
ebcc4f |
return (this - other).lenSqr() <= precision*precision;
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public double lenSqr() {
|
|
|
ebcc4f |
return x*x + y*y;
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public double len() {
|
|
|
ebcc4f |
return Math.Sqrt(lenSqr());
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public Point normalize() {
|
|
|
ebcc4f |
double l = len();
|
|
|
ebcc4f |
return l > precision*precision*precision ? this/l : this;
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public System.Drawing.PointF toFloat() {
|
|
|
ebcc4f |
return new System.Drawing.PointF((float)x, (float)y);
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public System.Drawing.Point toInt() {
|
|
|
ebcc4f |
return new System.Drawing.Point((int)Math.Floor(x), (int)Math.Floor(y));
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|