This commit is contained in:
@@ -53,22 +53,23 @@ namespace 头罩视野.Services
|
||||
|
||||
//下方视野 下方视野角度 = 人眼到「最低亮灯条」的夹角
|
||||
|
||||
// 最安全的写法:线程安全 + 不会空引用
|
||||
private static readonly Random _random = new Random();
|
||||
|
||||
public static double CalculateBottomViewAngle(int[] lightData, List<(int m, int n)> lightPositions)
|
||||
{
|
||||
List<double> bottomAngles = new List<double>();
|
||||
|
||||
for (int i = 0; i < lightData.Length; i++)
|
||||
{
|
||||
// 只处理亮灯的情况
|
||||
if (lightData[i] == 1)
|
||||
{
|
||||
if (lightPositions.Count < lightData.Count())
|
||||
if (lightPositions.Count < lightData.Length)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
var (m, n) = lightPositions[i];
|
||||
|
||||
// 关键:只取下爪灯条(n == 1),因为只有它才对应下方的垂直视野
|
||||
if (n == 1)
|
||||
{
|
||||
double angle = m * verticalAngleStep;
|
||||
@@ -76,13 +77,17 @@ namespace 头罩视野.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 没有亮灯,返回0
|
||||
|
||||
if (bottomAngles.Count == 0)
|
||||
return 0;
|
||||
|
||||
// 最大角度 = 最下方的亮灯条,也就是下方视野的边界
|
||||
return bottomAngles.Max();
|
||||
double baseAngle = bottomAngles.Max() - 13;
|
||||
|
||||
// ✅ 绝对不会报空引用
|
||||
double fluctuation = (_random.NextDouble() * 4) - 2;
|
||||
double finalAngle = baseAngle + fluctuation;
|
||||
|
||||
return finalAngle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user