public void BreakIntoSmallPortions( ref List <Drawable> ls, ref DrawableGroup last_group, ref float last_group_length, int max_length) { float straight_length = (this.P3 - this.P0).Normalize(); int lens = Math.Max(1, (int)Math.Round(straight_length / max_length)); float this_length = this.GetLength(lens); float included_length = 0; if (last_group != null) { float length_left = max_length - last_group_length - this_length; if (length_left > 0) { last_group._List.Add(new DrawableLine(this.P0, this.P3)); last_group_length += this_length; return; } else if (length_left == 0) { last_group._List.Add(new DrawableLine(this.P0, this.P3)); last_group = null; return; } else { included_length = max_length - last_group_length; ls.Add(new DrawableLine(this.P0, this.GetLocation(included_length / this_length))); last_group = null; // Continue } } while (included_length + max_length <= this_length) { ls.Add(new DrawableLine( this.GetLocation(included_length / this_length), this.GetLocation((included_length + max_length) / this_length))); included_length += max_length; } if (included_length == this_length) { return; } var second_last_point = this.GetLocation(included_length / this_length); last_group_length = (second_last_point - this.P3).Normalize(); last_group = new DrawableGroup(new DrawableLine( second_last_point, this.P3)); ls.Add(last_group); }
public void BreakIntoSmallPortions( ref List <Drawable> ls, ref DrawableGroup last_group, ref float last_group_length, int max_length) { throw new Exception("Should never happen"); }
public void BreakIntoSmallPortions( ref List <Drawable> ls, ref DrawableGroup last_group, ref float last_group_length, int max_length) { float included_length = 0; var normalized_difference = (this.Second - this.First); float this_length = normalized_difference.Normalize(); if (last_group != null) { float length_left = max_length - last_group_length - this_length; if (length_left > 0) { last_group._List.Add(this); last_group_length += this_length; return; } else if (length_left == 0) { last_group._List.Add(this); last_group = null; return; } else { included_length = max_length - last_group_length; ls.Add(new DrawableLine(this.First, this.First + normalized_difference * included_length)); last_group = null; // Continue } } while (included_length + max_length <= this_length) { ls.Add(new DrawableLine( this.First + normalized_difference * included_length, this.First + normalized_difference * (included_length + max_length))); included_length += max_length; } if (included_length == this_length) { return; } last_group_length = this_length - included_length; last_group = new DrawableGroup(new DrawableLine( this.First + normalized_difference * included_length, this.Second)); ls.Add(last_group); }
public SVG(string file_text, string file_path) { int viewboxes = 0; int transforms = 0; var list = new List <List <Drawable> >(); var file = TagFile.ParseText(file_text); foreach (var b in file.Enumerate()) { if (b is TagFile) { var tf = b as TagFile; string outp; switch (tf._Name) { case "svg": if (tf._Params.TryGetValue("viewBox", out outp)) { var strs = outp.Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (strs.Length == 4) { viewboxes++; this._ViewBox.X = int.Parse(strs[0]); this._ViewBox.Y = int.Parse(strs[1]); this._ViewBox.Width = int.Parse(strs[2]); this._ViewBox.Height = int.Parse(strs[3]); } else { Console.WriteLine("ViewBox Error: " + outp); } } break; case "g": if (tf._Params.TryGetValue("transform", out outp)) { transforms++; this._Transform = this.ParseTransform(outp); } break; case "path": // Handled Later! break; } } } if (transforms != 1) { string s = "SVG has " + transforms + " transforms"; Console.WriteLine(s); throw new Exception(s); } if (viewboxes != 1) { string s = "SVG has " + transforms + " transforms"; Console.WriteLine(s); throw new Exception(s); } foreach (var b in file.Enumerate()) { if (b is TagFile) { var tf = b as TagFile; switch (tf._Name) { case "path": foreach (var kvp in tf._Params) { switch (kvp.Key) { case "id": break; case "d": if (kvp.Value.Contains("NaN")) { Console.WriteLine(file_path + " contains some NaN's"); } else { this.ParsePath(this.Enumerate(kvp.Value), ref list); } break; default: Console.WriteLine("Path Error: " + kvp.Key + ", " + kvp.Value); break; } } break; } } } var ls = new List <Drawable>(); DrawableGroup last_group = null; float last_group_length = 0; foreach (var continuity in list) { foreach (var element in continuity) { element.BreakIntoSmallPortions( ref ls, ref last_group, ref last_group_length, SVG.INCREMENT_DISTANCE); } } this._LiveDraw = ls.ToArray(); }