wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 49  →  ?path2? @ 50
File deleted
/Geo/Constants.cs
File deleted
/Geo/GeographicCoordinate.cs
File deleted
/Geo/GeodesicExtensions.cs
File deleted
/Geo/Distance.cs
/Geodesics/Constants.cs
@@ -0,0 +1,13 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
namespace wasSharp.Geo
{
public static class Constants
{
public static readonly Distance EARTH_MEAN_RADIUS = new Distance(6371000);
}
}
/Geodesics/Distance.cs
@@ -0,0 +1,85 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
using System;
 
namespace wasSharp.Geo
{
public enum DistanceUnits
{
METERS = 1,
KILOMETERS = 2
}
 
public class Distance : IComparable<Distance>, IEquatable<Distance>
{
public Distance(double meters)
{
Meters = meters;
}
 
public double Kilometers => Meters / 1000d;
 
public double Meters { get; }
 
public int CompareTo(Distance other)
{
return Meters.CompareTo(other.Meters);
}
 
public bool Equals(Distance other)
{
return this == other;
}
 
public static bool operator >(Distance a, Distance b)
{
return a != null && b != null && a.Meters > b.Meters;
}
 
public static bool operator >=(Distance a, Distance b)
{
return (a == null && b == null) || (a != null && b != null && a.Meters >= b.Meters);
}
 
public static bool operator <(Distance a, Distance b)
{
return a != null && b != null && a.Meters < b.Meters;
}
 
public static bool operator <=(Distance a, Distance b)
{
return (a == null && b == null) || (a != null && b != null && a.Meters <= b.Meters);
}
 
public static bool operator ==(Distance a, Distance b)
{
return (ReferenceEquals(a, null) && ReferenceEquals(b, null)) ||
(!ReferenceEquals(a, null) && !ReferenceEquals(b, null) && a.Meters == b.Meters);
}
 
public static bool operator !=(Distance a, Distance b)
{
return !(a == b);
}
 
public override bool Equals(object obj)
{
if (obj == null)
return false;
 
if (obj is Distance)
return Equals(obj as Distance);
 
return ReferenceEquals(this, obj);
}
 
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
/Geodesics/GeodesicExtensions.cs
@@ -0,0 +1,37 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
using System;
 
namespace wasSharp.Geo
{
public static class GeodesicExtensions
{
public static Distance HaversineDistanceTo(this GeographicCoordinate sourceGeographicCoordinate,
GeographicCoordinate targetGeographicCoordinate)
{
return HaversineDistanceTo(sourceGeographicCoordinate, targetGeographicCoordinate, DistanceUnits.KILOMETERS);
}
 
public static Distance HaversineDistanceTo(this GeographicCoordinate sourceGeographicCoordinate,
GeographicCoordinate targetGeographicCoordinate,
DistanceUnits distanceUnits)
{
var sourcePhi = Math.PI * sourceGeographicCoordinate.Latitude / 180;
var targetPhi = Math.PI * targetGeographicCoordinate.Latitude / 180;
var deltaPhi = Math.PI * (targetPhi - sourcePhi) / 180;
var deltaLam = Math.PI * (targetGeographicCoordinate.Longitude - sourceGeographicCoordinate.Longitude) / 180;
 
var a = Math.Sin(deltaPhi / 2) * Math.Sin(deltaPhi / 2) +
Math.Cos(sourcePhi) * Math.Cos(targetPhi) *
Math.Sin(deltaLam / 2) * Math.Sin(deltaLam / 2);
 
var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
 
return new Distance(Constants.EARTH_MEAN_RADIUS.Meters * c);
}
}
}
/Geodesics/GeographicCoordinate.cs
@@ -0,0 +1,21 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
namespace wasSharp.Geo
{
public class GeographicCoordinate
{
public GeographicCoordinate(double latitude, double longitude)
{
Latitude = latitude;
Longitude = longitude;
}
 
public double Latitude { get; }
 
public double Longitude { get; }
}
}
/wasSharp.csproj
@@ -51,10 +51,10 @@
<Compile Include="Cryptography.cs" />
<Compile Include="CSV.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Geo\Constants.cs" />
<Compile Include="Geo\Distance.cs" />
<Compile Include="Geo\GeodesicExtensions.cs" />
<Compile Include="Geo\GeographicCoordinate.cs" />
<Compile Include="Geodesics\Constants.cs" />
<Compile Include="Geodesics\Distance.cs" />
<Compile Include="Geodesics\GeodesicExtensions.cs" />
<Compile Include="Geodesics\GeographicCoordinate.cs" />
<Compile Include="NetHash.cs" />
<Compile Include="IO.cs" />
<Compile Include="KeyValue.cs" />