Example #1
0
        public void Distance()
        {
            var p1 = new Pnt(1, 2, 3);
            var p2 = new Pnt(4, 5, 6);

            Assert.AreEqual(27, p1.SquareDistance(p2));
            Assert.AreEqual(Math.Sqrt(27), p1.Distance(p2));
        }
        public void ValueType_Pnt()
        {
            var p1 = new Pnt(1, 2, 3);
            var p2 = new Pnt(4, 5, 6);

            Assert.AreEqual(new Pnt(0, 0, 0), Pnt.Origin);

            Assert.AreEqual(27, p1.SquareDistance(p2));
            Assert.AreEqual(Math.Sqrt(27), p1.Distance(p2));

            Assert.IsTrue(p1.IsEqual(p2, 5.2));
            Assert.IsFalse(p1.IsEqual(p2, 5.18));

            p2 = new Pnt(1, 2, 3);
            p2.Mirror(new Pnt(2, 2, 2));
            Assert.AreEqual(new Pnt(3, 2, 1), p2);
            Assert.AreEqual(new Pnt(3, 2, 1), p1.Mirrored(new Pnt(2, 2, 2)));

            p2 = new Pnt(1, 2, 3);
            p2.Translate(new Pnt(2, 2, 2), new Pnt(1, 2, 3));
            Assert.AreEqual(new Pnt(0, 2, 4), p2);
            Assert.AreEqual(new Pnt(0, 2, 4), p1.Translated(new Pnt(2, 2, 2), new Pnt(1, 2, 3)));

            Assert.AreEqual(new XYZ(1, 2, 3), p1.ToXYZ());

            p2 = new Pnt(1, 2, 3);
            p2.Scale(new Pnt(2, 2, 2), 2);
            Assert.AreEqual(new Pnt(0, 2, 4), p2);
            Assert.AreEqual(new Pnt(0, 2, 4), p1.Scaled(new Pnt(2, 2, 2), 2));

            p2.BaryCenter(2, p1, 5);
            Assert.IsTrue(p2.IsEqual(new Pnt(0.71428, 2, 3.28571), 0.00001));

            p2 = new Pnt(1, 2, 3);
            p2.Translate(new Vec(2, 2, 2));
            Assert.AreEqual(new Pnt(3, 4, 5), p2);
            Assert.AreEqual(new Pnt(3, 4, 5), p1.Translated(new Vec(2, 2, 2)));

            p2 = new Pnt(2, 1, 3);
            Assert.AreEqual(new Pnt(4, 4, 7), p2.Translated(new Vec(2, 3, 4)));
            p2.Translate(new Vec(2, 3, 4));
            Assert.AreEqual(new Pnt(4, 4, 7), p2);

            var m2 = new Ax1(new Pnt(-1, 2, -3), new Dir(-1, 0, 0));

            p2 = new Pnt(2, 1, 3);
            Assert.AreEqual(new Pnt(2, 3, -9), p2.Mirrored(m2));
            p2.Mirror(m2);
            Assert.AreEqual(new Pnt(2, 3, -9), p2);

            var a2 = new Ax2(new Pnt(-1, 2, -3), new Dir(-1, 0, 0));

            p2 = new Pnt(2, 1, 3);
            Assert.AreEqual(new Pnt(-4, 1, 3), p2.Mirrored(a2));
            p2.Mirror(a2);
            Assert.AreEqual(new Pnt(-4, 1, 3), p2);

            p2 = new Pnt(2, 1, 3);
            Assert.IsTrue(new Pnt(2, 8, -2).IsEqual(p2.Rotated(m2, Math.PI / 2), 0.0001));
            p2.Rotate(m2, Math.PI / 2);
            Assert.IsTrue(new Pnt(2, 8, -2).IsEqual(p2, 0.0001));

            //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", gp2.x, gp2.y, gp2.z));

            Trsf t1 = new Trsf();

            t1.SetRotation(Ax1.OZ, Math.PI / 2);
            p2 = new Pnt(4, 5, 6);
            Assert.AreEqual("-5,4,6", p2.Transformed(t1).ToString());
            p2.Transform(t1);
            Assert.AreEqual("-5,4,6", p2.ToString());
        }