Ejemplo n.º 1
0
 public CrossEle CreateEle(Point pt, Size size, Int16 multiFactor, string text)
 {
     Point[] pts = new Point[8];
     DrawMultiFactor = multiFactor;
     objectCrossOp.DrawMultiFactor = DrawMultiFactor;
     pt.Offset(pt.X / DrawMultiFactor - pt.X, pt.Y / DrawMultiFactor - pt.Y);
     pts[0]   = pt;
     pts[1].X = pts[0].X + firstPart;
     pts[1].Y = pts[0].Y;
     pts[2].X = pts[1].X;
     pts[2].Y = pts[0].Y + 5;
     pts[3].X = pts[0].X + firstPart + secPart;
     pts[3].Y = pts[2].Y;
     pts[4].X = pts[3].X;
     pts[4].Y = pts[0].Y;
     pts[5].X = pts[0].X + lenghtOfStrai;
     pts[5].Y = pts[0].Y;
     pts[6].X = pts[1].X;
     pts[6].Y = pts[0].Y - 5;
     pts[7].X = pts[3].X;
     pts[7].Y = pts[0].Y - 45;
     PointList.AddRange(pts);
     directionOfCross = DirectionCross.first;
     this.railText    = text;
     return(this);
 }
Ejemplo n.º 2
0
 public override void ChangePropertyValue()
 {
     Point[] pts = new Point[2];
     PointList.CopyTo(pts);
     if (PointList[0].X == PointList[1].X)
     {
         if (PointList[0].Y < PointList[1].Y)
         {
             pts[1].Y = pts[0].Y + lenght;
         }
         else
         {
             pts[0].Y = pts[1].Y + lenght;
         }
     }
     else if (PointList[0].Y == PointList[1].Y)
     {
         if (PointList[0].X < PointList[1].X)
         {
             pts[1].X = pts[0].X + lenght;
         }
         else
         {
             pts[0].X = pts[1].X + lenght;
         }
     }
     PointList.Clear();
     PointList.AddRange(pts);
     base.ChangePropertyValue();
 }
Ejemplo n.º 3
0
    public static IEnumerable <RectPoint> GenerateMazeWalls <TCell>(RectGrid <TCell> grid)
    {
        var walls = grid.CloneStructure <bool>();        //true indicates passable

        foreach (var point in walls)
        {
            walls[point] = point.GetColor3() == 0;

            //Debug.Log(point);
        }

        var wallList = new PointList <RectPoint>();

        var newMaizePoint = grid.Where(p => p.GetColor3() == 0).RandomItem();
        var inMaze        = new PointList <RectPoint> {
            newMaizePoint
        };

        var edges = grid.GetNeighbors(newMaizePoint);

        wallList.AddRange(edges);

        while (wallList.Any())
        {
            var randomWall = wallList.RandomItem();
            var faces      = GetEdgeFaces(randomWall).Where(grid.Contains);

            //At least one of the two faces must be in the maze
            if (faces.Any(point => !inMaze.Contains(point)))
            {
                newMaizePoint = faces.First(point => !inMaze.Contains(point));
                inMaze.Add(newMaizePoint);
                walls[randomWall] = true;

                yield return(randomWall);

                // Add all edges that are not passages
                edges = grid.GetNeighbors(newMaizePoint).Where(edge => !(walls[edge]));
                wallList.AddRange(edges);
            }
            else
            {
                wallList.Remove(randomWall);
            }
        }
    }
Ejemplo n.º 4
0
 protected override void Translate(int offsetX, int offsetY)
 {
     Point[] pts = new Point[8];
     PointList.CopyTo(pts);
     for (int i = 0; i < 8; i++)
     {
         pts[i].Offset(offsetX, offsetY);
     }
     PointList.Clear();
     PointList.AddRange(pts);
 }
