Пример #1
0
        public bool addRoad(int a, int b, double lens, bool z)
        {
            Road t = new Road(NextID, LArrow[a].Coord, LArrow[a], LArrow[b], lens);

            Arrow[] temp = t.GetAllArrows();
            bool    fl   = true;

            if (findID(t.ID))
            {
                LError.Add(new ErrorRoad(2));
            }
            for (int i = 0; i < temp.Length && fl; i++)
            {
                int q = LArrow.IndexOf(temp[i]);
                if (q < 0)
                {
                    fl = false;
                    LError.Add(new ErrorRoad(1));
                }
                else
                {
                    fl = LArrow[q].TryPick(t);
                }
            }
            LRoad.Add(t);
            G.addEdge(LArrow[a], LArrow[b], t.Lenght);
            for (int i = 0; i < temp.Length && fl; i++)
            {
                int q = LArrow.IndexOf(temp[i]);
                if (q >= 0)
                {
                    LArrow[q].Add(t);
                }
            }
            return(fl);
        }
Пример #2
0
        public bool Add(Road a)
        {
            if (UsedFitst == 0 && UsedSecond == 0)
            {
                First[0] = a;
                UsedFitst++;
                return(true);
            }
            Point s = new Point();

            Arrow[] z = a.GetAllArrows();
            if (z.Length == 2 && z[0] == this)
            {
                s.X = coords.X - z[1].coords.X;
                s.Y = coords.Y - z[1].coords.Y;
            }
            if (z.Length == 2 && z[1] == this)
            {
                s.X = coords.X - z[0].coords.X;
                s.Y = coords.Y - z[0].coords.Y;
            }
            for (int i = 0; i < First.Length; i++)
            {
                if (First[i] != null)
                {
                    Point q = coords;
                    z = First[i].GetAllArrows();
                    if (z.Length == 2 && z[0] == this)
                    {
                        q.X = coords.X - z[1].coords.X;
                        q.X = coords.Y - z[1].coords.Y;
                    }
                    if (z.Length == 2 && z[1] == this)
                    {
                        q.X = coords.X - z[0].coords.X;
                        q.X = coords.Y - z[0].coords.Y;
                    }
                    double arc = Math.Acos((s.X * q.X + s.Y * q.Y) / Math.Sqrt((s.X * s.X + s.Y * s.Y) * (q.X * q.X + q.Y * q.Y)));
                    if (UsedFitst < 1 && arc > 0 && arc < 1)
                    {
                        First[UsedFitst] = a;
                        UsedFitst++;
                        return(true);
                    }
                    if (UsedSecond < 1 && arc > -1 && arc < 0)
                    {
                        Second[UsedSecond] = a;
                        UsedSecond++;
                        return(true);
                    }
                }
            }
            for (int i = 0; i < Second.Length; i++)
            {
                if (Second[i] != null)
                {
                    Point q = coords;
                    z = Second[i].GetAllArrows();
                    if (z.Length == 2 && z[0] == this)
                    {
                        q.X = coords.X - z[1].coords.X;
                        q.X = coords.Y - z[1].coords.Y;
                    }
                    if (z.Length == 2 && z[1] == this)
                    {
                        q.X = coords.X - z[0].coords.X;
                        q.X = coords.Y - z[0].coords.Y;
                    }
                    double arc = Math.Acos((s.X * q.X + s.Y * q.Y) / Math.Sqrt((s.X * s.X + s.Y * s.Y) * (q.X * q.X + q.Y * q.Y)));
                    if (arc > 0 && arc < 1)
                    {
                        if (UsedSecond < 1)
                        {
                            Second[UsedSecond] = a;
                            UsedSecond++;
                            return(true);
                        }
                        if (UsedFitst < 1)
                        {
                            First[UsedFitst] = a;
                            UsedFitst++;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }