示例#1
0
        public void Angle()
        {
            var p1 = new Dir(1, 0, 0);
            var p2 = new Dir(0, 1, 0);

            Assert.AreEqual(Math.PI / 2, p1.Angle(p2));
            Assert.AreEqual(Math.PI / 2, p1.AngleWithRef(p2, new Dir(0, 0, 1)));
        }
        public void ValueType_Dir()
        {
            Assert.AreEqual(new Dir(1, 0, 0), Dir.DX);
            Assert.AreEqual(new Dir(0, 1, 0), Dir.DY);
            Assert.AreEqual(new Dir(0, 0, 1), Dir.DZ);

            var p1 = new Dir(1, 0, 0);
            var p2 = new Dir(0, 1, 0);

            Assert.IsFalse(p1.IsEqual(p2, 0.1));
            Assert.IsTrue(p1.IsEqual(p2, Math.PI / 2));
            Assert.IsTrue(p1.IsNormal(p2, 0.1));
            Assert.IsFalse(p1.IsOpposite(p2, 0.1));
            Assert.IsTrue(p1.IsOpposite(p2, Math.PI / 2));
            Assert.IsFalse(p1.IsParallel(p2, 0.1));
            Assert.IsTrue(p1.IsParallel(p2, Math.PI / 2));

            Assert.AreEqual(Math.PI / 2, p1.Angle(p2));
            Assert.AreEqual(Math.PI / 2, p1.AngleWithRef(p2, new Dir(0, 0, 1)));

            p2 = new Dir(1, 0, 0);
            p2.Cross(new Dir(0, 1, 0));
            Assert.AreEqual(new Dir(0, 0, 1), p2);
            Assert.AreEqual(new Dir(0, 0, 1), p1.Crossed(new Dir(0, 1, 0)));

            p2 = new Dir(1, 0, 0);
            p2.CrossCross(new Dir(0, 1, 0), new Dir(1, 0, 1));
            Assert.AreEqual(new Dir(0, 1, 0), p2);
            Assert.AreEqual(new Dir(0, 1, 0), p1.CrossCrossed(new Dir(0, 1, 0), new Dir(1, 0, 1)));

            Assert.AreEqual(Math.Sqrt(2) / 2, p1.Dot(new Dir(1, 1, 0)), 0.0000001);
            Assert.AreEqual(Math.Sqrt(2) / 2, p1.DotCross(new Dir(0, 1, 0), new Dir(1, 0, 1)), 0.0000001);

            p2 = new Dir(1, 0, 0);
            p2.Reverse();
            Assert.AreEqual(new Dir(-1, 0, 0), p2);
            Assert.AreEqual(new Dir(-1, 0, 0), p1.Reversed());

            p2 = new Dir(1, 0, 0);
            p2.Mirror(new Dir(0, 1, 0));
            Assert.AreEqual(new Dir(-1, 0, 0), p2);
            Assert.AreEqual(new Dir(-1, 0, 0), p1.Mirrored(new Dir(0, 1, 0)));

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

            p2 = new Dir(1, 0, 0);
            p2.Mirror(m2);
            Assert.AreEqual(new Dir(1, 0, 0), p2);
            Assert.AreEqual(new Dir(1, 0, 0), p1.Mirrored(m2));

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

            p2 = new Dir(1, 0, 0);
            Assert.AreEqual(new Dir(-1, 0, 0), p2.Mirrored(a2));
            p2.Mirror(a2);
            Assert.AreEqual(new Dir(-1, 0, 0), p2);

            p2 = new Dir(1, 0, 0);
            p2.Rotate(m2, Math.PI / 2);
            Assert.AreEqual(new Dir(1, 0, 0), p2);
            Assert.AreEqual(new Dir(1, 0, 0), p1.Rotated(m2, Math.PI / 2));

            //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 Dir(0, 1, 0);
            Assert.AreEqual("-1,1.11022302462516E-16,0", p2.Transformed(t1).ToString());
            p2.Transform(t1);
            Assert.AreEqual("-1,1.11022302462516E-16,0", p2.ToString());
        }