wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 13  →  ?path2? @ 14
/Geo/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);
}
}
/Geo/Distance.cs
@@ -0,0 +1,88 @@
///////////////////////////////////////////////////////////////////////////
// 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
{
get { return 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();
}
}
}
/Geo/GeodesicExtensions.cs
@@ -0,0 +1,38 @@
///////////////////////////////////////////////////////////////////////////
// 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);
}
}
}
/Geo/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; }
}
}
/Web/wasHTTPClient.cs
@@ -18,7 +18,7 @@
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
// <summary>A portable HTTP client.</summar>
public class wasHTTPClient
public class wasHTTPClient : IDisposable
{
private readonly HttpClient HTTPClient;
private readonly string MediaType;
@@ -267,5 +267,33 @@
return null;
}
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends a GET request to an URL with set key-value pairs.
/// </summary>
/// <param name="URL">the url to send the message to</param>
public async Task<byte[]> GET(string URL)
{
try
{
using (var response = await HTTPClient.GetAsync(URL))
{
return response.IsSuccessStatusCode ? await response.Content.ReadAsByteArrayAsync() : null;
}
}
catch (Exception)
{
return null;
}
}
 
public void Dispose()
{
if (HTTPClient != null)
HTTPClient.Dispose();
}
}
}
/wasSharp.csproj
@@ -45,6 +45,10 @@
<Compile Include="Collections\Generic\SerializableSortedDictionary.cs" />
<Compile Include="Cryptography.cs" />
<Compile Include="CSV.cs" />
<Compile Include="Geo\Constants.cs" />
<Compile Include="Geo\Distance.cs" />
<Compile Include="Geo\GeodesicExtensions.cs" />
<Compile Include="Geo\GeographicCoordinate.cs" />
<Compile Include="IO.cs" />
<Compile Include="KeyValue.cs" />
<Compile Include="Linq.cs" />