예제 #1
0
        public void TestRectangleF2DNoDirection()
        {
            RectangleF2D rectangle = new RectangleF2D(0, 0, 1, 1);

            Assert.AreEqual(0, rectangle.BottomLeft[0]);
            Assert.AreEqual(0, rectangle.BottomLeft[1]);
            Assert.AreEqual(1, rectangle.BottomRight[0]);
            Assert.AreEqual(0, rectangle.BottomRight[1]);
            Assert.AreEqual(0, rectangle.TopLeft[0]);
            Assert.AreEqual(1, rectangle.TopLeft[1]);
            Assert.AreEqual(1, rectangle.TopRight[0]);
            Assert.AreEqual(1, rectangle.TopRight[1]);
            Assert.AreEqual(0, rectangle.Angle.Value);

            BoxF2D box = rectangle.BoundingBox;

            Assert.AreEqual(0, box.Min[0]);
            Assert.AreEqual(0, box.Min[1]);
            Assert.AreEqual(1, box.Max[0]);
            Assert.AreEqual(1, box.Max[1]);

            Assert.IsTrue(rectangle.Contains(0.25, 0.75));
            Assert.IsFalse(rectangle.Contains(1.2, 0.25));
            Assert.IsFalse(rectangle.Contains(0.25, 1.2));

            Assert.IsTrue(rectangle.Contains(new PointF2D(0.25, 0.75)));
            Assert.IsFalse(rectangle.Contains(new PointF2D(1.2, 0.25)));
            Assert.IsFalse(rectangle.Contains(new PointF2D(0.25, 1.2)));

            Assert.AreEqual(1, rectangle.Distance(new PointF2D(2, 0)));
            Assert.AreEqual(0, rectangle.Distance(new PointF2D(1, 0)));
            Assert.AreEqual(1, rectangle.Distance(new PointF2D(0, 2)));
            Assert.AreEqual(0, rectangle.Distance(new PointF2D(0, 1)));

            Assert.AreEqual(1, rectangle.Distance(new PointF2D(-1, 0.5)));
            Assert.AreEqual(0, rectangle.Distance(new PointF2D(0, 0.5)));

            Assert.AreEqual(1, rectangle.Height);
            Assert.AreEqual(1, rectangle.Width);

            double[] converted = rectangle.TransformFrom(100, 100, false, false,
                                                         new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(0.25, converted [0]);
            Assert.AreEqual(0.75, converted [1]);
            double[] convertedBack = rectangle.TransformTo(100, 100, false, false,
                                                           converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(25, convertedBack [0]);
            Assert.AreEqual(75, convertedBack [1]);

            converted = rectangle.TransformFrom(100, 100, false, true,
                                                new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(0.25, converted [0]);
            Assert.AreEqual(0.25, converted [1]);
            convertedBack = rectangle.TransformTo(100, 100, false, false,
                                                  converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(25, convertedBack [0]);
            Assert.AreEqual(25, convertedBack [1]);

            converted = rectangle.TransformFrom(100, 100, true, false,
                                                new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(0.75, converted [0]);
            Assert.AreEqual(0.75, converted [1]);
            convertedBack = rectangle.TransformTo(100, 100, false, false,
                                                  converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(75, convertedBack [0]);
            Assert.AreEqual(75, convertedBack [1]);

            converted = rectangle.TransformFrom(100, 100, true, true,
                                                new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(0.75, converted [0]);
            Assert.AreEqual(0.25, converted [1]);
            convertedBack = rectangle.TransformTo(100, 100, false, false,
                                                  converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(75, convertedBack [0]);
            Assert.AreEqual(25, convertedBack [1]);
        }