Files
win8phoneApp/CampusAppWP8/CampusAppWPortalLib8/Model/Utility/MapPoint.cs
2013-10-22 12:15:42 +02:00

140 lines
5.2 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="MapPoint.cs" company="BTU/IIT">
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
// </copyright>
// <author>Stubbfel</author>
// <date>22.10.2013</date>
// <summary>Implements the map point class</summary>
//-----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.Utility
{
using System;
/// <summary> A map point. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <seealso cref="T:System.IEquatable{CampusAppWPortalLib8.Model.Utility.MapPoint}"/>
public class MapPoint : IEquatable<MapPoint>
{
#region Constructor
/// <summary> Initializes a new instance of the MapPoint class. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
public MapPoint()
{
}
/// <summary> Initializes a new instance of the MapPoint class. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="x"> The x coordinate. </param>
/// <param name="y"> The y coordinate. </param>
public MapPoint(double x, double y)
{
this.X = x;
this.Y = y;
}
#endregion
#region property
/// <summary> Gets or sets the x coordinate. </summary>
/// <value> The x coordinate. </value>
public double X { get; set; }
/// <summary> Gets or sets the y coordinate. </summary>
/// <value> The y coordinate. </value>
public double Y { get; set; }
#endregion
#region method
/// <summary> Addition operator. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="mp1"> The first mapPoint. </param>
/// <param name="mp2"> The second mapPoint. </param>
/// <returns> The result of the operation. </returns>
public static MapPoint operator +(MapPoint mp1, MapPoint mp2)
{
return new MapPoint(mp1.X + mp2.X, mp1.Y + mp2.Y);
}
/// <summary> Subtraction operator. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="mp1"> The first mapPoint. </param>
/// <param name="mp2"> The second mapPoint. </param>
/// <returns> The result of the operation. </returns>
public static MapPoint operator -(MapPoint mp1, MapPoint mp2)
{
return new MapPoint(mp1.X - mp2.X, mp1.Y - mp2.Y);
}
/// <summary> Negation operator. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="mp1"> The mapPoint. </param>
/// <returns> The result of the operation. </returns>
public static MapPoint operator -(MapPoint mp1)
{
return new MapPoint(-mp1.X, -mp1.Y);
}
/// <summary> Multiplication operator. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="mp1"> The first mapPoint. </param>
/// <param name="mp2"> The second mapPoint. </param>
/// <returns> The result of the operation. </returns>
public static MapPoint operator *(MapPoint mp1, MapPoint mp2)
{
return new MapPoint(mp1.X * mp2.X, mp1.Y * mp2.Y);
}
/// <summary> Division operator. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="mp1"> The first mapPoint. </param>
/// <param name="mp2"> The second mapPoint. </param>
/// <returns> The result of the operation. </returns>
public static MapPoint operator /(MapPoint mp1, MapPoint mp2)
{
return new MapPoint(mp1.X / mp2.X, mp1.Y / mp2.Y);
}
/// <summary> Calculates the distance. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="src"> Start Point. </param>
/// <param name="dst"> End Point. </param>
/// <returns> The calculated distance. </returns>
public static double CalcDistance(MapPoint src, MapPoint dst)
{
MapPoint subPoint = dst - src;
subPoint *= subPoint;
double result = Math.Sqrt(subPoint.X + subPoint.Y);
return result;
}
/// <summary> Calculates the distance. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="other"> The map point to compare to this object. </param>
/// <returns> The calculated distance. </returns>
public double CalcDistance(MapPoint other)
{
return MapPoint.CalcDistance(other, this);
}
/// <summary> Tests if this MapPoint is considered equal to another. </summary>
/// <remarks> Stubbfel, 22.10.2013. </remarks>
/// <param name="other"> The map point to compare to this object. </param>
/// <returns> true if the objects are considered equal, false if they are not. </returns>
public bool Equals(MapPoint other)
{
if (other != null && this.X == other.X && this.Y == other.Y)
{
return true;
}
return false;
}
#endregion
}
}