| | | 1 | | using CounterDrone.Core.Algorithms; |
| | | 2 | | using System; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Text.Json; |
| | | 5 | | |
| | | 6 | | namespace CounterDrone.Core.Simulation |
| | | 7 | | { |
| | | 8 | | public class ControlZoneEntity |
| | | 9 | | { |
| | 1 | 10 | | public string Id { get; } |
| | 1 | 11 | | public string Name { get; } |
| | 1053 | 12 | | public List<Vector3> Vertices { get; } |
| | 76 | 13 | | public float MinAltitude { get; } |
| | 76 | 14 | | public float MaxAltitude { get; } |
| | | 15 | | |
| | 662 | 16 | | public struct Vector3 { public float X { get; set; } public float Y { get; set; } public float Z { get; set; } } |
| | | 17 | | |
| | 5 | 18 | | public ControlZoneEntity(string id, string name, string verticesJson, float minAlt, float maxAlt) |
| | 5 | 19 | | { |
| | 5 | 20 | | Id = id; |
| | 5 | 21 | | Name = name; |
| | 5 | 22 | | MinAltitude = minAlt; |
| | 5 | 23 | | MaxAltitude = maxAlt; |
| | 5 | 24 | | Vertices = JsonSerializer.Deserialize<List<Vector3>>(verticesJson) ?? new(); |
| | 5 | 25 | | } |
| | | 26 | | |
| | | 27 | | public bool ContainsPoint(float x, float y, float z) |
| | 76 | 28 | | { |
| | 77 | 29 | | if (y < MinAltitude || y > MaxAltitude) return false; |
| | | 30 | | |
| | 75 | 31 | | var vertices2D = new (float X, float Z)[Vertices.Count]; |
| | 750 | 32 | | for (int i = 0; i < Vertices.Count; i++) |
| | 300 | 33 | | vertices2D[i] = (Vertices[i].X, Vertices[i].Z); |
| | | 34 | | |
| | 75 | 35 | | return Kinematics.PointInPolygon(x, z, vertices2D); |
| | 76 | 36 | | } |
| | | 37 | | } |
| | | 38 | | } |