public static void Simplify(Polyline input, double threshold, HandleSegment handler) { if (input.Length < 2) return; Polyline output = new Polyline(); Recurse(input, threshold, handler, 0, input.Length - 1); }
internal Box(Polyline line) { if (line.Length == 0) { _x1 = Double.NegativeInfinity; _y1 = Double.NegativeInfinity; _x2 = Double.PositiveInfinity; _y2 = Double.PositiveInfinity; } else { _x1 = _x2 = line[0].X; _y1 = _y2 = line[0].Y; for (int i = 0; i < line.Length; i++) { Position p = line[i]; if (p.X < _x1) _x1 = p.X; if (p.Y < _y1) _y1 = p.Y; if (p.X > _x2) _x2 = p.X; if (p.Y > _y2) _y2 = p.Y; } } }
public Polyline Transform(Polyline pl) { Polyline npl = new Polyline(); for (int i = 0; i < pl.Length; i++) { npl.Add(Transform(pl[i])); } return npl; }
public void ReverseTest() { Polyline a = new Polyline(); a.Add(new Position(1, 1)); a.Add(new Position(1, 2)); Polyline b = a.Reversed; Assert.AreEqual(2, b[0].Y); Assert.AreEqual(1, b[1].Y); Assert.AreEqual(1, a[0].Y); Assert.AreEqual(2, a[1].Y); }
public void AddTest() { Polyline a = new Polyline(); a.Add(new Position(1, 1)); a.Add(new Position(1, 2)); Polyline b = new Polyline(); b.Add(new Position(1, 3)); a.AddPolyline(b); Assert.AreEqual(1, a[0].Y); Assert.AreEqual(2, a[1].Y); Assert.AreEqual(3, a[2].Y); Assert.AreEqual(3, b[0].Y); }
private void Recurse(Polyline input, double threshold, int i, int j) { double maxDistance; int maxI; FindSplit(input, i, j, out maxDistance, out maxI); if (maxDistance > threshold) { Recurse(input, threshold, i, maxI); Recurse(input, threshold, maxI, j); } else { HandleSegment(i, j); } }
private static void FindSplit(Polyline l, int i, int j, out double maxDistance, out int maxI) { maxI = -1; maxDistance = 0.0; if (j - i <= 1) return; Position a = l[i]; Position b = l[j]; for (int k = i + 1; k < j; k++) { double distance = GetSegmentSquaredDistance(a, b, l[k]); if (distance > maxDistance || maxI == -1) { maxI = k; maxDistance = distance; } } }
public void TestArea() { Polyline triangle = new Polyline(); triangle.Add(new Position(1, 1)); triangle.Add(new Position(1, 2)); triangle.Add(new Position(2, 1)); triangle.Add(new Position(1, 1)); Assert.AreEqual(0.5, triangle.Area, Double.Epsilon); Polyline arrow = new Polyline(); arrow.Add(new Position(1, 1)); arrow.Add(new Position(1, 4)); arrow.Add(new Position(2, 3)); arrow.Add(new Position(3, 4)); arrow.Add(new Position(4, 3)); arrow.Add(new Position(3, 2)); arrow.Add(new Position(4, 1)); Assert.AreEqual(6.5, arrow.Area, Double.Epsilon); Assert.AreEqual(6.5, arrow.Reversed.Area, Double.Epsilon); }
public void TestSimplify() { Polyline p = new Polyline(); Assert.AreEqual(0, p.Simplify(1.0).Length); p = new Polyline(); p.Add(new Position(0, 0)); p.Add(new Position(0, 1)); p.Add(new Position(10, 1)); p.Add(new Position(2, 0)); Assert.AreEqual(4, p.Simplify(0.0).Length); Assert.AreEqual(4, p.Simplify(0.5).Length); Assert.AreEqual(3, p.Simplify(2).Length); Assert.AreEqual(2, p.Simplify(20).Length); Random seed = new Random(); p = new Polyline(); for (int i = 0; i < 6000; i++) { p.Add(new Position(seed.NextDouble(), seed.NextDouble())); } Polyline o = p.Simplify(0.01); }
public Polyline Apply(ApplyDelegate f) { Polyline new_line = new Polyline(); for (int i = 0; i < _points.Count; i++) { new_line.Add(f((Position)_points[i])); } return new_line; }
public Journey(Polyline line, double threshold) { _input = line; DouglasPeucker.Simplify(line, threshold, new DouglasPeucker.HandleSegment(HandleSegment)); }
public PolylineSimplifyBuilder(Polyline input) { this.input = input; output = new Polyline(); }
public Polyline SubString(int i, int j) { if (j <= i) throw new ArgumentOutOfRangeException(); if (i < 0 || Length < i) throw new ArgumentOutOfRangeException(); if (j < 0 || Length < j) throw new ArgumentOutOfRangeException(); Polyline new_line = new Polyline(); for (int k = i; k < j; k++) { new_line.Add((Position)_points[k]); } return new_line; }
public Polyline Clone() { Polyline l = new Polyline(); l._points = _points.GetRange(0, _points.Count); return l; }
public Polyline ApplyDegreesToRadians() { Polyline new_line = new Polyline(); for (int i = 0; i < _points.Count; i++) { Position p = (Position)_points[i]; new_line.Add(new Position(Math.PI * p.X / 180.0, Math.PI * p.Y / 180.0)); } return new_line; }
protected void Simplify(Polyline input, double threshold) { if (input.Length < 2) return; Recurse(input, threshold, 0, input.Length - 1); }
public void AddPolyline(Polyline p) { _points.AddRange(p._points); }