//求最优边长
        /// <summary>
        /// 求最优边长
        /// </summary>
        /// <param name="m_rect_h">高度</param>
        /// <param name="m_rect_w">宽度</param>
        /// <param name="m_spacing">行距</param>
        /// <param name="m_sidemax">最大允许长度</param>
        /// <param name="m_side_min">最小边长</param>
        /// <returns>m_sidelength 边长</returns>
        private List<lengthRowColNum> CalculateSideLength(float m_rect_h, float m_rect_w, float m_spacing, float m_Lmax, float m_side_min)
        {
            List<lengthRowColNum> m_lengthRowColNums = new List<lengthRowColNum>();
            lengthRowColNum mtemp_lengthRowColNum = new lengthRowColNum();
            //float[] m_lengthRowColNum = new float[3];  //输出  边长、行数、列数
            float m_sidelength = m_Lmax;       //边长
            int m_Rownum=0, m_Columnum=0;         //行数、列数
            float m_Dmax;         //允许的最大边长
            int m_Rownum_Max = 0, m_Columnnum_Max = 0;
            float m_Drerow;          //行余量、即高度余量
            float m_Drecol;          //列余量 、即宽度余量
            bool rowState = false;           //判读行是否可行,若可行则进行列判断
            bool colState = false;           //判读列是否可行,若可行则循环截止

            m_Dmax = (((Int32)((m_Lmax - m_spacing) / 2 / m_spacing)) * 2 + 1) * m_spacing;   //最大边长 初始迭代值
            m_sidelength = m_Dmax;

            //用来判断初始情况
            m_Rownum_Max = (int)(m_rect_h / m_sidelength);         //最大行数
            m_Drerow = m_rect_h - m_sidelength * m_Rownum_Max;     //求取行余量
            m_Columnnum_Max = (int)(m_rect_w / m_sidelength);      //最大列数
            m_Drecol = m_rect_w - m_sidelength * m_Columnnum_Max;         //求取列余量

            if ((m_Drerow <= FLT_MIN) && (m_Drecol <= FLT_MIN))    //如果行和列都刚刚好
            {
                //mtemp_lengthRowColNum.Sidelength = m_Dmax;
                //mtemp_lengthRowColNum.Rownum = m_Rownum_Max;
                //mtemp_lengthRowColNum.Colnumnum = m_Columnnum_Max;
                //m_lengthRowColNums.Add(mtemp_lengthRowColNum);

                //mtemp_lengthRowColNum = new lengthRowColNum();
               // m_sidelength = m_sidelength - 2 * m_spacing; colState = false;
                //return m_lengthRowColNum;
            }
            if (m_Drerow > FLT_MIN) { m_Rownum_Max++; }         //保存最大情况,以防无法优化
            if (m_Drecol > FLT_MIN) { m_Columnnum_Max++; }

            m_sidelength = m_sidelength - 2 * m_spacing; colState = false;

            //若初始情况无法跳出,进行判断
            while (m_sidelength >= m_side_min)        //如果小于最小边长  直接退回原始状况并返回
            {

                int temp_numDrow = (int)(m_rect_h / m_sidelength);         //h=n*d+Dre
                m_Drerow = m_rect_h - m_sidelength * temp_numDrow;         //求取行余量

                //判读余量的情况,进行决策

                if ((m_Drerow + m_sidelength) <= m_Dmax+FLT_MIN)      //如果Dre+D<Dmax +FLT_MIN解决了整数倍的情况
                {
                    m_Rownum = temp_numDrow;
                    rowState = true;
                }
                else if (m_Drerow >= m_side_min)           //如果Dre>Dmin
                {
                    m_Rownum = temp_numDrow + 1;
                    rowState = true;
                }
                else { m_sidelength = m_sidelength - 2 * m_spacing; rowState = false; }

                if (rowState == true)      //如果行好使则进行列判断
                {
                    int temp_numDcol = (int)(m_rect_w / m_sidelength);         //h=n*d+Dre
                    m_Drecol = m_rect_w - m_sidelength * temp_numDcol;         //求取列余量
                   // if (m_Drecol < FLT_MIN) { m_Columnum = m_Drecol; }         //刚好整数倍
                    if ((m_Drecol + m_sidelength) <= m_Dmax+FLT_MIN)      //如果Dre+D<Dmax  包含了整数倍的情况
                    {
                        m_Columnum = temp_numDcol;
                        colState = true;
                    }
                    else if (m_Drerow >= m_side_min)           //如果Dre>Dmin
                    {
                        m_Columnum = temp_numDcol + 1;
                        colState = true;
                    }
                    else { m_sidelength = m_sidelength - 2 * m_spacing; colState = false; }
                  }
                if (rowState && colState)
                {
                    mtemp_lengthRowColNum.Sidelength = m_sidelength;    //边长
                    mtemp_lengthRowColNum.Rownum = m_Rownum;        //行数
                    mtemp_lengthRowColNum.Colnumnum = m_Columnum;      //列数
                    m_lengthRowColNums.Add(mtemp_lengthRowColNum);
                    mtemp_lengthRowColNum = new lengthRowColNum();
                    m_sidelength = m_sidelength - 2 * m_spacing;
                    rowState = false;
                    colState = false;
                }
            }
            mtemp_lengthRowColNum.Sidelength = m_Dmax;
            mtemp_lengthRowColNum.Rownum = m_Rownum_Max;
            mtemp_lengthRowColNum.Colnumnum = m_Columnnum_Max;
            m_lengthRowColNums.Add(mtemp_lengthRowColNum);
            return m_lengthRowColNums;
        }
