165 lines
6.3 KiB
C#
165 lines
6.3 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;
|
|
}
|
|
|
|
/// <summary> Rotate degrees. </summary>
|
|
/// <remarks> Fiedler, 13.11.2013. </remarks>
|
|
/// <param name="fixPoint"> The fix point. </param>
|
|
/// <param name="angleDeg"> The angle degrees. positive values -> counterclockwise rotation.</param>
|
|
/// <returns> A MapPoint. </returns>
|
|
public MapPoint RotateDeg(MapPoint fixPoint, double angleDeg)
|
|
{
|
|
return this.Rotate(fixPoint, angleDeg * (Math.PI / 180));
|
|
}
|
|
|
|
/// <summary> Rotates. </summary>
|
|
/// <remarks> Fiedler, 13.11.2013. </remarks>
|
|
/// <param name="fixPoint"> The fix point. </param>
|
|
/// <param name="angleRad"> The angle radians. positive values -> counterclockwise rotation.</param>
|
|
/// <returns> A MapPoint. </returns>
|
|
public MapPoint Rotate(MapPoint fixPoint, double angleRad)
|
|
{
|
|
MapPoint retValue = new MapPoint(0, 0);
|
|
|
|
retValue.X = fixPoint.X + (this.X - fixPoint.X) * Math.Cos(angleRad) - (this.Y - fixPoint.Y) * Math.Sin(angleRad);
|
|
retValue.Y = fixPoint.Y + (this.X - fixPoint.X) * Math.Sin(angleRad) + (this.Y - fixPoint.Y) * Math.Cos(angleRad);
|
|
|
|
return retValue;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|