-
Notifications
You must be signed in to change notification settings - Fork 7
/
Point2D.cs
53 lines (47 loc) · 1.36 KB
/
Point2D.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
using System;
namespace ExerciseSolution
{
/// <summary>
/// Represent a point in 2D.
/// </summary>
public class Point2D
{
/// <summary>
/// The x value of the point.
/// </summary>
public int X;
/// <summary>
/// The y value of the point.
/// </summary>
public int Y;
/// <summary>
/// Constructor. Assign 0 to the coordinates.
/// </summary>
public Point2D()
{
X = 0;
Y = 0;
}
/// <summary>
/// Constructor. Assign the parameters to the coordinates.
/// </summary>
/// <param name="x">the x coordinate</param>
/// <param name="y">the y coordinate</param>
public Point2D(int x, int y)
{
X = x;
Y = y;
}
/// <summary>
/// Calculates the euclidean distance between this and the parameter point.
/// </summary>
/// <param name="point">the other point</param>
/// <returns>the distance between the points</returns>
public double calculateEuclideanDistanceTo(Point2D point)
{
double distance = Math.Sqrt((this.X - point.X) * (this.X - point.X) +
(this.Y - point.Y) * (this.Y - point.Y));
return distance;
}
}
}