using System; using System.Collections.Generic; using System.Text; using System.Drawing; namespace SimpleRadar { public class Sector { public static float Ratio = (float)(8); static public bool PointInPolygon(PointF p, Sector sect) { PointF p1, p2; bool inside = false; foreach (Slice slice in sect.Slices) { PointF[] poly = slice.Points; if (poly.Length < 3) { return inside; } PointF oldPoint = new PointF( poly[poly.Length - 1].X, poly[poly.Length - 1].Y); for (int i = 0; i < poly.Length; i++) { PointF newPoint = new PointF(poly[i].X, poly[i].Y); if (newPoint.X > oldPoint.X) { p1 = oldPoint; p2 = newPoint; } else { p1 = newPoint; p2 = oldPoint; } if ((newPoint.X < p.X) == (p.X <= oldPoint.X) && ((long)p.Y - (long)p1.Y) * (long)(p2.X - p1.X) < ((long)p2.Y - (long)p1.Y) * (long)(p.X - p1.X)) { inside = !inside; } oldPoint = newPoint; } if (inside == true) break; } return inside; } public bool IsSelected = false; public struct Slice { public int Floor; public int Ceiling; public PointF[] Points; } private string _Name; public string Name { get { return _Name; } set { _Name = value; } } public Slice[] Slices; public override string ToString() { return _Name; } public void Draw(Graphics g, Pen p) { if (IsSelected) p = new Pen(Brushes.Red, 5.0f); PointF p1, p2; foreach (Slice s in Slices) { for (int i = 0; i < (s.Points.Length - 1); i++) { p1 = s.Points[i] ; p2 = s.Points[i + 1]; g.DrawLine(p, (float)PanAndZoomX(p1.X / Ratio), (float)PanAndZoomY(p1.Y / Ratio), (float)PanAndZoomX(p2.X / Ratio), (float)PanAndZoomY(p2.Y / Ratio)); } } } public Sector(sectorsSector raw) { _Name = raw.name; Slices = new Slice[raw.slice.Length]; int indexSlice = 0; foreach (sectorsSectorSlice s in raw.slice) { Slices[indexSlice].Floor = s.floor; Slices[indexSlice].Ceiling = s.ceiling; Slices[indexSlice].Points = new PointF[s.vertex.Length]; int indexVextex = 0; foreach (sectorsSectorSliceVertex v in s.vertex) { Slices[indexSlice].Points[indexVextex] = MathCautra.ToCautra4(v.lat, v.lon); indexVextex++; } indexSlice++; } } #region Delegate Pan And Zoom public delegate double PanAndZoom(double input); [NonSerialized] static public PanAndZoom PanAndZoomX; [NonSerialized] static public PanAndZoom PanAndZoomY; #endregion } }