public void storeSegments2() //获取边与点,取代上面三个函数,目前使用中 { if (sket.GetSketchPoints2() == null) { Debug.Print("No points!"); return; } verNum = sket.GetSketchPoints2().Length; //以下为保存边、边的邻接点;点、点的邻接边的操作 adj = new int[verNum, verNum]; for (int i = 0; i < verNum; i++) //初始化邻接点数组,为之后的最小环提取做准备,在存储点与边的同时需要存储邻接关系 { for (int j = 0; j < verNum; j++) { adj[i, j] = INF; } } object[] segments = sket.GetSketchSegments(); foreach (SketchSegment seg in segments) //此时遍历所有边,判断边的类型,而后分类存储 { bool flag = false; int type = seg.GetType(); switch (type) { case 0: flag = false; loopSeg temLine = new loopSeg(seg); SketchLine line = (SketchLine)seg; temLine.setPoint(addPoint(line.GetStartPoint2()), addPoint(line.GetEndPoint2())); temLine.setIndex(loopSegs.Count); for (int i = 0; i < loopSegs.Count; i++) { if (temLine.same(loopSegs[i])) { flag = true; } } if (!flag) { loopSegs.Add(temLine); pois[temLine.start].setNext(temLine.end); pois[temLine.end].setNext(temLine.start); pois[temLine.start].setNextSeg2(temLine.index); pois[temLine.end].setNextSeg2(temLine.index); adj[temLine.start, temLine.end] = 1; adj[temLine.end, temLine.start] = 1; } break; case 1: flag = false; loopSeg temArc = new loopSeg(seg); SketchArc arc = (SketchArc)seg; temArc.setPoint(addPoint(arc.GetStartPoint2()), addPoint(arc.GetEndPoint2())); temArc.setIndex(loopSegs.Count); for (int i = 0; i < loopSegs.Count; i++) { if (temArc.same(loopSegs[i])) { flag = true; } } if (!flag) { loopSegs.Add(temArc); pois[temArc.start].setNext(temArc.end); pois[temArc.end].setNext(temArc.start); pois[temArc.start].setNextSeg2(temArc.index); pois[temArc.end].setNextSeg2(temArc.index); adj[temArc.start, temArc.end] = 1; adj[temArc.end, temArc.start] = 1; } break; case 2: flag = false; loopSeg temEll = new loopSeg(seg); SketchEllipse ell = (SketchEllipse)seg; temEll.setPoint(addPoint(ell.GetStartPoint2()), addPoint(ell.GetEndPoint2())); temEll.setIndex(loopSegs.Count); for (int i = 0; i < loopSegs.Count; i++) { if (temEll.same(loopSegs[i])) { flag = true; } } if (!flag) { loopSegs.Add(temEll); pois[temEll.start].setNext(temEll.end); pois[temEll.end].setNext(temEll.start); pois[temEll.start].setNextSeg2(temEll.index); pois[temEll.end].setNextSeg2(temEll.index); adj[temEll.start, temEll.end] = 1; adj[temEll.end, temEll.start] = 1; } break; case 3: flag = false; loopSeg temSpl = new loopSeg(seg); SketchSpline spl = (SketchSpline)seg; object[] tem = spl.GetPoints2(); temSpl.setPoint(addPoint((SketchPoint)tem[0]), addPoint((SketchPoint)tem[tem.Length - 1])); temSpl.setIndex(loopSegs.Count); for (int i = 0; i < loopSegs.Count; i++) { if (temSpl.same(loopSegs[i])) { flag = true; } } if (!flag) { loopSegs.Add(temSpl); pois[temSpl.start].setNext(temSpl.end); pois[temSpl.end].setNext(temSpl.start); pois[temSpl.start].setNextSeg2(temSpl.index); pois[temSpl.end].setNextSeg2(temSpl.index); adj[temSpl.start, temSpl.end] = 1; adj[temSpl.end, temSpl.start] = 1; } break; case 5: flag = false; loopSeg temPar = new loopSeg(seg); SketchParabola par = (SketchParabola)seg; temPar.setPoint(addPoint(par.GetStartPoint2()), addPoint(par.GetEndPoint2())); temPar.setIndex(loopSegs.Count); for (int i = 0; i < loopSegs.Count; i++) { if (temPar.same(loopSegs[i])) { flag = true; } } if (!flag) { loopSegs.Add(temPar); pois[temPar.start].setNext(temPar.end); pois[temPar.end].setNext(temPar.start); pois[temPar.start].setNextSeg2(temPar.index); pois[temPar.end].setNextSeg2(temPar.index); adj[temPar.start, temPar.end] = 1; adj[temPar.end, temPar.start] = 1; } break; case 4: break; } } }