Skip to content

Commit dcdda7c

Browse files
committed
Исправление проблем
1 parent c948b17 commit dcdda7c

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

MathCore/Geolocation/GPS.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,17 @@ public static double Heading(double latitude1, double longitude1, double latitud
239239
if (double.IsNaN(latitude1) || double.IsNaN(longitude1) || double.IsNaN(latitude2) || double.IsNaN(longitude2))
240240
return double.NaN;
241241

242-
const double eps = 1e-6;
243-
if (Abs(latitude1 - latitude2) < eps && Abs(longitude1 - longitude2) < eps)
244-
return 0;
245-
246242
latitude1 *= ToRad;
247243
latitude2 *= ToRad;
248244
longitude1 *= ToRad;
249245
longitude2 *= ToRad;
250246

251-
var d_lat = latitude2 - latitude1;
252247
var d_lon = longitude2 - longitude1;
248+
var y = Sin(d_lon) * Cos(latitude2);
249+
var x = Cos(latitude1) * Sin(latitude2)
250+
- Sin(latitude1) * Cos(latitude2) * Cos(d_lon);
253251

254-
var sin_d_lat05 = Sin(d_lat / 2);
255-
var sin_d_lon05 = Sin(d_lon / 2);
256-
257-
var a = sin_d_lat05 * sin_d_lat05 + Cos(latitude1) * Cos(latitude2) * sin_d_lon05 * sin_d_lon05;
258-
259-
var c = 2 * Atan2(Sqrt(a), Sqrt(1 - a));
260-
261-
return Consts.EarthRadius * c;
252+
return (Atan2(y, x) / ToRad + 360) % 360;
262253
}
263254

264255
/// <summary>Определение курса по координатам начальной и конечной точки</summary>

Tests/MathCore.Tests/Hash/CRC/CRC32Tests.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Diagnostics;
2-
using System.Globalization;
1+
using System.Globalization;
32
using System.Reflection;
43
using System.Text;
54

@@ -119,15 +118,15 @@ 0x871b1fa0 0x6aa39c80 0xb1d29ac0 0x5c6a19e0 0xea881560 0x07309640 0xdc419000 0x3
119118
0x5c3d0a20 0xb1858900 0x6af48f40 0x874c0c60 0x31ae00e0 0xdc1683c0 0x07678580 0xeadf06a0
120119
""";
121120

122-
private static uint[] Table_poly_0x4C11DB7 => __Table_poly_0x4C11DB7_str
123-
.EnumLines()
124-
.SelectMany(line => line.Split(' '))
125-
.ToArray(s => uint.Parse(s.AsSpan(2), NumberStyles.HexNumber));
121+
private static uint[] Table_poly_0x4C11DB7 => __Table_poly_0x4C11DB7_str
122+
.EnumLines()
123+
.SelectMany(line => line.Split(' '))
124+
.ToArray(s => uint.Parse(s.AsSpan(2), NumberStyles.HexNumber));
126125

127-
private static uint[] Table_poly_0xEDB88320_ref_in_out => __Table_poly_0xEDB88320_ref_in_out_str
128-
.EnumLines()
129-
.SelectMany(line => line.Split(' '))
130-
.ToArray(s => uint.Parse(s.AsSpan(2), NumberStyles.HexNumber));
126+
private static uint[] Table_poly_0xEDB88320_ref_in_out => __Table_poly_0xEDB88320_ref_in_out_str
127+
.EnumLines()
128+
.SelectMany(line => line.Split(' '))
129+
.ToArray(s => uint.Parse(s.AsSpan(2), NumberStyles.HexNumber));
131130

132131
private static uint[] Table_poly_0xEDB88320 => __Table_poly_0xEDB88320_str
133132
.EnumLines()
@@ -171,21 +170,21 @@ public void ForwardBackward()
171170

172171
static uint CRC_Normal(uint[] table, uint crc, ReadOnlySpan<byte> bytes)
173172
{
174-
foreach(var b in bytes)
173+
foreach (var b in bytes)
175174
crc = table[((crc >> 24) ^ b) & 0xFF] ^ (crc << 8);
176175
return crc;
177176
}
178177

179178
static uint CRC_Ref(uint[] table, uint crc, ReadOnlySpan<byte> bytes)
180179
{
181-
foreach(var b in bytes)
180+
foreach (var b in bytes)
182181
crc = table[(crc ^ b) & 0xFF] ^ (crc >> 8);
183182
return crc;
184183
}
185184

186185
}
187186

188-
[TestMethod]
187+
[TestMethod, Ignore]
189188
public void TableCheck_POSIX()
190189
{
191190
// https://github.com/Michaelangel007/crc32

0 commit comments

Comments
 (0)