Example #2
0
        //求最优边长
        /// <summary>
        /// 求最优边长
        /// </summary>
        /// <param name="m_rect_h">高度</param>
        /// <param name="m_rect_w">宽度</param>
        /// <param name="m_spacing">行距</param>
        /// <param name="m_sidemax">最大允许长度</param>
        /// <param name="m_side_min">最小边长</param>
        /// <returns>m_sidelength 边长</returns>
        private List <lengthRowColNum> CalculateSideLength(float m_rect_h, float m_rect_w, float m_spacing, float m_Lmax, float m_side_min)
        {
            List <lengthRowColNum> m_lengthRowColNums    = new List <lengthRowColNum>();
            lengthRowColNum        mtemp_lengthRowColNum = new lengthRowColNum();
            //float[] m_lengthRowColNum = new float[3];  //输出  边长、行数、列数
            float m_sidelength = m_Lmax;                                                          //边长
            int   m_Rownum = 0, m_Columnum = 0;                                                   //行数、列数
            float m_Dmax;                                                                         //允许的最大边长
            int   m_Rownum_Max = 0, m_Columnnum_Max = 0;
            float m_Drerow;                                                                       //行余量、即高度余量
            float m_Drecol;                                                                       //列余量 、即宽度余量
            bool  rowState = false;                                                               //判读行是否可行,若可行则进行列判断
            bool  colState = false;                                                               //判读列是否可行,若可行则循环截止

            m_Dmax       = (((Int32)((m_Lmax - m_spacing) / 2 / m_spacing)) * 2 + 1) * m_spacing; //最大边长 初始迭代值
            m_sidelength = m_Dmax;

            //用来判断初始情况
            m_Rownum_Max    = (int)(m_rect_h / m_sidelength);            //最大行数
            m_Drerow        = m_rect_h - m_sidelength * m_Rownum_Max;    //求取行余量
            m_Columnnum_Max = (int)(m_rect_w / m_sidelength);            //最大列数
            m_Drecol        = m_rect_w - m_sidelength * m_Columnnum_Max; //求取列余量


            if ((m_Drerow <= FLT_MIN) && (m_Drecol <= FLT_MIN))    //如果行和列都刚刚好
            {
                //mtemp_lengthRowColNum.Sidelength = m_Dmax;
                //mtemp_lengthRowColNum.Rownum = m_Rownum_Max;
                //mtemp_lengthRowColNum.Colnumnum = m_Columnnum_Max;
                //m_lengthRowColNums.Add(mtemp_lengthRowColNum);

                //mtemp_lengthRowColNum = new lengthRowColNum();
                // m_sidelength = m_sidelength - 2 * m_spacing; colState = false;
                //return m_lengthRowColNum;
            }
            if (m_Drerow > FLT_MIN)
            {
                m_Rownum_Max++;
            }                                                   //保存最大情况,以防无法优化
            if (m_Drecol > FLT_MIN)
            {
                m_Columnnum_Max++;
            }

            m_sidelength = m_sidelength - 2 * m_spacing; colState = false;

            //若初始情况无法跳出,进行判断
            while (m_sidelength >= m_side_min)                     //如果小于最小边长  直接退回原始状况并返回
            {
                int temp_numDrow = (int)(m_rect_h / m_sidelength); //h=n*d+Dre
                m_Drerow = m_rect_h - m_sidelength * temp_numDrow; //求取行余量

                //判读余量的情况,进行决策

                if ((m_Drerow + m_sidelength) <= m_Dmax + FLT_MIN)      //如果Dre+D<Dmax +FLT_MIN解决了整数倍的情况
                {
                    m_Rownum = temp_numDrow;
                    rowState = true;
                }
                else if (m_Drerow >= m_side_min)           //如果Dre>Dmin
                {
                    m_Rownum = temp_numDrow + 1;
                    rowState = true;
                }
                else
                {
                    m_sidelength = m_sidelength - 2 * m_spacing; rowState = false;
                }

                if (rowState == true)                                  //如果行好使则进行列判断
                {
                    int temp_numDcol = (int)(m_rect_w / m_sidelength); //h=n*d+Dre
                    m_Drecol = m_rect_w - m_sidelength * temp_numDcol; //求取列余量
                    // if (m_Drecol < FLT_MIN) { m_Columnum = m_Drecol; }         //刚好整数倍
                    if ((m_Drecol + m_sidelength) <= m_Dmax + FLT_MIN) //如果Dre+D<Dmax  包含了整数倍的情况
                    {
                        m_Columnum = temp_numDcol;
                        colState   = true;
                    }
                    else if (m_Drerow >= m_side_min)           //如果Dre>Dmin
                    {
                        m_Columnum = temp_numDcol + 1;
                        colState   = true;
                    }
                    else
                    {
                        m_sidelength = m_sidelength - 2 * m_spacing; colState = false;
                    }
                }
                if (rowState && colState)
                {
                    mtemp_lengthRowColNum.Sidelength = m_sidelength; //边长
                    mtemp_lengthRowColNum.Rownum     = m_Rownum;     //行数
                    mtemp_lengthRowColNum.Colnumnum  = m_Columnum;   //列数
                    m_lengthRowColNums.Add(mtemp_lengthRowColNum);
                    mtemp_lengthRowColNum = new lengthRowColNum();
                    m_sidelength          = m_sidelength - 2 * m_spacing;
                    rowState = false;
                    colState = false;
                }
            }
            mtemp_lengthRowColNum.Sidelength = m_Dmax;
            mtemp_lengthRowColNum.Rownum     = m_Rownum_Max;
            mtemp_lengthRowColNum.Colnumnum  = m_Columnnum_Max;
            m_lengthRowColNums.Add(mtemp_lengthRowColNum);
            return(m_lengthRowColNums);
        }