예제 #1
0
파일: GraphControl.cs 프로젝트: ellil4/PCAT
        private CSPoint getOutRangePoint(CSPointType type, short radius)
        {
            CSPoint pTemp          = null;
            int     dicMax         = mSpaceDict.mDic.Count;
            int     randomPointPos = -1;

            if (mSpaceDict.mDic.Count != 0)//when no space left, redo in the DrawScene()
            {
                if (type != CSPointType.AllQuad)
                {
                    while (pTemp == null ||
                           !mSpaceDict.mDic.ContainsKey(mSpaceDict.GetIndex(pTemp.x, pTemp.y)))
                    {
                        pTemp = getPoint(type);
                    }
                }
                else
                {
                    randomPointPos = mRDM.Next(0, dicMax);
                    pTemp          = mSpaceDict.mDic.ElementAt(randomPointPos).Value;
                }

                mSpaceDict.TakeRoundSpace(pTemp, radius);
            }

            if (pTemp == null)
            {
                Console.WriteLine("Rearrange");
            }

            return(pTemp);
        }
예제 #2
0
        private bool isInside(CSPoint pin, short radius, short x, short y)
        {
            bool retval = false;

            if (Math.Pow((double)(pin.x - x), 2) + Math.Pow((double)(pin.y - y), 2) <
                Math.Pow(radius, 2))
            {
                retval = true;
            }

            return(retval);
        }
예제 #3
0
파일: GraphControl.cs 프로젝트: ellil4/PCAT
        private CSPoint getPoint(CSPointType type)
        {
            CSPoint retval = new CSPoint();
            int     limitxMin = 0, limitxMax = 0, limityMin = 0, limityMax = 0;

            switch (type)
            {
            case CSPointType.FirstQuad:
                limitxMin = 320;
                limitxMax = 640;
                limityMin = 0;
                limityMax = 240;
                break;

            case CSPointType.SecondQuad:
                limitxMin = 0;
                limitxMax = 320;
                limityMin = 0;
                limityMax = 240;
                break;

            case CSPointType.ThirdQuad:
                limitxMin = 0;
                limitxMax = 320;
                limityMin = 240;
                limityMax = 480;
                break;

            case CSPointType.AllQuad:
                limitxMin = 0;
                limitxMax = 640;
                limityMin = 0;
                limityMax = 480;
                break;
            }

            retval.x = (short)mRDM.Next(limitxMin, limitxMax);
            retval.y = (short)mRDM.Next(limityMin, limityMax);

            return(retval);
        }
예제 #4
0
        public void TakeRoundSpace(CSPoint pinPoint, short radius)
        {
            short horMax = (short)(pinPoint.x + (radius - 1));
            short horMin = (short)(pinPoint.x - (radius - 1));
            short verMax = (short)(pinPoint.y + (radius - 1));
            short verMin = (short)(pinPoint.y - (radius - 1));

            for (short ver = verMin; ver <= verMax; ver++)
            {
                for (short hor = horMin; hor <= horMax; hor++)
                {
                    if (isInside(pinPoint, radius, hor, ver))
                    {
                        int key = GetIndex(hor, ver);

                        if (mDic.ContainsKey(key))
                        {
                            mDic.Remove(key);
                        }
                    }
                }
            }
        }
예제 #5
0
파일: GraphControl.cs 프로젝트: ellil4/PCAT
        public List <CSPoint> DrawScene(int tarCount, int interCirCount, int interTriCount,
                                        short disTar, short disComm)
        {
            List <CSPoint> retval = null;

            while (true)
            {
                //assert
                if (tarCount < 3 || interCirCount < 0 ||
                    interTriCount < 0 || disTar < 0.0 || disComm < 0.0)
                {
                    return(null);
                }

                Clear();

                retval = new List <CSPoint>();

                //first 3 target
                CSPoint pTemp = getOutRangePoint(CSPointType.FirstQuad, disTar);
                if (pTemp == null)
                {
                    continue;
                }

                DrawTarget(pTemp.x, pTemp.y);
                pTemp.type = 0;
                retval.Add(pTemp);

                pTemp = getOutRangePoint(CSPointType.SecondQuad, disTar);
                if (pTemp == null)
                {
                    continue;
                }

                DrawTarget(pTemp.x, pTemp.y);
                pTemp.type = 0;
                retval.Add(pTemp);

                pTemp = getOutRangePoint(CSPointType.ThirdQuad, disTar);
                if (pTemp == null)
                {
                    continue;
                }

                DrawTarget(pTemp.x, pTemp.y);
                pTemp.type = 0;
                retval.Add(pTemp);

                //other targets
                for (int i = 0; i < tarCount - 3; i++)
                {
                    pTemp = getOutRangePoint(CSPointType.AllQuad, disTar);
                    if (pTemp == null)
                    {
                        break;
                    }

                    DrawTarget(pTemp.x, pTemp.y);
                    pTemp.type = 0;
                    retval.Add(pTemp);
                }
                if (pTemp == null)
                {
                    continue;
                }

                //inter triangle
                for (int i = 0; i < interTriCount; i++)
                {
                    pTemp = getOutRangePoint(CSPointType.AllQuad, disComm);
                    if (pTemp == null)
                    {
                        break;
                    }

                    DrawInterTriangle(pTemp.x, pTemp.y);
                    pTemp.type = 1;
                    retval.Add(pTemp);
                }
                if (pTemp == null)
                {
                    continue;
                }

                //inter circle
                for (int i = 0; i < interCirCount; i++)
                {
                    pTemp = getOutRangePoint(CSPointType.AllQuad, disComm);
                    if (pTemp == null)
                    {
                        break;
                    }

                    DrawInterCircle(pTemp.x, pTemp.y);
                    pTemp.type = 2;
                    retval.Add(pTemp);
                }
                if (pTemp == null)
                {
                    continue;
                }

                break;
            }

            return(retval);
        }