Esempio n. 1
0
        public Graph setWith(Graph graf)
        {
            Graph graf1 = new Graph(graf.getGrafDecart().count());

            //заполняю координаты в пространстве
            Nodes grafDecart = new Nodes(graf.getGrafDecart().getSizeDecartGrafMatrixX(),
                                                   graf.getGrafDecart().getSizeDecartGrafMatrixY(), false);
            for (int y = 0; y < graf.getGrafDecart().getSizeDecartGrafMatrixY(); y++)
            {
                for (int x = 0; x < graf.getGrafDecart().getSizeDecartGrafMatrixX(); x++)
                {
                    grafDecart.setGrafMatrixDecart(x, y, graf.getGrafDecart().getElementDecartGraf(x, y));
                }
            }
            graf1.setGrafDecart(grafDecart);

            //заполняю грани в пространстве
            for (int y = 0; y < graf.getSize(); y++)
            {
                for (int x = 0; x < graf.getSize(); x++)
                {
                    graf1.setCoordinates(x, y, graf.getCoordinates(x, y));
                }
            }
            //заполняю размеры путей
            for (int y = 0; y < graf.getSize(); y++)
            {
                List<OptionsGraf> listbuf = new List<OptionsGraf>();
                for (int x = 0; x < graf.getSize(); x++)
                {
                    listbuf.Add(graf.grafSizeWay[x][y]);
                }
                graf1.grafSizeWay.Add(listbuf);
            }

            for (int y = 0; y < graf.getSize(); y++)
            {
                List<OptionsGraf> listbuf = new List<OptionsGraf>();
                for (int x = 0; x < graf.getSize(); x++)
                {
                    listbuf.Add(graf.resultSizeWay[x][y]);
                }
                graf1.resultSizeWay.Add(listbuf);
            }

            return graf1;
        }
Esempio n. 2
0
        //операция объединения
        public static Graph operator +(Graph graf1, Graph graf2)
        {
            Graph graf = graf1.getSize() > graf2.getSize()
                            ? new Graph(graf1.getCountPoint(graf2.getGrafDecart()))
                            : new Graph(graf2.getCountPoint(graf1.getGrafDecart()));

            //заполняю координаты в пространстве
            int grafDecartX = graf1.getGrafDecart().getSizeDecartGrafMatrixX() >
                              graf2.getGrafDecart().getSizeDecartGrafMatrixX()
                                  ? graf1.getGrafDecart().getSizeDecartGrafMatrixX()
                                  : graf2.getGrafDecart().getSizeDecartGrafMatrixX();
            int grafDecartY = graf1.getGrafDecart().getSizeDecartGrafMatrixY() >
                              graf2.getGrafDecart().getSizeDecartGrafMatrixY()
                                  ? graf1.getGrafDecart().getSizeDecartGrafMatrixY()
                                  : graf2.getGrafDecart().getSizeDecartGrafMatrixY();

            Nodes grafDecart = new Nodes(grafDecartX, grafDecartY, false);
            for (int y = 0; y < graf2.getGrafDecart().getSizeDecartGrafMatrixY(); y++)
            {
                for (int x = 0; x < graf2.getGrafDecart().getSizeDecartGrafMatrixX(); x++)
                {
                    grafDecart.setGrafMatrixDecart(x, y, graf2.getGrafDecart().getElementDecartGraf(x, y));
                }
            }

            for (int y = 0; y < graf1.getGrafDecart().getSizeDecartGrafMatrixY(); y++)
            {
                for (int x = 0; x < graf1.getGrafDecart().getSizeDecartGrafMatrixX(); x++)
                {
                    if (grafDecart.getElementDecartGraf(x, y) == 0)
                    {
                        grafDecart.setGrafMatrixDecart(x, y,
                                                       graf1.getGrafDecart().getElementDecartGraf(x, y) > 0
                                                           ? grafDecart.findLastDot() + 1
                                                           : 0);
                    }

                }
            }
            graf.setGrafDecart(grafDecart);

            //заполняю грани в пространстве
            for (int y = 0; y < graf2.getSize(); y++)
            {
                for (int x = 0; x < graf2.getSize(); x++)
                {
                    if (graf2.getCoordinates(x, y))
                    {
                        graf.setCoordinates(x, y, true);
                    }
                }
            }

            for (int y = 0; y < graf1.getGraf().Count; y++)
            {
                for (int x = 0; x < graf1.getGraf().Count; x++)
                {
                    if (graf1.getCoordinates(x, y))
                    {
                        graf.setCoordinates(
                            graf.getGrafDecart().getElementDecartGraf(
                                graf1.getCoordinatePoint(x).getStartCoordinate().getX(),
                                graf1.getCoordinatePoint(x).getStartCoordinate().getY()) - 1,
                            graf.getGrafDecart().getElementDecartGraf(
                                graf1.getCoordinatePoint(y).getStartCoordinate().getX(),
                                graf1.getCoordinatePoint(y).getStartCoordinate().getY()) - 1, true);

                    }
                }
            }

            return graf;
        }