예제 #1
0
        public static Collision FindBetween(Point from, Point to, ConnectionZone fromEl, ConnectionZone toEl,ref HashSet<Element> elementsAlreadyCollided, List<Element> elements = null)
        {
            if (elements == null)
                elements = Element.AllElements;

            double deltaMin = double.MaxValue;
            Collision minimum = null;

            foreach (Element element in elements)
            {
                if (element == fromEl.Parent) continue;
                if (element == toEl.Parent) continue;

                bool interects = Intersects(element.A, element.B, from, to);
                if(!interects)
                    interects = Intersects(element.A, element.D, from, to);
                if (!interects)
                    interects = Intersects(element.C, element.D, from, to);
                if (!interects)
                   interects = Intersects(element.C, element.B, from, to);
                if (interects)
                {
                    double deltaX = element.Center.X - fromEl.Parent.Center.X;
                    double deltaY = element.Center.Y - fromEl.Parent.Center.Y;
                    double delta = deltaX * deltaX + deltaY * deltaY;
                    delta = Math.Sqrt(delta);
                    Collision collision = new Collision(element, from, to);
                    if (elementsAlreadyCollided.Contains(element)) continue;

                    //find closest collision
                    if (deltaMin > delta)
                    {
                        deltaMin = delta;
                        minimum = collision;
                    }
                }
            }
            if(minimum != null)
                elementsAlreadyCollided.Add(minimum.Element);
            return minimum;
        }
예제 #2
0
 public Path(ConnectionZone from, ConnectionZone to)
 {
     this.From = from;
     this.To   = to;
 }
예제 #3
0
 public Path GetPathTo(ConnectionZone to)
 {
     return(PathFromTo(this, to));
 }
예제 #4
0
 public static Path PathFromTo(ConnectionZone from, ConnectionZone to)
 {
     return(new Path(from, to));
 }
예제 #5
0
 public Path(ConnectionZone from, ConnectionZone to)
 {
     this.From = from;
     this.To = to;
 }
예제 #6
0
 public Path GetPathTo(ConnectionZone to)
 {
     return PathFromTo(this, to);
 }
예제 #7
0
 public static Path PathFromTo(ConnectionZone from, ConnectionZone to)
 {
     return new Path(from, to);
 }
예제 #8
0
 public bool FlowIsSameAs(ConnectionZone other)
 {
     if (other == null) return false;
     return this.isInFlow == other.isInFlow;
 }
예제 #9
0
 public Path(ConnectionZone from, ConnectionZone to)
 {
     this.IsNew = true;
     if (from.isInFlow == to.isInFlow) throw new ArgumentException("Two connection zones with same flow type connected");
     if (from.IsOutFlow)
     {
         this.From = from;
         this.To = to;
     }
     else
     {
         this.From = to;
         this.To = from;
     }
 }
예제 #10
0
        public static Collision FindBetween(Point from, Point to, ConnectionZone fromEl, ConnectionZone toEl,ref HashSet<Collision> lastCollision, List<Element> elements = null)
        {
            if (elements == null) elements = Element.AllElements;

            double deltaMin = double.MaxValue;
            Collision minimum = null;

            foreach (Element element in elements)
            {
                if (element == fromEl.Parent) continue;
                if (element == toEl.Parent) continue;

                Point intersection = new Point();
                bool interects = Intersects(element.A, element.B, from, to, out intersection);
                if(!interects)
                    interects = Intersects(element.A, element.D, from, to, out intersection);
                if (!interects)
                    interects = Intersects(element.C, element.D, from, to, out intersection);
                if (!interects)
                   interects = Intersects(element.C, element.B, from, to, out intersection);
                if (interects)
                //bool interects = Intersects(from, to, element);
                if (interects)
                {
                    double deltaX = element.Center.X - fromEl.Parent.Center.X;
                    double deltaY = element.Center.Y - fromEl.Parent.Center.Y;
                    double delta = deltaX * deltaX + deltaY * deltaY;
                    delta = Math.Sqrt(delta);
                    Collision collision = new Collision(intersection, element, from, to);
                    if (lastCollision.FirstOrDefault(x => x.Element == element) != null) continue;

                    if (deltaMin > delta)
                    {
                        deltaMin = delta;
                        minimum = collision;
                    }
                }
            }
            if(minimum != null)
                lastCollision.Add(minimum);
            return minimum;
        }
예제 #11
0
 public static System.Drawing.Image Icon(ConnectionZone zone)
 {
     return IconFromDictionary(ConnectionZoneIcons, zone);
 }
 public PathMidPointDrawable(int x, int y, ConnectionZone.Path path)
 {
     this.X = x;
     this.Y = y;
     this.Path = path;
 }
예제 #13
0
        public static Collision FindBetween(Point from, Point to, ConnectionZone fromEl, ConnectionZone toEl, ref HashSet <Collision> lastCollision, List <Element> elements = null)
        {
            if (elements == null)
            {
                elements = Element.AllElements;
            }

            double    deltaMin = double.MaxValue;
            Collision minimum  = null;

            foreach (Element element in elements)
            {
                if (element == fromEl.Parent)
                {
                    continue;
                }
                if (element == toEl.Parent)
                {
                    continue;
                }

                Point intersection = new Point();
                bool  interects    = Intersects(element.A, element.B, from, to, out intersection);
                if (!interects)
                {
                    interects = Intersects(element.A, element.D, from, to, out intersection);
                }
                if (!interects)
                {
                    interects = Intersects(element.C, element.D, from, to, out intersection);
                }
                if (!interects)
                {
                    interects = Intersects(element.C, element.B, from, to, out intersection);
                }
                if (interects)
                {
                    //bool interects = Intersects(from, to, element);
                    if (interects)
                    {
                        double deltaX = element.Center.X - fromEl.Parent.Center.X;
                        double deltaY = element.Center.Y - fromEl.Parent.Center.Y;
                        double delta  = deltaX * deltaX + deltaY * deltaY;
                        delta = Math.Sqrt(delta);
                        Collision collision = new Collision(intersection, element, from, to);
                        if (lastCollision.FirstOrDefault(x => x.Element == element) != null)
                        {
                            continue;
                        }

                        if (deltaMin > delta)
                        {
                            deltaMin = delta;
                            minimum  = collision;
                        }
                    }
                }
            }
            if (minimum != null)
            {
                lastCollision.Add(minimum);
            }
            return(minimum);
        }