public void DouglasPeuckerAlgorithmSimplifyTest() { // first line string Double delta = 5.0; List <Coordinate> coordinates = new List <Coordinate>(new Coordinate[] { new Coordinate(1.0, 1.0, 0.0), new Coordinate(2.0, 5.0, 0.0), new Coordinate(5.0, 2.0, 0.0) }); IList <Coordinate> result = DouglasPeuckerAlgorithm.Simplify(coordinates, delta); Assert.IsTrue(result.Count == 2); Assert.IsTrue(result[0].X == 1.0 && result[0].Y == 1.0); Assert.IsTrue(result[1].X == 5.0 && result[1].Y == 2.0); // third line string delta = 2.0; coordinates = new List <Coordinate>(new Coordinate[] { new Coordinate(0.0, 3.0, 0.0), new Coordinate(0.5, 3.0, 1.0), new Coordinate(1.5, 2.0, 0.0), new Coordinate(2.5, 1.0, 0.0), new Coordinate(3.7, 3.9, 0.0), new Coordinate(5.0, 3.0, 0.0) }); result = DouglasPeuckerAlgorithm.Simplify(coordinates, delta); Assert.IsTrue(result.Count == 2); Assert.IsTrue(result[0].X == 0.0 && result[0].Y == 3.0 && result[0].Z == .0); Assert.IsTrue(result[1].X == 5.0 && result[1].Y == 3.0 && result[1].Z == .0); // third line string delta = 2.0; coordinates = new List <Coordinate>(new Coordinate[] { new Coordinate(0.0, 3.0, 0.0), new Coordinate(0.0, 3.0, 3.0), new Coordinate(1.5, 2.0, 0.0), new Coordinate(2.5, 1.0, 0.0), new Coordinate(3.7, 3.9, 0.0), new Coordinate(5.0, 3.0, 0.0) }); result = DouglasPeuckerAlgorithm.Simplify(coordinates, delta); Assert.IsTrue(result.Count == 3); Assert.IsTrue(result[0].X == 0.0 && result[0].Y == 3.0 && result[0].Z == .0); Assert.IsTrue(result[1].X == 0.0 && result[1].Y == 3.0 && result[1].Z == 3.0); Assert.IsTrue(result[2].X == 5.0 && result[2].Y == 3.0 && result[2].Z == .0); // exceptions Assert.Throws <ArgumentNullException>(() => DouglasPeuckerAlgorithm.Simplify((IList <Coordinate>)null, 1.0)); Assert.Throws <ArgumentOutOfRangeException>(() => DouglasPeuckerAlgorithm.Simplify(coordinates, 0)); }
public void DouglasPeuckerAlgorithmSimplifyTest() { // first line string Double delta = 5.0; List <Coordinate> coordinates = new List <Coordinate>(new Coordinate[] { new Coordinate(1.0, 1.0, 0.0), new Coordinate(2.0, 5.0, 0.0), new Coordinate(5.0, 2.0, 0.0) }); IReadOnlyList <Coordinate> result = DouglasPeuckerAlgorithm.Simplify(coordinates, delta); result.Count.ShouldBe(2); result[0].X.ShouldBe(1.0); result[0].Y.ShouldBe(1.0); result[1].X.ShouldBe(5.0); result[1].Y.ShouldBe(2.0); // third line string delta = 2.0; coordinates = new List <Coordinate>(new Coordinate[] { new Coordinate(0.0, 3.0, 0.0), new Coordinate(0.5, 3.0, 1.0), new Coordinate(1.5, 2.0, 0.0), new Coordinate(2.5, 1.0, 0.0), new Coordinate(3.7, 3.9, 0.0), new Coordinate(5.0, 3.0, 0.0) }); result = DouglasPeuckerAlgorithm.Simplify(coordinates, delta); result.Count.ShouldBe(2); result[0].X.ShouldBe(0.0); result[0].Y.ShouldBe(3.0); result[0].Z.ShouldBe(0.0); result[1].X.ShouldBe(5.0); result[1].Y.ShouldBe(3.0); result[1].Z.ShouldBe(0.0); // third line string delta = 2.0; coordinates = new List <Coordinate>(new Coordinate[] { new Coordinate(0.0, 3.0, 0.0), new Coordinate(0.0, 3.0, 3.0), new Coordinate(1.5, 2.0, 0.0), new Coordinate(2.5, 1.0, 0.0), new Coordinate(3.7, 3.9, 0.0), new Coordinate(5.0, 3.0, 0.0) }); result = DouglasPeuckerAlgorithm.Simplify(coordinates, delta); result.Count.ShouldBe(3); result[0].X.ShouldBe(0.0); result[0].Y.ShouldBe(3.0); result[0].Z.ShouldBe(0.0); result[1].X.ShouldBe(0.0); result[1].Y.ShouldBe(3.0); result[1].Z.ShouldBe(3.0); result[2].X.ShouldBe(5.0); result[2].Y.ShouldBe(3.0); result[2].Z.ShouldBe(0.0); // exceptions Should.Throw <ArgumentNullException>(() => DouglasPeuckerAlgorithm.Simplify((List <Coordinate>)null, 1.0)); Should.Throw <ArgumentOutOfRangeException>(() => DouglasPeuckerAlgorithm.Simplify(coordinates, 0)); }