public static dynamic GetTSObject(Matrix[] dynArray)
        {
            if (dynArray is null)
            {
                return(null);
            }
            var list = new System.Collections.Generic.List <dynamic>();

            foreach (var dynItem in dynArray)
            {
                list.Add(Matrix_.GetTSObject(dynItem));
            }
            return(list.ToArray());
        }
        public static Matrix[] FromTSObject(dynamic[] tsArray)
        {
            if (tsArray is null)
            {
                return(null);
            }
            var list = new System.Collections.Generic.List <Matrix>();

            foreach (var tsItem in tsArray)
            {
                list.Add(Matrix_.FromTSObject(tsItem));
            }
            return(list.ToArray());
        }
Ejemplo n.º 3
0
        public List <Vector2> GetAdjacent(Grid grid)
        {
            Extensions.Matrix_ points = new Extensions.Matrix_(new Vector2[, ]
            {
                { corners[Corner.TopLeft], corners[Corner.BottomLeft], },
                { corners[Corner.TopRight], corners[Corner.BottomRight] }
            });

            Vector2[] vecP = new Vector2[4];
            vecP[0] = corners[Corner.TopLeft];
            vecP[1] = corners[Corner.TopRight];
            vecP[2] = corners[Corner.BottomLeft];
            vecP[3] = corners[Corner.BottomRight];
            Vector2 cp = new Vector2(Extensions.Extensions.Midpoint(corners[Corner.TopLeft].X, corners[Corner.TopRight].X),
                                     Extensions.Extensions.Midpoint(corners[Corner.TopRight].Y, corners[Corner.BottomRight].Y));

            Matrix_[] translations = new Matrix_[4];
            Vector2   trans        = new Vector2(size.X / 2, size.Y / 2);

            translations[0] = new Matrix_(new Vector2[, ]
            {
                { new Vector2(trans.X, 0) },
                { new Vector2(0, trans.Y) }
            });

            translations[1] = new Matrix_(new Vector2[, ]
            {
                { new Vector2(-trans.X, 0) },
                { new Vector2(0, trans.Y) }
            });

            translations[2] = new Matrix_(new Vector2[, ]
            {
                { new Vector2(trans.X, 0) },
                { new Vector2(0, -trans.Y) }
            });

            translations[3] = new Matrix_(new Vector2[, ]
            {
                { new Vector2(-trans.X, 0) },
                { new Vector2(0, -trans.Y) }
            });

            Extensions.Matrix_ origin = new Matrix_(new Vector2[, ] {
                { new Vector2(trans.X + corners[Corner.TopRight].X, 0) },
                { new Vector2(0, trans.Y + corners[Corner.TopRight].Y) }
            });

            Matrix_ IOrigin = origin.Inverse();

            Extensions.Matrix_ translate = new Extensions.Matrix_(new Vector2[, ]
            {
                { new Vector2(trans.X, 0) },
                { new Vector2(0, trans.Y) }
            });

            Matrix_ IT = translate.Inverse();


            Extensions.Matrix_ scaler = new Extensions.Matrix_(new Vector2[, ] {
                { new Vector2(2, 0) },
                { new Vector2(0, 2) }
            });
            Extensions.Matrix_ combination = Extensions.Matrix_.Multiply(translate, scaler);


            Vector2[] finalPoints = new Vector2[4];
            int       I           = 0;

            foreach (Matrix_ m in translations)
            {
                Extensions.Matrix_ t = Extensions.Matrix_.Minus(vecP[I].ToMatrix(), cp.ToMatrix());
                Extensions.Matrix_ c = Extensions.Matrix_.Multiply(t, scaler);
                finalPoints[I] = Matrix_.Add(c, cp.ToMatrix()).ReturnVector();
                I++;
            }

            int xpos  = (int)finalPoints[1].X;
            int sizex = xpos - (int)finalPoints[0].X;

            Vector2[,] allPoints = new Vector2[sizex / (size.X / 2), sizex / (size.Y / 2)];
            //get vectors
            int a = 0;
            int b = 0;

            for (int x = (int)finalPoints[0].X; x < finalPoints[1].X; x += size.X / 2)
            {
                for (int y = (int)finalPoints[0].Y; y < finalPoints[2].Y; y += size.Y / 2)
                {
                    allPoints[a, b] = new Vector2(x, y);

                    b++;
                }
                a++;
                b = 0;
            }

            List <Vector2> adj = allPoints.GetEdges();

            adj = grid.CheckPositions(adj);

            return(adj);
        }