Ejemplo n.º 5
0
    /**
     *      Generates a maze using a randomized version of Prim's algorithm.
     *
     *      @returns a IEnumerable of passages
     */
    //For some reason, the generic version gives a TypeLoadException in Unity (but not when run from visual studio).

    /*
     * public static IEnumerable<TEdge> GenerateMazeWalls<TGrid, TPoint, TEdge>(TGrid grid)
     *      where TEdge : IGridPoint<TEdge>, IEdge<TPoint>
     *      where TPoint : IGridPoint<TPoint>, ISupportsEdges<TEdge>
     *      where TGrid : ISupportsEdgeGrid<TEdge>, IGridSpace<TPoint>
     * {
     *      IGrid<bool, TEdge> walls = grid.MakeEdgeGrid<bool>(); //true indicates passable
     *      var wallList = new List<TEdge>();
     *
     *      TPoint newMaizePoint = grid.RandomItem<TPoint>();
     *      var inMaze = new List<TPoint>();
     *      inMaze.Add(newMaizePoint);
     *
     *      var edges = newMaizePoint.GetEdges();
     *      wallList.AddRange(edges);
     *
     *      while (wallList.Any())
     *      {
     *              var randomWall = wallList.RandomItem();
     *              IEnumerable<TPoint> faces = (randomWall as IEdge<TPoint>).GetEdgeFaces().Where(x => grid.Contains(x));
     *
     *              //At least one of the two faces must be in the maze
     *              if (faces.Any(point => !inMaze.Contains(point)))
     *              {
     *                      newMaizePoint = faces.First(point => !inMaze.Contains(point));
     *                      inMaze.Add(newMaizePoint);
     *                      walls[randomWall] = true;
     *
     *                      yield return randomWall;
     *
     *                      // Add all edges that are not passages
     *                      edges = newMaizePoint.GetEdges().Where(edge => !(walls[edge]));
     *                      wallList.AddRange(edges);
     *              }
     *              else
     *              {
     *                      wallList.Remove(randomWall);
     *              }
     *      }
     *      yield return (TEdge)(object) g.First();
     *      yield break;
     * }
     */

    /**
     *      Generates a maze using a randomized version of Prim's algorithm.
     *
     *      @returns a IEnumerable of passages
     */
    public static IEnumerable <PointyRhombPoint> GenerateMazeWalls <TCell>(FlatTriGrid <TCell> grid)
    {
        var walls    = grid.MakeEdgeGrid <bool>();     //true indicates passable
        var wallList = new PointList <PointyRhombPoint>();

        var newMaizePoint = grid.RandomItem();
        var inMaze        = new PointList <FlatTriPoint> {
            newMaizePoint
        };

        var edges = newMaizePoint.GetEdges();

        wallList.AddRange(edges);

        while (wallList.Any())
        {
            var randomWall = wallList.RandomItem();
            var faces      = (randomWall as IEdge <FlatTriPoint>).GetEdgeFaces().Where(x => grid.Contains(x));

            //At least one of the two faces must be in the maze
            if (faces.Any(point => !inMaze.Contains(point)))
            {
                newMaizePoint = faces.First(point => !inMaze.Contains(point));
                inMaze.Add(newMaizePoint);
                walls[randomWall] = true;

                yield return(randomWall);

                // Add all edges that are not passages
                edges = newMaizePoint.GetEdges().Where(edge => !(walls[edge]));
                wallList.AddRange(edges);
            }
            else
            {
                wallList.Remove(randomWall);
            }
        }
    }
