internal static MapPoint GetMapPoint(MapLine thisline, int p) { MapPoint tmp = (MapPoint)thisline.APoints[p]; return(new MapPoint { X = tmp.X, Y = tmp.Y, Z = tmp.Z }); }
internal void OptimizeMap() { if (Lines != null) { List <MapLine> linesToRemove = new List <MapLine>(); MapLine lastline = null; FindvoidLines(linesToRemove, lastline); RemoveLines(linesToRemove); NormalizeMaxMinZ(); // Put in offsets for use when drawing text on map, for duplicate text at same location //OptimizeText(); } }
internal void ParseLP(string line, ref int numtexts, ref int numlines) { if (line.StartsWith("L")) { MapLine work = new MapLine(line); Lines.Add(work); numlines++; } else if (line.StartsWith("P")) { MapText work = new MapText(line); Texts.Add(work); numtexts++; } }
internal void FindvoidLines(List <MapLine> linesToRemove, MapLine lastline) { float prod; foreach (MapLine line in Lines) { MapLine thisline = line; if (thisline != null && lastline != null) { var thiscount = thisline.APoints.Count; var lastcount = lastline.APoints.Count; MapPoint thispoint = (MapPoint)thisline.APoints[0]; MapPoint thisnext = (MapPoint)thisline.APoints[1]; MapPoint lastpoint = (MapPoint)lastline.APoints[lastcount - 1]; MapPoint lastprev = (MapPoint)lastline.APoints[lastcount - 2]; Pen thisColor = thisline.LineColor; Pen lastColor = lastline.LineColor; int droppoint; if (PointsAreEqual(ref thispoint, ref lastpoint, thisColor, lastColor)) { droppoint = 0; // Take Dot Product to see if lines have 0 degrees between angle // Basic Dot Product, where varies from -1 at 180 degrees to 1 at 0 degrees if ((thiscount > 1) && (lastcount > 1)) { prod = CalcDotProduct(lastprev, thispoint, thisnext); droppoint = ProdPoint(prod, droppoint); } // Second Line Starts at End of First Line lastline.LinePoints = new PointF[thiscount + lastcount - 1 - droppoint]; for (var p = 0; p < (lastcount - droppoint); p++) { MapPoint tmp = (MapPoint)lastline.APoints[p]; lastline.LinePoints[p] = new PointF(tmp.X, tmp.Y); } if (droppoint == 1) { lastline.APoints.RemoveAt(lastcount - 1); } for (var p = 1; p < thiscount; p++) { MapPoint temp = GetMapPoint(thisline, p); lastline.LinePoints[p + lastcount - 1 - droppoint] = new PointF(temp.X, temp.Y); lastline.APoints.Add(temp); } linesToRemove.Add(thisline); thisline = lastline; } else { droppoint = 0; thispoint = (MapPoint)thisline.APoints[thiscount - 1]; MapPoint thisprev = (MapPoint)thisline.APoints[thiscount - 2]; lastpoint = (MapPoint)lastline.APoints[0]; MapPoint lastnext = (MapPoint)lastline.APoints[1]; if (lastpoint.X == thispoint.X && lastpoint.Y == thispoint.Y && lastpoint.Z == thispoint.Z && thisColor.Color == lastColor.Color) { prod = CalcDotProduct(thisprev, thispoint, lastnext); droppoint = ProdPoint(prod, droppoint); // Second Line Starts at End of First Line lastline.LinePoints = new PointF[thiscount + lastcount - 1 - droppoint]; if (droppoint == 1) { lastline.APoints.RemoveAt(0); } for (var p = 0; p < (thiscount - 1); p++) { MapPoint temp = GetMapPoint(thisline, p); lastline.APoints.Insert(p, temp); } thiscount = lastline.APoints.Count; for (var p = 0; p < thiscount; p++) { MapPoint tmp = (MapPoint)lastline.APoints[p]; lastline.LinePoints[p] = new PointF(tmp.X, tmp.Y); } linesToRemove.Add(thisline); thisline = lastline; } } } lastline = thisline; } }
public void OptimizeMap() { if (eq.lines == null) { return; } ArrayList linesToRemove = new ArrayList(); MapLine lastline = null; float prod; var pointsdrop = 0; foreach (MapLine line in eq.lines) { MapLine thisline = line; if (thisline != null && lastline != null) { var thiscount = thisline.aPoints.Count; MapPoint thispoint = (MapPoint)thisline.aPoints[0]; MapPoint thisnext = (MapPoint)thisline.aPoints[1]; Pen thisColor = thisline.color; var lastcount = lastline.aPoints.Count; MapPoint lastpoint = (MapPoint)lastline.aPoints[lastcount - 1]; MapPoint lastprev = (MapPoint)lastline.aPoints[lastcount - 2]; Pen lastColor = lastline.color; int droppoint; if (lastpoint.x == thispoint.x && lastpoint.y == thispoint.y && lastpoint.z == thispoint.z && thisColor.Color == lastColor.Color) { droppoint = 0; // Take Dot Product to see if lines have 0 degrees between angle // Basic Dot Product, where varies from -1 at 180 degrees to 1 at 0 degrees if ((thiscount > 1) && (lastcount > 1)) { prod = CalcDotProduct(lastprev.x, lastprev.y, lastprev.z, thispoint.x, thispoint.y, thispoint.z, thisnext.x, thisnext.y, thisnext.z); if (prod > 0.9999f) { pointsdrop++; droppoint = 1; } } // Second Line Starts at End of First Line lastline.linePoints = new PointF[thiscount + lastcount - 1 - droppoint]; for (int p = 0; p < (lastcount - droppoint); p++) { MapPoint tmp = (MapPoint)lastline.aPoints[p]; lastline.linePoints[p] = new PointF(tmp.x, tmp.y); } if (droppoint == 1) { lastline.aPoints.RemoveAt(lastcount - 1); } for (int p = 1; p < thiscount; p++) { MapPoint tmp = (MapPoint)thisline.aPoints[p]; lastline.linePoints[p + lastcount - 1 - droppoint] = new PointF(tmp.x, tmp.y); MapPoint temp = new MapPoint { x = tmp.x, y = tmp.y, z = tmp.z }; lastline.aPoints.Add(temp); } linesToRemove.Add(thisline); thisline = lastline; } else { droppoint = 0; thispoint = (MapPoint)thisline.aPoints[thiscount - 1]; MapPoint thisprev = (MapPoint)thisline.aPoints[thiscount - 2]; lastpoint = (MapPoint)lastline.aPoints[0]; MapPoint lastnext = (MapPoint)lastline.aPoints[1]; if (lastpoint.x == thispoint.x && lastpoint.y == thispoint.y && lastpoint.z == thispoint.z && thisColor.Color == lastColor.Color) { prod = CalcDotProduct(thisprev.x, thisprev.y, thisprev.z, thispoint.x, thispoint.y, thispoint.z, lastnext.x, lastnext.y, lastnext.z); if (prod > 0.9999f) { pointsdrop++; droppoint = 1; // look here } // Second Line is at beginning of first line lastline.linePoints = new PointF[thiscount + lastcount - 1 - droppoint]; if (droppoint == 1) { lastline.aPoints.RemoveAt(0); } for (int p = 0; p < (thiscount - 1); p++) { MapPoint tmp = (MapPoint)thisline.aPoints[p]; MapPoint temp = new MapPoint { x = tmp.x, y = tmp.y, z = tmp.z }; lastline.aPoints.Insert(p, temp); } thiscount = lastline.aPoints.Count; for (int p = 0; p < thiscount; p++) { MapPoint tmp = (MapPoint)lastline.aPoints[p]; lastline.linePoints[p] = new PointF(tmp.x, tmp.y); } linesToRemove.Add(thisline); thisline = lastline; } } } lastline = thisline; } foreach (MapLine lineToRemove in linesToRemove) { eq.lines.Remove(lineToRemove); } foreach (MapLine line in eq.lines) { line.maxZ = line.minZ = line.Point(0).z; for (int j = 1; j < line.aPoints.Count; j++) { if (line.minZ > line.Point(j).z) { line.minZ = line.Point(j).z; } if (line.maxZ < line.Point(j).z) { line.maxZ = line.Point(j).z; } } } // Put in offsets for use when drawing text on map, for duplicate text at same location int index = 0; foreach (MapText tex1 in eq.texts) { int index2 = 0; foreach (MapText tex2 in eq.texts) { if (index2 > index && tex1.x == tex2.x && tex1.y == tex2.y && tex1.z == tex2.z && tex1.text != tex2.text) { tex2.offset = tex1.offset + (int)(2.0f * Settings.Instance.MapLabelFontSize); } index2++; } index++; } }