public void Intersect() { Assert.AreEqual(diagD.Start, diagD.Intersect(diagD.Start)); Assert.AreEqual(diagD.End, diagD.Intersect(diagD.End)); Assert.AreEqual(diagF.Start, diagF.Intersect(diagF.Start)); Assert.AreEqual(diagF.End, diagF.Intersect(diagF.End)); Assert.AreEqual((PointD)diagI.Start, diagI.Intersect(diagI.Start)); Assert.AreEqual((PointD)diagI.End, diagI.Intersect(diagI.End)); for (int d = -2; d <= 4; d++) { Assert.AreEqual(new PointD(d, d), diagD.Intersect(new PointD(d, d))); Assert.AreEqual(new PointD(d, d), diagD.Intersect(new PointD(d - 1, d + 1))); Assert.AreEqual(new PointD(d, d), diagD.Intersect(new PointD(d + 1, d - 1))); Assert.AreEqual(new PointF(d, d), diagF.Intersect(new PointF(d, d))); Assert.AreEqual(new PointF(d, d), diagF.Intersect(new PointF(d - 1, d + 1))); Assert.AreEqual(new PointF(d, d), diagF.Intersect(new PointF(d + 1, d - 1))); Assert.AreEqual(new PointD(d, d), diagI.Intersect(new PointI(d, d))); Assert.AreEqual(new PointD(d, d), diagI.Intersect(new PointI(d - 1, d + 1))); Assert.AreEqual(new PointD(d, d), diagI.Intersect(new PointI(d + 1, d - 1))); } }
private void GeometryBasicTest() { Stopwatch timer = new Stopwatch(); long polyTicks = 0, polyEpsilonTicks = 0, lineTicks = 0, lineEpsilonTicks = 0; const double epsilon = 1e-10; const int outerLoop = 10000, innerLoop = 1000; const int iterations = outerLoop * innerLoop; for (int i = 0; i < outerLoop; i++) { PointD[] polygon = GeoAlgorithms.RandomPolygon(0, 0, 1000, 1000); LineD line = GeoAlgorithms.RandomLine(0, 0, 1000, 1000); LineD line2 = GeoAlgorithms.RandomLine(0, 0, 1000, 1000); PointD q = GeoAlgorithms.RandomPoint(0, 0, 1000, 1000); // trigger JIT compilation if (i == 0) { GeoAlgorithms.PointInPolygon(q, polygon); GeoAlgorithms.PointInPolygon(q, polygon, epsilon); line.Intersect(line2); line.Intersect(line2, epsilon); } timer.Restart(); for (int j = 0; j < innerLoop; j++) { line.Intersect(line2); } timer.Stop(); lineTicks += timer.ElapsedTicks; timer.Restart(); for (int j = 0; j < innerLoop; j++) { line.Intersect(line2, epsilon); } timer.Stop(); lineEpsilonTicks += timer.ElapsedTicks; timer.Restart(); for (int j = 0; j < innerLoop; j++) { GeoAlgorithms.PointInPolygon(q, polygon); } timer.Stop(); polyTicks += timer.ElapsedTicks; timer.Restart(); for (int j = 0; j < innerLoop; j++) { GeoAlgorithms.PointInPolygon(q, polygon, epsilon); } timer.Stop(); polyEpsilonTicks += timer.ElapsedTicks; } Output(" "); Output(String.Format("{0,12}", "Exact")); Output(String.Format("{0,12}", "Epsilon")); Output("\nLine Intersection "); Output(String.Format("{0,12:N2}", 1000 * AverageMicrosecs(lineTicks, iterations))); Output(String.Format("{0,12:N2}", 1000 * AverageMicrosecs(lineEpsilonTicks, iterations))); Output("\nPoint in Polygon "); Output(String.Format("{0,12:N2}", 1000 * AverageMicrosecs(polyTicks, iterations))); Output(String.Format("{0,12:N2}", 1000 * AverageMicrosecs(polyEpsilonTicks, iterations))); Output("\nTimes are nsec averages for exact and epsilon comparisons.\n"); Output("Point in Polygon uses random polygons with 3-60 vertices.\n"); }