Ejemplo n.º 6
0
 public StraightRailEle CreateEle(Point pt, Size size, Int16 multiFactor, string text)
 {
     Point[] pts = new Point[2];
     DrawMultiFactor = multiFactor;
     objectStaightOp.DrawMultiFactor = multiFactor;
     pt.Offset(pt.X / DrawMultiFactor - pt.X, pt.Y / DrawMultiFactor - pt.Y);
     pts[0] = pt;
     if ((pt.X + Lenght) > size.Width)
     {
         pts[0] = new Point(pt.X - lenght, pt.Y);
         pts[1] = new Point(pt.X, pt.Y);
     }
     else
     {
         pts[0] = new Point(pt.X, pt.Y);
         pts[1] = new Point(pt.X + lenght, pt.Y);
     }
     PointList.AddRange(pts);
     this.railText = text;
     return(this);
 }
    //========================================================================================
    //                                     public
    //========================================================================================

    /// <summary>
    /// 初期処理
    /// </summary>
    public void GroupInitialize()
    {
        var cp = GetComponentsInChildren <GroupEnemyCheckPoint>();

        PointList.AddRange(cp);
    }
Ejemplo n.º 8
0
        public override void ChangePropertyValue()
        {
            Point ptTemp = new Point(fourPart.X * DrawMultiFactor, fourPart.Y * DrawMultiFactor);

            Point[] ptsList = new Point[8];
            PointList.CopyTo(ptsList);
            switch (directionOfCross)
            {
            case DirectionCross.first:
                if (PointList[0].X < PointList[1].X)
                {
                    ptsList[0].X = PointList[1].X - firstPart;
                    ptsList[3].X = ptsList[1].X + secPart;
                    ptsList[4].X = ptsList[3].X;
                    ptsList[5].X = ptsList[3].X + thPart;
                    ptsList[7].X = ptsList[6].X + fourPart.X;
                    ptsList[7].Y = ptsList[6].Y - fourPart.Y;
                }
                else
                {
                    ptsList[0].X = PointList[1].X + firstPart;
                    ptsList[3].X = ptsList[1].X - secPart;
                    ptsList[4].X = ptsList[3].X;
                    ptsList[5].X = ptsList[3].X - thPart;
                    ptsList[7].X = ptsList[6].X - fourPart.X;
                    ptsList[7].Y = ptsList[6].Y - fourPart.Y;
                }
                PointList.Clear();
                PointList.AddRange(ptsList);
                break;

            case DirectionCross.second:
                if (PointList[0].Y < PointList[1].Y)
                {
                    ptsList[0].Y = ptsList[1].Y - firstPart;
                    ptsList[3].Y = ptsList[1].Y + secPart;
                    ptsList[4].Y = ptsList[3].Y;
                    ptsList[5].Y = ptsList[3].Y + thPart;
                    ptsList[7].X = ptsList[6].X + fourPart.X;
                    ptsList[7].Y = ptsList[6].Y + fourPart.Y;
                }
                else
                {
                    ptsList[0].Y = ptsList[1].Y + firstPart;
                    ptsList[3].Y = ptsList[1].Y - secPart;
                    ptsList[4].Y = ptsList[3].Y;
                    ptsList[5].Y = ptsList[3].Y - thPart;
                    ptsList[7].X = ptsList[6].X + fourPart.X;
                    ptsList[7].Y = ptsList[6].Y - fourPart.Y;
                }
                PointList.Clear();
                PointList.AddRange(ptsList);
                break;

            case DirectionCross.third:
                if (PointList[0].X < PointList[1].X)
                {
                    ptsList[0].X = PointList[1].X - firstPart;
                    ptsList[3].X = ptsList[1].X + secPart;
                    ptsList[4].X = ptsList[3].X;
                    ptsList[5].X = ptsList[3].X + thPart;
                    ptsList[7].X = ptsList[6].X + fourPart.X;
                    ptsList[7].Y = ptsList[6].Y + fourPart.Y;
                }
                else
                {
                    ptsList[0].X = PointList[1].X + firstPart;
                    ptsList[3].X = ptsList[1].X - secPart;
                    ptsList[4].X = ptsList[3].X;
                    ptsList[5].X = ptsList[3].X - thPart;
                    ptsList[7].X = ptsList[6].X - fourPart.X;
                    ptsList[7].Y = ptsList[6].Y + fourPart.Y;
                }
                PointList.Clear();
                PointList.AddRange(ptsList);
                break;

            case DirectionCross.four:
                if (PointList[0].Y < PointList[1].Y)
                {
                    ptsList[0].Y = ptsList[1].Y - firstPart;
                    ptsList[3].Y = ptsList[1].Y + secPart;
                    ptsList[4].Y = ptsList[3].Y;
                    ptsList[5].Y = ptsList[3].Y + thPart;
                    ptsList[7].X = ptsList[6].X - fourPart.X;
                    ptsList[7].Y = ptsList[6].Y + fourPart.Y;
                }
                else
                {
                    ptsList[0].Y = ptsList[1].Y + firstPart;
                    ptsList[3].Y = ptsList[1].Y - secPart;
                    ptsList[4].Y = ptsList[3].Y;
                    ptsList[5].Y = ptsList[3].Y - thPart;
                    ptsList[7].X = ptsList[6].X - fourPart.X;
                    ptsList[7].Y = ptsList[6].Y - fourPart.Y;
                }
                PointList.Clear();
                PointList.AddRange(ptsList);
                break;

            case DirectionCross.NULL:
                break;
            }
            Debug.WriteLine(string.Format("first is {0},sec is {1},th is {2}", firstPart, secPart, thPart));
        }
