From 2a399ff089ec19012388e36fe3a7059f2a59f1c2 Mon Sep 17 00:00:00 2001 From: kimikage Date: Thu, 7 Jun 2012 18:04:30 +0900 Subject: [PATCH] =?utf8?q?=E5=9F=BA=E6=BA=96=E3=83=AC=E3=83=99=E3=83=AB?= =?utf8?q?=E3=82=92=E6=8C=87=E5=AE=9A=E5=8F=AF=E8=83=BD=E3=81=AA=E9=AB=98?= =?utf8?q?=E3=81=95=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Yubeshi/Height.cs | 111 +++++++++++++++++++++++++++++++++++++++++ Yubeshi/Yubeshi.csproj | 1 + YubeshiTest/HeightTest.cs | 65 ++++++++++++++++++++++++ YubeshiTest/YubeshiTest.csproj | 1 + 4 files changed, 178 insertions(+) create mode 100755 Yubeshi/Height.cs create mode 100755 YubeshiTest/HeightTest.cs diff --git a/Yubeshi/Height.cs b/Yubeshi/Height.cs new file mode 100755 index 0000000..0a6745c --- /dev/null +++ b/Yubeshi/Height.cs @@ -0,0 +1,111 @@ +/* + * Yubeshi GPS Parser + * + * This software is distributed under a zlib-style license. + * See license.txt for more information. + */ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Yubeshi +{ + /// + /// Height(or Altitude) in metre + /// + public struct Height + { + #region type definitions + public enum Base : int + { + Unknown = 0, + EarthCenter = 1, + MeanSeaLevel = 2, + Geoid = 3, + Ellipsoid = 0x100, + BesselEllipsoid = Ellipsoid | 41, + Grs80Ellipsoid = Ellipsoid | 80, + Wgs84Ellipsoid = Ellipsoid | 84, + } + #endregion + + #region fields + private double height; + private Base baseLevel; + #endregion + + #region constructors + public Height(double height) + :this(height, Base.Unknown) + { + } + + public Height(double height, Base baseLevel) + { + + this.height = height; + this.baseLevel = baseLevel; + } + #endregion + + #region operators + public static implicit operator Height(double height) + { + return new Height(height); + } + + public static implicit operator double(Height height) + { + return height.height; + } + + public static Height operator +(Height left, double right) + { + return new Height(left.height + right, left.baseLevel); + } + + public static Height operator +(double left, Height right) + { + return new Height(right.height + left, right.baseLevel); + } + + public static double operator -(Height left, Height right) + { + if (left.baseLevel != right.baseLevel) + { + if (left.baseLevel != Base.Unknown && + right.baseLevel != Base.Unknown) + { + throw new InvalidOperationException( + "mismatched base level"); + } + } + return left.height - right.height; + } + #endregion + + #region properties + + public Base BaseLevel + { + get + { + return baseLevel; + } + } + + public bool IsAltitude + { + get + { + return (baseLevel == Base.MeanSeaLevel) || + (baseLevel == Base.Geoid); + } + } + #endregion + + #region public methods + #endregion + } +} diff --git a/Yubeshi/Yubeshi.csproj b/Yubeshi/Yubeshi.csproj index a05c7d2..c9cde3d 100755 --- a/Yubeshi/Yubeshi.csproj +++ b/Yubeshi/Yubeshi.csproj @@ -94,6 +94,7 @@ + diff --git a/YubeshiTest/HeightTest.cs b/YubeshiTest/HeightTest.cs new file mode 100755 index 0000000..6cf2755 --- /dev/null +++ b/YubeshiTest/HeightTest.cs @@ -0,0 +1,65 @@ +/* + * Yubeshi GPS Parser + * + * This software is distributed under a zlib-style license. + * See license.txt for more information. + */ + +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using Yubeshi; + +namespace YubeshiTest +{ + [TestFixture] + class HeightTest + { + + [Test] + public void FromDouble() + { + Height h = new Height(123.45); + Assert.AreEqual(123.45, (double)h); + Assert.AreEqual(Height.Base.Unknown, h.BaseLevel); + } + + [Test] + public void Add() + { + Height h = new Height(123.45, Height.Base.Wgs84Ellipsoid); + Height ha = h + 1.0; + ha = 2.0 + ha; + Assert.AreEqual(126.45, (double)ha); + Assert.AreEqual(Height.Base.Wgs84Ellipsoid, ha.BaseLevel); + } + + [Test] + public void Sub() + { + Height h1 = new Height(123.45, Height.Base.Wgs84Ellipsoid); + Height h2 = new Height(67.89, Height.Base.Wgs84Ellipsoid); + + double hs = h1 - h2; + Assert.AreEqual(55.56, (double)hs); + } + + [Test] + [ExpectedException(typeof(InvalidOperationException))] + public void InvalidSub() + { + Height h1 = new Height(123.45, Height.Base.Wgs84Ellipsoid); + Height h2 = new Height(67.89, Height.Base.Geoid); + double hs = h1 - h2; + } + + [Test] + public void IsAltitude() + { + Assert.True(new Height(0, Height.Base.Geoid).IsAltitude); + Assert.True(new Height(1, Height.Base.MeanSeaLevel).IsAltitude); + Assert.False(new Height(2, Height.Base.Wgs84Ellipsoid).IsAltitude); + } + } +} diff --git a/YubeshiTest/YubeshiTest.csproj b/YubeshiTest/YubeshiTest.csproj index 441a11c..7ef2584 100755 --- a/YubeshiTest/YubeshiTest.csproj +++ b/YubeshiTest/YubeshiTest.csproj @@ -48,6 +48,7 @@ + -- 2.11.0