OSDN Git Service

基準レベルを指定可能な高さクラスを追加
authorkimikage <kimikage_ceo@hotmail.com>
Thu, 7 Jun 2012 09:04:30 +0000 (18:04 +0900)
committerkimikage <kimikage_ceo@hotmail.com>
Thu, 7 Jun 2012 09:26:33 +0000 (18:26 +0900)
Yubeshi/Height.cs [new file with mode: 0755]
Yubeshi/Yubeshi.csproj
YubeshiTest/HeightTest.cs [new file with mode: 0755]
YubeshiTest/YubeshiTest.csproj

diff --git a/Yubeshi/Height.cs b/Yubeshi/Height.cs
new file mode 100755 (executable)
index 0000000..0a6745c
--- /dev/null
@@ -0,0 +1,111 @@
+/*\r
+ *     Yubeshi GPS Parser\r
+ *\r
+ *     This software is distributed under a zlib-style license.\r
+ *     See license.txt for more information.\r
+ */\r
+\r
+using System;\r
+using System.Collections.Generic;\r
+using System.Text;\r
+\r
+namespace Yubeshi\r
+{\r
+    /// <summary>\r
+    ///     Height(or Altitude) in metre\r
+    /// </summary>\r
+    public struct Height\r
+    {\r
+        #region type definitions\r
+        public enum Base : int\r
+        {\r
+            Unknown = 0,\r
+            EarthCenter = 1,\r
+            MeanSeaLevel = 2,\r
+            Geoid = 3,\r
+            Ellipsoid = 0x100,\r
+            BesselEllipsoid = Ellipsoid | 41,\r
+            Grs80Ellipsoid = Ellipsoid | 80,\r
+            Wgs84Ellipsoid = Ellipsoid | 84,\r
+        }\r
+        #endregion\r
+\r
+        #region fields\r
+        private double height;\r
+        private Base baseLevel;\r
+        #endregion\r
+\r
+        #region constructors\r
+        public Height(double height)\r
+            :this(height, Base.Unknown)\r
+        {\r
+        }\r
+\r
+        public Height(double height, Base baseLevel)\r
+        {\r
+            \r
+            this.height = height;\r
+            this.baseLevel = baseLevel;\r
+        }\r
+        #endregion\r
+\r
+        #region operators\r
+        public static implicit operator Height(double height)\r
+        {\r
+            return new Height(height);\r
+        }\r
+\r
+        public static implicit operator double(Height height)\r
+        {\r
+            return height.height;\r
+        }\r
+        \r
+        public static Height operator +(Height left, double right)\r
+        {\r
+            return new Height(left.height + right, left.baseLevel);\r
+        }\r
+\r
+        public static Height operator +(double left, Height right)\r
+        {\r
+            return new Height(right.height + left, right.baseLevel);\r
+        }\r
+\r
+        public static double operator -(Height left, Height right)\r
+        {\r
+            if (left.baseLevel != right.baseLevel)\r
+            {\r
+                if (left.baseLevel != Base.Unknown &&\r
+                                            right.baseLevel != Base.Unknown)\r
+                {\r
+                    throw new InvalidOperationException(\r
+                                                    "mismatched base level");\r
+                }\r
+            }\r
+            return left.height - right.height;\r
+        }\r
+        #endregion\r
+\r
+        #region properties\r
+\r
+        public Base BaseLevel\r
+        {\r
+            get\r
+            {\r
+                return baseLevel;\r
+            }\r
+        }\r
+\r
+        public bool IsAltitude\r
+        {\r
+            get\r
+            {\r
+                return (baseLevel == Base.MeanSeaLevel) ||\r
+                                                    (baseLevel == Base.Geoid);\r
+            }\r
+        }\r
+        #endregion\r
+\r
+        #region public methods\r
+        #endregion\r
+    }\r
+}\r
index a05c7d2..c9cde3d 100755 (executable)
@@ -94,6 +94,7 @@
     <Compile Include="UnknownPacket.cs" />\r
     <Compile Include="EnuVelocity.cs" />\r
     <Compile Include="YumaAlmanacReader.cs" />\r
+    <Compile Include="Height.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <None Include="app.config" />\r
diff --git a/YubeshiTest/HeightTest.cs b/YubeshiTest/HeightTest.cs
new file mode 100755 (executable)
index 0000000..6cf2755
--- /dev/null
@@ -0,0 +1,65 @@
+/*\r
+ *     Yubeshi GPS Parser\r
+ *\r
+ *     This software is distributed under a zlib-style license.\r
+ *     See license.txt for more information.\r
+ */\r
+\r
+using System;\r
+using System.Collections.Generic;\r
+using System.Text;\r
+using NUnit.Framework;\r
+using Yubeshi;\r
+\r
+namespace YubeshiTest\r
+{\r
+    [TestFixture]\r
+    class HeightTest\r
+    {\r
+\r
+        [Test]\r
+        public void FromDouble()\r
+        {\r
+            Height h = new Height(123.45);\r
+            Assert.AreEqual(123.45, (double)h);\r
+            Assert.AreEqual(Height.Base.Unknown, h.BaseLevel);\r
+        }\r
+\r
+        [Test]\r
+        public void Add()\r
+        {\r
+            Height h = new Height(123.45, Height.Base.Wgs84Ellipsoid);\r
+            Height ha = h + 1.0;\r
+            ha = 2.0 + ha;\r
+            Assert.AreEqual(126.45, (double)ha);\r
+            Assert.AreEqual(Height.Base.Wgs84Ellipsoid, ha.BaseLevel);\r
+        }\r
+\r
+        [Test]\r
+        public void Sub()\r
+        {\r
+            Height h1 = new Height(123.45, Height.Base.Wgs84Ellipsoid);\r
+            Height h2 = new Height(67.89, Height.Base.Wgs84Ellipsoid);\r
+\r
+            double hs = h1 - h2;\r
+            Assert.AreEqual(55.56, (double)hs);\r
+        }\r
+\r
+        [Test]\r
+        [ExpectedException(typeof(InvalidOperationException))]\r
+        public void InvalidSub()\r
+        {\r
+            Height h1 = new Height(123.45, Height.Base.Wgs84Ellipsoid);\r
+            Height h2 = new Height(67.89, Height.Base.Geoid);\r
+            double hs = h1 - h2;\r
+        }\r
+\r
+        [Test]\r
+        public void IsAltitude()\r
+        {\r
+            Assert.True(new Height(0, Height.Base.Geoid).IsAltitude);\r
+            Assert.True(new Height(1, Height.Base.MeanSeaLevel).IsAltitude);\r
+            Assert.False(new Height(2, Height.Base.Wgs84Ellipsoid).IsAltitude);\r
+        }\r
+    }\r
+}\r
index 441a11c..7ef2584 100755 (executable)
@@ -48,6 +48,7 @@
     <Compile Include="GeodeticCoordinateTest.cs" />\r
     <Compile Include="GpsTest\WordTest.cs" />\r
     <Compile Include="GpsTimeTest.cs" />\r
+    <Compile Include="HeightTest.cs" />\r
     <Compile Include="JapanTest\JpcTest.cs" />\r
     <Compile Include="NmeaTest\PacketTest.cs" />\r
     <Compile Include="NmeaTest\ParserTest.cs" />\r