public MoveToFront(Point[] ps) { ValidateArg.IsNotNull(ps, "ps"); this.ps = ps; L = new LinkedList<int>(); for (int i = 0; i < ps.Length; ++i) { L.AddLast(i); } MinDisc md = mtf_md(null, new List<int>()); disc = md.disc; boundary = md.boundary; }
public void ContainingTests() { Disc disc = new Disc(new Point(10, 0), new Point(-10, 0)); Point[] points = new Point[] { new Point(0, 10), new Point(0, 12), new Point(0, -10), new Point(20, 0) }; WriteLine("Trying correct except"); int[] except = new int[] { 1, 3 }; Assert.IsTrue(disc.Contains(points, except), "ContainingTest not working"); WriteLine("Trying incomplete except"); except = new int[] { 1 }; Assert.IsFalse(disc.Contains(points, except), "ContainingTest not working"); WriteLine("Trying empty and incorrect except"); except = new int[] { }; Assert.IsFalse(disc.Contains(points, except), "ContainingTest not working"); }
public void NonCollinearThreePointsDiscTests() { WriteLine("Try non-colliear case next"); Point p1 = new Point(random.Next(MaxValue), random.Next(MaxValue)); Point p2 = new Point(random.Next(MaxValue), random.Next(MaxValue)); Point p3 = new Point(random.Next(MaxValue), random.Next(MaxValue)); MakePointsNotSame(ref p1, ref p2); MakePointsNotSame(ref p1, ref p3); MakePointsNotSame(ref p2, ref p3); Disc disc = new Disc(p1, p2, p3); WriteLine(string.Format("p1 {0}, p2 {1} and p3 {2}", p1, p2, p3)); Assert.AreEqual(disc.Radius, (disc.Center - p1).Length, Tolerance, string.Format("point p1 {0} not on the disc centered {1} with radius {2}", p1, disc.Center, disc.Radius)); Assert.AreEqual(disc.Radius, (disc.Center - p2).Length, Tolerance, string.Format("point p2 {0} not on the disc centered {1} with radius {2}", p2, disc.Center, disc.Radius)); Assert.AreEqual(disc.Radius, (disc.Center - p3).Length, Tolerance, string.Format("point p3 {0} not on the disc centered {1} with radius {2}", p3, disc.Center, disc.Radius)); }
public MinDisc(Point[] ps, List<int> b) { this.boundary = b; Debug.Assert(b.Count <= 3); switch(b.Count) { case 0: disc = null; break; case 1: disc = new Disc(ps[b[0]]); break; case 2: disc = new Disc(ps[b[0]], ps[b[1]]); break; case 3: disc = new Disc(ps[b[0]], ps[b[1]], ps[b[2]]); break; } }
/// <summary> /// Computing the minimum enclosing disc the slow stupid way. Just for testing purposes. /// </summary> /// <param name="points"></param> /// <returns>Smallest disc that encloses all the points</returns> public static Disc SlowComputation(Point[] points) { ValidateArg.IsNotNull(points, "points"); int n = points.Length; Disc mc = null; int[] b = null; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i != j) { Disc c = new Disc(points[i], points[j]); if (c.Contains(points, new int[] { i, j })) { if (mc == null || mc.Radius > c.Radius) { mc = c; b = new int[] { i, j }; } } } for (int k = 0; k < n; ++k) { if (k != i && k != j && !Disc.Collinear(points[i],points[j],points[k])) { Disc c3 = new Disc(points[i], points[j], points[k]); if (c3.Contains(points, new int[]{i,j,k})) { if (mc == null || mc.Radius > c3.Radius) { mc = c3; b = new int[] { i, j, k }; } } } } } } Debug.Assert(b != null); return mc; }