1
0
Fork 0
forked from aly/qstbak
qstbak/SmartNav.Model/SmartNav.Model.Navigation/SubRegionDefinition.cs
2026-08-17 20:29:32 +10:00

49 lines
965 B
C#

using System.Collections.Generic;
namespace SmartNav.Model.Navigation;
public sealed class SubRegionDefinition
{
public string Id { get; set; } = string.Empty;
public string? Comment { get; set; }
public float? MinY { get; set; }
public float? MaxY { get; set; }
public List<SubRegionVertex> Vertices { get; set; } = new List<SubRegionVertex>();
public bool Contains(float x, float y, float z)
{
if (MinY.HasValue && y < MinY.Value)
{
return false;
}
if (MaxY.HasValue && y > MaxY.Value)
{
return false;
}
int count = Vertices.Count;
if (count < 3)
{
return false;
}
bool flag = false;
int num = 0;
int index = count - 1;
while (num < count)
{
float x2 = Vertices[num].X;
float z2 = Vertices[num].Z;
float x3 = Vertices[index].X;
float z3 = Vertices[index].Z;
if (z2 > z != z3 > z && x < (x3 - x2) * (z - z2) / (z3 - z2) + x2)
{
flag = !flag;
}
index = num++;
}
return flag;
}
}