//public void SetSlope(ref List <CEdge > CEdgeLt)
        //{
        //    CGeoFunc.SetSlope(ref CEdgeLt);
        //}


        /// <summary>Detect the intesection between two edges</summary>
        /// <returns >the intersection point</returns>
        /// <remarks>the edges have to be set slope before using this function
        ///                  If the two edges overlap, then the IntersectCpt is the point with larger XY coordinate of the two ends of the overlap line segment
        /// </remarks>
        public void DetectIntersection()
        {
            CEdge cedge1 = _CEdge1;
            CEdge cedge2 = _CEdge2;

            cedge1.JudgeAndSetSlope();
            cedge2.JudgeAndSetSlope();

            CPoint IntersectCpt = null;
            CEdge  overlapcedge = null;
            CEnumIntersectionType penumIntersectionType = CEnumIntersectionType.NoNo;


            if (cedge1.blnHasSlope == true && cedge2.blnHasSlope == true)   //this is the normal case
            {
                //if (CCmpMethods.Cmp(cedge1.dblSlope, cedge2.dblSlope)==0)  //parallel
                if (CCmpMethods.CmpDbl_ConstVerySmall(cedge1.dblSlope, cedge2.dblSlope) == 0)               //parallel
                {
                    if (CCmpMethods.CmpDbl_CoordVerySmall(cedge1.dblYIntercept, cedge2.dblYIntercept) == 0) //parallel and with the same YIntercept
                    {
                        penumIntersectionType = DetectIntersectionParralel(cedge1, cedge2, out IntersectCpt, out overlapcedge);
                    }
                    else    //parallel but not with the same YIntercept
                    {
                        penumIntersectionType = CEnumIntersectionType.NoNo;
                    }
                }
                else  //not parallel
                {
                    penumIntersectionType = DetectIntersectionNormal(cedge1, cedge2, out IntersectCpt);
                }
            }
            else if (cedge1.blnHasSlope == true && cedge2.blnHasSlope == false)
            {
                penumIntersectionType = DetectIntersectionOneNoSlope(cedge1, cedge2, out IntersectCpt);
            }
            else if (cedge1.blnHasSlope == false && cedge2.blnHasSlope == true)
            {
                penumIntersectionType = DetectIntersectionOneNoSlope(cedge2, cedge1, out IntersectCpt);
                penumIntersectionType = ReverseIntersectionType(penumIntersectionType);
            }
            else if (cedge1.blnHasSlope == false && cedge2.blnHasSlope == false)
            {
                if (CCmpMethods.CmpDbl_CoordVerySmall(cedge1.FrCpt.X, cedge2.FrCpt.X) == 0)   //parallel and with the same X Coordinate
                {
                    penumIntersectionType = DetectIntersectionParralel(cedge1, cedge2, out IntersectCpt, out overlapcedge);
                }
                else    //parallel but not with the same X Coordinate
                {
                    penumIntersectionType = CEnumIntersectionType.NoNo;
                }
            }

            _enumIntersectionType = penumIntersectionType;
            _IntersectCpt         = IntersectCpt;
            _OverlapCEdge         = overlapcedge;
        }
 public CIntersection(CEdge cedge1, CEdge cedge2, CPoint pIntersectCpt, CEdge pOverlapCEdge,
                      CEnumIntersectionType penumIntersectionType)
 {
     _CEdge1               = cedge1;
     _CEdge2               = cedge2;
     _IntersectCpt         = pIntersectCpt;
     _OverlapCEdge         = pOverlapCEdge;
     _enumIntersectionType = penumIntersectionType;
 }
        private CEnumIntersectionType ReverseIntersectionType(CEnumIntersectionType penumIntersectionType)
        {
            CEnumIntersectionType ReversedEnumIntersectionType = penumIntersectionType;

            switch (penumIntersectionType)
            {
            case CEnumIntersectionType.NoNo:
                break;

            case CEnumIntersectionType.FrFr:
                break;

            case CEnumIntersectionType.FrIn:
                ReversedEnumIntersectionType = CEnumIntersectionType.InFr;
                break;

            case CEnumIntersectionType.FrTo:
                ReversedEnumIntersectionType = CEnumIntersectionType.ToFr;
                break;

            case CEnumIntersectionType.InFr:
                ReversedEnumIntersectionType = CEnumIntersectionType.FrIn;
                break;

            case CEnumIntersectionType.InIn:
                break;

            case CEnumIntersectionType.InTo:
                ReversedEnumIntersectionType = CEnumIntersectionType.ToIn;
                break;

            case CEnumIntersectionType.ToFr:
                ReversedEnumIntersectionType = CEnumIntersectionType.FrTo;
                break;

            case CEnumIntersectionType.ToIn:
                ReversedEnumIntersectionType = CEnumIntersectionType.InTo;
                break;

            case CEnumIntersectionType.ToTo:
                break;

            case CEnumIntersectionType.Overlap:
                break;

            default:
                break;
            }
            return(ReversedEnumIntersectionType);
        }
 private CEnumIntersectionType DetectIntersectionParralelIncrease(CEdge cedge1, CEdge cedge2,
                                                                  out CPoint IntersectCpt, out CEdge overlapcedge)
 {
     if (CCmpMethods.CmpCptXY(cedge1.ToCpt, cedge2.ToCpt) <= 0)   //we compare both x and y so that we can handle two edges which have no slope
     {
         return(DetectIntersectionParralelIncreaseCEdge2Righter(cedge1, cedge2, out IntersectCpt, out overlapcedge));
     }
     else
     {
         CEnumIntersectionType enumIntersectionType =
             DetectIntersectionParralelIncreaseCEdge2Righter(cedge2, cedge1, out IntersectCpt, out overlapcedge);
         return(ReverseIntersectionType(enumIntersectionType));
     }
 }
        private CEnumIntersectionType DetectIntersectionParralel(CEdge cedge1, CEdge cedge2,
                                                                 out CPoint IntersectCpt, out CEdge overlapcedge)
        {
            CEdge auxCEdge1    = cedge1;
            bool  blnReversed1 = false;

            if (CCmpMethods.CmpCptXY(cedge1.FrCpt, cedge1.ToCpt) == 1)
            {
                auxCEdge1    = new CEdge(cedge1.ToCpt, cedge1.FrCpt);
                blnReversed1 = true;
            }

            CEdge auxCEdge2    = cedge2;
            bool  blnReversed2 = false;

            if (CCmpMethods.CmpCptXY(cedge2.FrCpt, cedge2.ToCpt) == 1)
            {
                auxCEdge2    = new CEdge(cedge2.ToCpt, cedge2.FrCpt);
                blnReversed2 = true;
            }

            CEnumIntersectionType penumIntersectionType =
                DetectIntersectionParralelIncrease(auxCEdge1, auxCEdge2, out IntersectCpt, out overlapcedge);

            if (penumIntersectionType == CEnumIntersectionType.FrTo || penumIntersectionType == CEnumIntersectionType.ToFr)   //besides, penumIntersectionType coud be CEnumIntersectionType.NoNo or CEnumIntersectionType.Overlap
            {
                string substr1 = penumIntersectionType.ToString().Substring(0, 2);
                string substr2 = penumIntersectionType.ToString().Substring(2, 2);
                if (blnReversed1 == true)
                {
                    substr1 = ReverseEnd(substr1);
                }
                if (blnReversed2 == true)
                {
                    substr2 = ReverseEnd(substr2);
                }

                string strIntersectionType = substr1 + substr2;
                return((CEnumIntersectionType)Enum.Parse(typeof(CEnumIntersectionType), strIntersectionType));
            }
            return(penumIntersectionType);
        }