private ArbiterZoneNavigableNode[][] NodeMatrix(ArbiterZone az)
        {
            // get bL and tR
            Coordinates bl;
            Coordinates tr;

            this.GetBoundingPoints(az, out bl, out tr);
            int n = (int)tr.Y;
            int s = (int)bl.Y;
            int e = (int)tr.X;
            int w = (int)bl.X;

            // create matrix
            ArbiterZoneNavigableNode[][] nodeMatrix = new ArbiterZoneNavigableNode[e - w + 1][];

            // loop through coordinates
            for (int i = w; i <= e; i++)
            {
                for (int j = s; j <= n; j++)
                {
                    // position
                    Coordinates c = new Coordinates((double)i, (double)j);

                    // check inside perimeter
                    if (az.Perimeter.PerimeterPolygon.IsInside(c))
                    {
                        // check interacts
                        bool clear = true;
                        foreach (Polygon o in az.StayOutAreas)
                        {
                            if (o.IsInside(c))
                            {
                                clear = false;
                            }
                        }

                        // not inside out of polys
                        if (clear)
                        {
                            nodeMatrix[i - w][j - s] = new ArbiterZoneNavigableNode(c);
                        }
                    }
                }
            }

            // return
            return(nodeMatrix);
        }
        private ArbiterZoneNavigableNode[][] NodeMatrix(ArbiterZone az)
        {
            // get bL and tR
            Coordinates bl;
            Coordinates tr;
            this.GetBoundingPoints(az, out bl, out tr);
            int n = (int)tr.Y;
            int s = (int)bl.Y;
            int e = (int)tr.X;
            int w = (int)bl.X;

            // create matrix
            ArbiterZoneNavigableNode[][] nodeMatrix = new ArbiterZoneNavigableNode[e - w + 1][];

            // loop through coordinates
            for (int i = w; i <= e; i++)
            {
                for (int j = s; j <= n; j++)
                {
                    // position
                    Coordinates c = new Coordinates((double)i, (double)j);

                    // check inside perimeter
                    if (az.Perimeter.PerimeterPolygon.IsInside(c))
                    {
                        // check interacts
                        bool clear = true;
                        foreach (Polygon o in az.StayOutAreas)
                        {
                            if (o.IsInside(c))
                                clear = false;
                        }

                        // not inside out of polys
                        if (clear)
                        {
                            nodeMatrix[i - w][j - s] = new ArbiterZoneNavigableNode(c);
                        }
                    }
                }
            }

            // return
            return nodeMatrix;
        }
        public void Click(Coordinates c)
        {
            if (this.zt.Mode == ZoneToolboxMode.Selection)
            {
                this.zt.SelectZone(c);
            }
            else if (this.Mode == ZoneToolboxMode.NavNodes && this.zt.current != null)
            {
                // save undo point
                this.ed.SaveUndoPoint();

                // check if we hit any of hte edges or nodes part of the zone
                ArbiterZone az = this.zt.current;

                // check if hit node or edge
                NavigableEdge ne;
                INavigableNode nn;
                this.NavigationHitTest(c, out nn, out ne);

                if (nn != null)
                {
                    // create new node
                    INavigableNode aznn = nn;

                    if (this.PreviousNode != null)
                    {
                        // create new edges
                        NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List<IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE1);
                        this.zt.current.NavigableEdges.Add(newE1);
                    }

                    this.PreviousNode = aznn;
                }
                else if (ne != null)
                {
                    // remove old
                    this.zt.current.NavigableEdges.Remove(ne);

                    // remove all references
                    ne.Start.OutgoingConnections.Remove(ne);

                    // create new node
                    ArbiterZoneNavigableNode aznn = new ArbiterZoneNavigableNode(c);

                    // create new edges
                    NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List<IConnectAreaWaypoints>(), ne.Start, aznn);
                    NavigableEdge newE2 = new NavigableEdge(true, this.zt.current, false, null, new List<IConnectAreaWaypoints>(), aznn, ne.End);

                    // add edges
                    ne.Start.OutgoingConnections.Add(newE1);
                    aznn.OutgoingConnections.Add(newE2);

                    // add all to lists
                    this.zt.current.NavigableEdges.Add(newE1);
                    this.zt.current.NavigableEdges.Add(newE2);
                    this.zt.current.NavigationNodes.Add(aznn);

                    if (this.PreviousNode != null)
                    {
                        NavigableEdge newE3 = new NavigableEdge(true, this.zt.current, false, null, new List<IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE3);
                        this.zt.current.NavigableEdges.Add(newE3);
                    }

                    this.PreviousNode = aznn;
                }
                else
                {
                    // create new node
                    ArbiterZoneNavigableNode aznn = new ArbiterZoneNavigableNode(c);

                    if (this.PreviousNode != null)
                    {
                        // create new edges
                        NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List<IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE1);
                        this.zt.current.NavigableEdges.Add(newE1);
                    }

                    this.PreviousNode = aznn;
                    this.zt.current.NavigationNodes.Add(aznn);
                }
            }
            else if (this.zt.Mode == ZoneToolboxMode.StayOut && this.zt.current != null)
            {
                if (this.WrappingHelpers.Count == 0)
                {
                    this.WrappingHelpers.Add(c);
                }
                else
                {
                    // Determine size of bounding box
                    float scaled_offset = 1 / this.rd.WorldTransform.Scale;

                    // invert the scale
                    float scaled_size = DrawingUtility.cp_large_size;

                    // assume that the world transform is currently applied correctly to the graphics
                    RectangleF rect = new RectangleF((float)c.X - scaled_size / 2, (float)c.Y - scaled_size / 2, scaled_size, scaled_size);

                    if (rect.Contains(DrawingUtility.ToPointF(this.WrappingHelpers[0])) &&
                        c.DistanceTo(this.WrappingHelpers[0]) < 1)
                    {
                        ed.SaveUndoPoint();
                        Polygon p = new Polygon(this.WrappingHelpers);
                        this.zt.current.StayOutAreas.Add(p);
                        this.WrappingHelpers = new List<Coordinates>();
                    }
                    else
                        this.WrappingHelpers.Add(c);
                }

                this.rd.Invalidate();
            }
        }
        public void Click(Coordinates c)
        {
            if (this.zt.Mode == ZoneToolboxMode.Selection)
            {
                this.zt.SelectZone(c);
            }
            else if (this.Mode == ZoneToolboxMode.NavNodes && this.zt.current != null)
            {
                // save undo point
                this.ed.SaveUndoPoint();

                // check if we hit any of hte edges or nodes part of the zone
                ArbiterZone az = this.zt.current;

                // check if hit node or edge
                NavigableEdge  ne;
                INavigableNode nn;
                this.NavigationHitTest(c, out nn, out ne);

                if (nn != null)
                {
                    // create new node
                    INavigableNode aznn = nn;

                    if (this.PreviousNode != null)
                    {
                        // create new edges
                        NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE1);
                        this.zt.current.NavigableEdges.Add(newE1);
                    }

                    this.PreviousNode = aznn;
                }
                else if (ne != null)
                {
                    // remove old
                    this.zt.current.NavigableEdges.Remove(ne);

                    // remove all references
                    ne.Start.OutgoingConnections.Remove(ne);

                    // create new node
                    ArbiterZoneNavigableNode aznn = new ArbiterZoneNavigableNode(c);

                    // create new edges
                    NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), ne.Start, aznn);
                    NavigableEdge newE2 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), aznn, ne.End);

                    // add edges
                    ne.Start.OutgoingConnections.Add(newE1);
                    aznn.OutgoingConnections.Add(newE2);

                    // add all to lists
                    this.zt.current.NavigableEdges.Add(newE1);
                    this.zt.current.NavigableEdges.Add(newE2);
                    this.zt.current.NavigationNodes.Add(aznn);

                    if (this.PreviousNode != null)
                    {
                        NavigableEdge newE3 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE3);
                        this.zt.current.NavigableEdges.Add(newE3);
                    }

                    this.PreviousNode = aznn;
                }
                else
                {
                    // create new node
                    ArbiterZoneNavigableNode aznn = new ArbiterZoneNavigableNode(c);

                    if (this.PreviousNode != null)
                    {
                        // create new edges
                        NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE1);
                        this.zt.current.NavigableEdges.Add(newE1);
                    }

                    this.PreviousNode = aznn;
                    this.zt.current.NavigationNodes.Add(aznn);
                }
            }
            else if (this.zt.Mode == ZoneToolboxMode.StayOut && this.zt.current != null)
            {
                if (this.WrappingHelpers.Count == 0)
                {
                    this.WrappingHelpers.Add(c);
                }
                else
                {
                    // Determine size of bounding box
                    float scaled_offset = 1 / this.rd.WorldTransform.Scale;

                    // invert the scale
                    float scaled_size = DrawingUtility.cp_large_size;

                    // assume that the world transform is currently applied correctly to the graphics
                    RectangleF rect = new RectangleF((float)c.X - scaled_size / 2, (float)c.Y - scaled_size / 2, scaled_size, scaled_size);

                    if (rect.Contains(DrawingUtility.ToPointF(this.WrappingHelpers[0])) &&
                        c.DistanceTo(this.WrappingHelpers[0]) < 1)
                    {
                        ed.SaveUndoPoint();
                        Polygon p = new Polygon(this.WrappingHelpers);
                        this.zt.current.StayOutAreas.Add(p);
                        this.WrappingHelpers = new List <Coordinates>();
                    }
                    else
                    {
                        this.WrappingHelpers.Add(c);
                    }
                }

                this.rd.Invalidate();
            }
        }