• R/O
  • HTTP
  • SSH
  • HTTPS

yubeshi: Commit

source codes and tests


Commit MetaInfo

Revision2a399ff089ec19012388e36fe3a7059f2a59f1c2 (tree)
Time2012-06-07 18:26:33
Authorkimikage <kimikage_ceo@hotm...>
Commiterkimikage

Log Message

基準レベルを指定可能な高さクラスを追加

Change Summary

Incremental Difference

--- /dev/null
+++ b/Yubeshi/Height.cs
@@ -0,0 +1,111 @@
1+/*
2+ * Yubeshi GPS Parser
3+ *
4+ * This software is distributed under a zlib-style license.
5+ * See license.txt for more information.
6+ */
7+
8+using System;
9+using System.Collections.Generic;
10+using System.Text;
11+
12+namespace Yubeshi
13+{
14+ /// <summary>
15+ /// Height(or Altitude) in metre
16+ /// </summary>
17+ public struct Height
18+ {
19+ #region type definitions
20+ public enum Base : int
21+ {
22+ Unknown = 0,
23+ EarthCenter = 1,
24+ MeanSeaLevel = 2,
25+ Geoid = 3,
26+ Ellipsoid = 0x100,
27+ BesselEllipsoid = Ellipsoid | 41,
28+ Grs80Ellipsoid = Ellipsoid | 80,
29+ Wgs84Ellipsoid = Ellipsoid | 84,
30+ }
31+ #endregion
32+
33+ #region fields
34+ private double height;
35+ private Base baseLevel;
36+ #endregion
37+
38+ #region constructors
39+ public Height(double height)
40+ :this(height, Base.Unknown)
41+ {
42+ }
43+
44+ public Height(double height, Base baseLevel)
45+ {
46+
47+ this.height = height;
48+ this.baseLevel = baseLevel;
49+ }
50+ #endregion
51+
52+ #region operators
53+ public static implicit operator Height(double height)
54+ {
55+ return new Height(height);
56+ }
57+
58+ public static implicit operator double(Height height)
59+ {
60+ return height.height;
61+ }
62+
63+ public static Height operator +(Height left, double right)
64+ {
65+ return new Height(left.height + right, left.baseLevel);
66+ }
67+
68+ public static Height operator +(double left, Height right)
69+ {
70+ return new Height(right.height + left, right.baseLevel);
71+ }
72+
73+ public static double operator -(Height left, Height right)
74+ {
75+ if (left.baseLevel != right.baseLevel)
76+ {
77+ if (left.baseLevel != Base.Unknown &&
78+ right.baseLevel != Base.Unknown)
79+ {
80+ throw new InvalidOperationException(
81+ "mismatched base level");
82+ }
83+ }
84+ return left.height - right.height;
85+ }
86+ #endregion
87+
88+ #region properties
89+
90+ public Base BaseLevel
91+ {
92+ get
93+ {
94+ return baseLevel;
95+ }
96+ }
97+
98+ public bool IsAltitude
99+ {
100+ get
101+ {
102+ return (baseLevel == Base.MeanSeaLevel) ||
103+ (baseLevel == Base.Geoid);
104+ }
105+ }
106+ #endregion
107+
108+ #region public methods
109+ #endregion
110+ }
111+}
--- a/Yubeshi/Yubeshi.csproj
+++ b/Yubeshi/Yubeshi.csproj
@@ -94,6 +94,7 @@
9494 <Compile Include="UnknownPacket.cs" />
9595 <Compile Include="EnuVelocity.cs" />
9696 <Compile Include="YumaAlmanacReader.cs" />
97+ <Compile Include="Height.cs" />
9798 </ItemGroup>
9899 <ItemGroup>
99100 <None Include="app.config" />
--- /dev/null
+++ b/YubeshiTest/HeightTest.cs
@@ -0,0 +1,65 @@
1+/*
2+ * Yubeshi GPS Parser
3+ *
4+ * This software is distributed under a zlib-style license.
5+ * See license.txt for more information.
6+ */
7+
8+using System;
9+using System.Collections.Generic;
10+using System.Text;
11+using NUnit.Framework;
12+using Yubeshi;
13+
14+namespace YubeshiTest
15+{
16+ [TestFixture]
17+ class HeightTest
18+ {
19+
20+ [Test]
21+ public void FromDouble()
22+ {
23+ Height h = new Height(123.45);
24+ Assert.AreEqual(123.45, (double)h);
25+ Assert.AreEqual(Height.Base.Unknown, h.BaseLevel);
26+ }
27+
28+ [Test]
29+ public void Add()
30+ {
31+ Height h = new Height(123.45, Height.Base.Wgs84Ellipsoid);
32+ Height ha = h + 1.0;
33+ ha = 2.0 + ha;
34+ Assert.AreEqual(126.45, (double)ha);
35+ Assert.AreEqual(Height.Base.Wgs84Ellipsoid, ha.BaseLevel);
36+ }
37+
38+ [Test]
39+ public void Sub()
40+ {
41+ Height h1 = new Height(123.45, Height.Base.Wgs84Ellipsoid);
42+ Height h2 = new Height(67.89, Height.Base.Wgs84Ellipsoid);
43+
44+ double hs = h1 - h2;
45+ Assert.AreEqual(55.56, (double)hs);
46+ }
47+
48+ [Test]
49+ [ExpectedException(typeof(InvalidOperationException))]
50+ public void InvalidSub()
51+ {
52+ Height h1 = new Height(123.45, Height.Base.Wgs84Ellipsoid);
53+ Height h2 = new Height(67.89, Height.Base.Geoid);
54+ double hs = h1 - h2;
55+ }
56+
57+ [Test]
58+ public void IsAltitude()
59+ {
60+ Assert.True(new Height(0, Height.Base.Geoid).IsAltitude);
61+ Assert.True(new Height(1, Height.Base.MeanSeaLevel).IsAltitude);
62+ Assert.False(new Height(2, Height.Base.Wgs84Ellipsoid).IsAltitude);
63+ }
64+ }
65+}
--- a/YubeshiTest/YubeshiTest.csproj
+++ b/YubeshiTest/YubeshiTest.csproj
@@ -48,6 +48,7 @@
4848 <Compile Include="GeodeticCoordinateTest.cs" />
4949 <Compile Include="GpsTest\WordTest.cs" />
5050 <Compile Include="GpsTimeTest.cs" />
51+ <Compile Include="HeightTest.cs" />
5152 <Compile Include="JapanTest\JpcTest.cs" />
5253 <Compile Include="NmeaTest\PacketTest.cs" />
5354 <Compile Include="NmeaTest\ParserTest.cs" />
Show on old repository browser