-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point.cs
65 lines (55 loc) · 1.49 KB
/
Point.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
namespace ShapesGraphics
{
[Serializable]
// public class Point
public struct Point
{
// ----
// Data
// ----
public int X { get; set; }
public int Y { get; set; }
// -------
// Methods
// -------
public Point(int x, int y) : this()
{
this.X = x;
this.Y = y;
}
// Return distance to (0,0)
public float Distance()
{
return Distance(X, 0, Y, 0);
}
// Return distance to (x,y)
public float Distance(int x, int y)
{
return Distance(X, x, Y, x);
}
// Return distance to (p.x, p.y)
public float Distance(Point p)
{
return Distance(X, p.X, Y, p.Y);
}
// Return distance between (x1,x2) & (y1,y2)
private float Distance(int x1, int x2, int y1, int y2)
{
return Convert.ToSingle(Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)));
}
public override string ToString()
{
return String.Format("({0},{1})", X.ToString(), Y.ToString());
}
//public override bool Equals(object obj)
//{
// if (obj == null)
// return false;
// if (obj.GetType().Name != "Point")
// return false;
// Point p = (Point)obj;
// return (p.X == this.X) && (p.Y == this.Y);
//}
}
}