private static List <CIntersection> DetectIntersectionOneEdge(CEdge cedge, CEdgeGrid fEdgeGrid, List <CValPair <int, int> > intRowColVpLt, bool blnJustTestIfIntersect = false, bool blnTouchBothEnds = false, bool blnTouchEndEdge = false, bool blnOverlap = false, SortedSet <CEdge> IgnoreCEdgeSS = null) { var IntersectionLt = new List <CIntersection>(); var TraversedCEdgeLt = new List <CEdge>(); bool blnIntersect = false; //this variable effects only when blnJustTestIfIntersect==true foreach (var RowColVp in intRowColVpLt) { if (RowColVp.val1 < 0 || RowColVp.val1 >= fEdgeGrid.intRowCount || RowColVp.val2 < 0 || RowColVp.val2 >= fEdgeGrid.intColCount) { continue; } foreach (var pcedge in fEdgeGrid.aCEdgeLtCell[RowColVp.val1, RowColVp.val2]) { if (pcedge.isTraversed == true || (IgnoreCEdgeSS != null && IgnoreCEdgeSS.Contains(pcedge))) { continue; } pcedge.isTraversed = true; TraversedCEdgeLt.Add(pcedge); var pIntersection = cedge.IntersectWith(pcedge); if (pIntersection.JudgeIntersect(blnTouchBothEnds, blnTouchEndEdge, blnOverlap)) { IntersectionLt.Add(pIntersection); //record the intersection in the whole Lt if (blnJustTestIfIntersect == true) { blnIntersect = true; break; } else { cedge.IntersectLt.Add(pIntersection); //record the intersection in the CEdge //add the intersection to the other edge pcedge.IntersectLt.Add(pIntersection.ReverseIntersection()); } } } if (blnJustTestIfIntersect == true && blnIntersect == true) { break; } } //Set the TraversedCEdge to false foreach (var TraversedCEdge in TraversedCEdgeLt) { TraversedCEdge.isTraversed = false; } return(IntersectionLt); }
/// <summary> /// /// </summary> /// <param name="cedgelt"></param> /// <param name="rawfaceLt"></param> /// <returns></returns> private List <CPolygon> MergeFaces(List <CEdge> cedgelt, ref List <CPolygon> rawfaceLt) { List <CPoint> holeleftcptlt = new List <CPoint>(rawfaceLt.Count); foreach (CPolygon cpg in rawfaceLt) { if (cpg.IsHole == true) { cpg.LeftMostCpt.HoleCpg = cpg; holeleftcptlt.Add(cpg.LeftMostCpt); } } //CEdgeGrid pEdgeGrid = new CEdgeGrid(cedgelt); //put edges in the cells of a grid //_pEdgeGrid = CGeoFunc.DetectCloestLeftCorrectCEdge(cedgelt, ref holeleftcptlt); _pEdgeGrid = new CEdgeGrid(cedgelt); //put edges in the cells of a grid DetectCloestLeftCorrectCEdge(holeleftcptlt); int intCount = 0; CPolygon SuperFace = new CPolygon(); SuperFace.InnerCmptCEdgeLt = new List <CEdge>(); foreach (var rawface in rawfaceLt) { if (rawface.IsHole == true) { //LeftFace can be a hole or the face inluding the current hole //we merge the information of faces and store the information in the LeftFace //we don't need to care about the OuterCmptCEdge, because it is always from the LeftFace which will be kept CPolygon TargetFace = null; if (rawface.LeftMostCpt.ClosestLeftCIntersection != null) //there is an edge to the left { //LeftFace is the original incident face of rawface.LeftMostCpt.ClosestLeftCIntersection.CEdge2 CPolygon LeftFace = rawface.LeftMostCpt.ClosestLeftCIntersection.CEdge2IncidentFace; if (LeftFace.IsHole == true) { //TargetCpg may or may not be LeftFace because the cedgeInnerComponent of a face may be updated to indicate another cpgIncidentFace TargetFace = LeftFace.InnerCmptCEdgeLt[0].cpgIncidentFace; TargetFace.InnerCmptCEdgeLt.AddRange(rawface.InnerCmptCEdgeLt); } else //LeftFace is the TargetCpg { if (LeftFace.InnerCmptCEdgeLt == null) { LeftFace.InnerCmptCEdgeLt = rawface.InnerCmptCEdgeLt; } else { LeftFace.InnerCmptCEdgeLt.AddRange(rawface.InnerCmptCEdgeLt); } TargetFace = LeftFace; } } else { SuperFace.InnerCmptCEdgeLt.AddRange(rawface.InnerCmptCEdgeLt); TargetFace = SuperFace; } foreach (var cedgeInnerComponent in rawface.InnerCmptCEdgeLt) { cedgeInnerComponent.cpgIncidentFace = TargetFace; } intCount++; } } //add each face into FaceCpgLt foreach (CPolygon rawface in rawfaceLt) { rawface.isTraversed = false; } List <CPolygon> FaceCpgLt = new List <CPolygon>(rawfaceLt.Count - intCount + 1); FaceCpgLt.Add(SuperFace); SuperFace.isTraversed = true; foreach (CPolygon rawface in rawfaceLt) { if (rawface.OuterCmptCEdge != null) { if (rawface.OuterCmptCEdge.cpgIncidentFace.isTraversed == false) { FaceCpgLt.Add(rawface.OuterCmptCEdge.cpgIncidentFace); rawface.OuterCmptCEdge.cpgIncidentFace.isTraversed = true; } } } UpdateEdgeIncidentFace(FaceCpgLt); return(FaceCpgLt); }