예제 #1
0
파일: MyType.cs 프로젝트: yisea123/TestOne
        public ST_XYZA ToXYZA(double z = 0, double a = 0)
        {
            ST_XYZA xyza = new ST_XYZA();

            xyza.x = x;
            xyza.y = y;
            xyza.z = z;
            xyza.a = a;
            return(xyza);
        }
예제 #2
0
파일: Utility.cs 프로젝트: yisea123/TestOne
        /// <summary>
        /// 根据矩形的三个顶点生成阵列,返回List,XY为坐标,Z为row编号,A为col编号
        /// </summary>
        /// <param name="st_pos_tl">左上点</param>
        /// <param name="st_pos_tl_x">右上点</param>
        /// <param name="st_pos_tl_y">左下点</param>
        /// <param name="col_x">列数</param>
        /// <param name="row_y">行数</param>
        /// <param name="brolback">排序方式,设为True时,编号从左上到右上,再从右到左。False时,编号从左上到右上,返回再从左到右。</param>
        /// <returns>返回List</returns>
        public static List <ST_XYZA> ArrayToList(ST_XYZA st_pos_tl, ST_XYZA st_pos_tl_x, ST_XYZA st_pos_tl_y, int col_x, int row_y, bool brolback = false)
        {
            List <ST_XYZA> ls = new List <ST_XYZA>();

            //check
            if (col_x <= 0 && row_y <= 0)
            {
                VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, "阵列数据异常!\r\n行数或列数小于1!");
                return(ls);
            }

            double col_w = 0;
            double col_h = 0;
            double row_w = 0;
            double row_h = 0;

            if (col_x > 1)
            {
                col_w = (st_pos_tl_x.x - st_pos_tl.x);
                col_h = (st_pos_tl_x.y - st_pos_tl.y);
            }
            if (row_y > 1)
            {
                row_w = (st_pos_tl_y.x - st_pos_tl.x);
                row_h = (st_pos_tl_y.y - st_pos_tl.y);
            }
            int  c   = 0;
            int  r   = 0;
            bool dir = true;

            for (c = 0; c < col_x; c++)
            {
                if (dir)
                {
                    for (r = 0; r < row_y; r++)
                    {
                        ST_XYZA pos = new ST_XYZA();
                        pos.x = st_pos_tl.x + c * col_w + r * row_w;
                        pos.y = st_pos_tl.y + r * row_h + c * col_h;
                        pos.z = r;
                        pos.a = c;
                        ls.Add(pos);
                    }
                }
                else
                {
                    for (r = row_y - 1; r >= 0; r--)
                    {
                        ST_XYZA pos = new ST_XYZA();
                        pos.x = st_pos_tl.x + c * col_w + r * row_w;
                        pos.y = st_pos_tl.y + r * row_h + c * col_h;
                        pos.z = r;
                        pos.a = c;
                        ls.Add(pos);
                    }
                }
                if (brolback)
                {
                    dir = !dir;
                }
            }

            return(ls);
        }
예제 #3
0
파일: Utility.cs 프로젝트: yisea123/TestOne
        /// <summary>
        /// 根据矩形的三个顶点生成阵列,返回二维数组
        /// </summary>
        /// <param name="st_pos_tl">左上点</param>
        /// <param name="st_pos_tl_x">右上点</param>
        /// <param name="st_pos_tl_y">左下点</param>
        /// <param name="col_x">列数</param>
        /// <param name="row_y">行数</param>
        /// <param name="brow_inc">true按row增长,false按col增长</param>
        /// <param name="brolback">true为折返增长方式,false为行/列到头则返回行/列头增长</param>
        /// <param name="bshort_step_mode">true:表示tl_x/tl_y为第2/2个目标位置,false:表示tl_x/tl_y为第col_x/row_y个目标位置</param>
        /// <returns>返回二维数组</returns>
        public static ST_XYZA[][] Array(ST_XYZA st_pos_tl, ST_XYZA st_pos_tl_x, ST_XYZA st_pos_tl_y, int col_x,
                                        int row_y, bool brow_inc = false, bool brolback = false, bool bshort_step_mode = false)
        {
            //check
            if (col_x <= 0 && row_y <= 0)
            {
                VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, "阵列数据异常!\r\n行数或列数小于1!");
                return(null);
            }

            ST_XYZA[][] st_pos;
            if (brow_inc)
            {
                st_pos = new ST_XYZA[col_x][];
                for (int n = 0; n < col_x; n++)
                {
                    st_pos[n] = new ST_XYZA[row_y];
                }
            }
            else
            {
                st_pos = new ST_XYZA[row_y][];
                for (int n = 0; n < row_y; n++)
                {
                    st_pos[n] = new ST_XYZA[col_x];
                }
            }

            double col_w = 0;
            double col_h = 0;
            double row_w = 0;
            double row_h = 0;

            if (col_x > 1)
            {
                col_w = bshort_step_mode ? (st_pos_tl_x.x - st_pos_tl.x) : (st_pos_tl_x.x - st_pos_tl.x) / (col_x - 1);
                col_h = bshort_step_mode ? (st_pos_tl_x.y - st_pos_tl.y) : (st_pos_tl_x.y - st_pos_tl.y) / (col_x - 1);
            }

            if (row_y > 1)
            {
                row_w = bshort_step_mode ? (st_pos_tl_y.x - st_pos_tl.x) : (st_pos_tl_y.x - st_pos_tl.x) / (row_y - 1);
                row_h = bshort_step_mode ? (st_pos_tl_y.y - st_pos_tl.y) : (st_pos_tl_y.y - st_pos_tl.y) / (row_y - 1);
            }

            int  c   = 0;
            int  r   = 0;
            bool dir = true;

            for (c = 0; c < col_x; c++)
            {
                if (dir)
                {
                    for (r = 0; r < row_y; r++)
                    {
                        if (brow_inc)
                        {
                            st_pos[c][r].x = st_pos_tl.x + c * col_w + r * row_w;
                            st_pos[c][r].y = st_pos_tl.y + r * row_h + c * col_h;
                        }
                        else
                        {
                            st_pos[r][c].x = st_pos_tl.x + c * col_w + r * row_w;
                            st_pos[r][c].y = st_pos_tl.y + r * row_h + c * col_h;
                        }
                    }
                }
                else
                {
                    for (r = row_y - 1; r >= 0; r--)
                    {
                        if (brow_inc)
                        {
                            st_pos[c][r].x = st_pos_tl.x + c * col_w + r * row_w;
                            st_pos[c][r].y = st_pos_tl.y + r * row_h + c * col_h;
                        }
                        else
                        {
                            st_pos[r][c].x = st_pos_tl.x + c * col_w + r * row_w;
                            st_pos[r][c].y = st_pos_tl.y + r * row_h + c * col_h;
                        }
                    }
                }

                if (brolback)
                {
                    dir = !dir;
                }
            }

            return(st_pos);
        }