private static int SortByWeight(Segment a, Segment b) { if (a == null) { if (b == null) return 0; return 1; } if (b == null) { return -1; } if (a.Weight == b.Weight) return 0; if (a.Weight > b.Weight) return -1; else return 1; }
public Segment Next() { if (!HasNext()) return null; int index = 0; Segment seg = new Segment(polys); TtPoint prev = points[index]; index++; seg.Add(prev); bool finished = false; bool travStarted = false; bool startTypeFound = (prev.IsGpsType() || (prev.op == OpType.Quondam && ((QuondamPoint)prev).ParentPoint.IsGpsType())); bool SavePrev = false; TtPoint current; string currentPolygon = prev.PolyCN; if (index == points.Count) points.Remove(prev); while (index < points.Count && !finished) { current = points[index]; if (currentPolygon != current.PolyCN) { finished = true; points.Remove(prev); continue; } OpType tmpOp = current.op; TtPoint tmpQp = null; while (tmpOp == OpType.Quondam) { if (tmpQp == null) tmpQp = ((QuondamPoint)current).ParentPoint; else tmpQp = ((QuondamPoint)tmpQp).ParentPoint; tmpOp = tmpQp.op; } switch (tmpOp) { case OpType.GPS: case OpType.WayPoint: case OpType.Walk: case OpType.Take5: { if (seg.Count == 1) { if (startTypeFound) //Already have a point (and only 1), Segment is finished { finished = true; } else //left over trav point from a sideshot { seg = new Segment(polys); seg.Add(current); startTypeFound = true; } } else if (travStarted) //Or we are at the closing end of a traverse { finished = true; seg.Add(current); } else { throw new Exception("2nd GPS type without trav start"); } points.Remove(prev); index--; prev = current; break; } case OpType.Traverse: { if ( prev.op == OpType.Traverse || prev.op == OpType.Quondam && ((QuondamPoint)prev).ParentOp == OpType.Traverse) { //finished = true; seg.Add(current); points.Remove(prev); } else { seg.Add(current); if (startTypeFound) travStarted = true; if (!SavePrev) { if (points.Count == 1) points.Remove(current); points.Remove(prev); } else { SavePrev = false; index++; } } prev = current; break; } case OpType.SideShot: { if (seg.Count == 1) //Only the parent point for this sideshot so far { seg.Add(current); points.Remove(current); // don't remove the parent point, may be needed again finished = true; } else // skip this point { SavePrev = true; index++; } break; } } } return seg; }
public void Add(Segment s) { _list.Add(s); _sorted = false; }