Ejemplo n.º 9
0
        public static PointList RoughScan(PointList inputList)
        {
            int rowCount = (int)Math.Round(Math.Sqrt(inputList.Count) / 2f) * 2;

            decimal lowestY = inputList.Min(p => p.Y);
            decimal highestY = inputList.Max(p => p.Y);
            decimal rowHeight = (highestY - lowestY) / rowCount;

            List<int> rowIndices = new List<int>();
            for (int i = 0; i < rowCount; i++)
                rowIndices.Add(i);

            List<List<Point>> rows = rowIndices.ConvertAll(rowIndex => inputList.FindAll(point => point.Y >= (lowestY + rowHeight * rowIndex) &&
                                                                                                  point.Y < (lowestY + rowHeight * (rowIndex + 1))));
            rows[rows.Count - 1].AddRange(inputList.FindAll(point => point.Y == highestY));
            rows = rows.Where(r => r.Count > 0).ToList();

            PointList path = new PointList();
            for (int i = 0; i < rows.Count; i++)
            {
                PointList rowPath = new PointList(rows[i].OrderBy(point => point.X * (decimal)Math.Pow(-1f, i)));
                rowPath = nearestNeighbor(rowPath, rowPath[0]);
                rowPath.RemoveAt(rowPath.Count - 1);
                path.AddRange(rowPath);
            }

            path.Add(path[0]);
            return path;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Intialize Rectangle
 /// </summary>
 public RectangleComplex()
 {
     PointList.AddRange(new Point2D[VertexCount]);
 }
Ejemplo n.º 11
0
 private void cboGraphType_SelectedIndexChanged(object sender, EventArgs e)
 {
     switch (cboGraphType.SelectedIndex)
     {
         case 0:
             selectedPointList = TspTest.Cycle;
             break;
         case 1:
             selectedPointList = TspTest.StraightLine;
             break;
         case 2:
             selectedPointList = TspTest.RowsAndColumns;
             break;
         case 3:
             selectedPointList = new PointList(TspTest.Cycle);
             selectedPointList.AddRange(TspTest.StraightLine);
             selectedPointList.AddRange(TspTest.RowsAndColumns);
             selectedPointList.AddRange(new PointList(selectedPointList.ConvertAll(p => new Point(p.Y + 260, p.X + 30))));
             break;
         case 4:
             selectedPointList = customPointList;
             break;
     }
 }
Ejemplo n.º 12
0
 public void UpdatePolygen(Point3d[] pointString)
 {
     PointList.Clear();
     PointList.AddRange(pointString);
     CreatePolygon();
 }