public void Orient() { double[] p1 = new[] { 0.10000000000000001, 0.10000000000000001 }; double[] p2 = new[] { 0.20000000000000001, 0.20000000000000004 }; double[] p3 = new[] { 0.79999999999999993, 0.80000000000000004 }; double[] p4 = new[] { 1.267650600228229e30, 1.2676506002282291e30 }; Assert.IsTrue(GP.Orient2DFast(p1, p2, p3) > 0.0); // Wrong! Assert.IsTrue(GP.Orient2DExact(p1, p2, p3) < 0.0); Assert.IsTrue(GP.Orient2DSlow(p1, p2, p3) < 0.0); Assert.IsTrue(GP.Orient2D(p1, p2, p3) < 0.0); Assert.IsTrue(GP.Orient2DFast(p1, p2, p4) == 0.0); // Wrong! Assert.IsTrue(GP.Orient2DExact(p1, p2, p4) < 0.0); Assert.IsTrue(GP.Orient2DSlow(p1, p2, p4) < 0.0); Assert.IsTrue(GP.Orient2D(p1, p2, p4) < 0.0); Assert.IsTrue(GP.Orient2DFast(p2, p3, p4) == 0.0); // Wrong! Assert.IsTrue(GP.Orient2DExact(p2, p3, p4) < 0.0); Assert.IsTrue(GP.Orient2DSlow(p2, p3, p4) < 0.0); Assert.IsTrue(GP.Orient2D(p2, p3, p4) < 0.0); Assert.IsTrue(GP.Orient2DFast(p3, p1, p4) == 0.0); // Wrong! Assert.IsTrue(GP.Orient2DExact(p3, p1, p4) > 0.0); Assert.IsTrue(GP.Orient2DSlow(p3, p1, p4) > 0.0); Assert.IsTrue(GP.Orient2D(p3, p1, p4) > 0.0); }
static double Orient2D_Checked_InOrder(double[] pa, double[] pb, double[] pc) { double fast = GP.Orient2DFast(pa, pb, pc); double exact = GP.Orient2DExact(pa, pb, pc); double slow = GP.Orient2DSlow(pa, pb, pc); double adapt = GP.Orient2D(pa, pb, pc); Assert.AreEqual(exact, slow); Assert.AreEqual(exact, adapt); // We don't expect these to be true, but it's nice to stop when they're not... // Assert.IsTrue(Math.Sign(fast) == Math.Sign(exact)); // Assert.IsTrue(Math.Abs(fast - exact) < 1e-4); if (Math.Sign(fast) != Math.Sign(adapt)) { Debug.Print("Fast: " + fast + " Adapt: " + adapt); } return(adapt); }