public void TestDegenerateSailboat()
        {
            // A set of edges that represents the fancy art above. Note that in this test case
            // the width/height is a bit lengthened to really ensure that the top rectangle is
            // much bigger.
            Edge[] edges = new Edge[]
            {
                new Edge(new Vector2(0, 0), new Vector2(100, 0)),
                new Edge(new Vector2(100, 0), new Vector2(100, 1)),
                new Edge(new Vector2(100, 1), new Vector2(1, 1)),
                new Edge(new Vector2(1, 1), new Vector2(1, 2)),
                new Edge(new Vector2(1, 2), new Vector2(100, 2)),
                new Edge(new Vector2(100, 2), new Vector2(0, 100)),
                new Edge(new Vector2(0, 100), new Vector2(0, 0)),
            };

            InscribedRectangle rectangle = new InscribedRectangle(edges, 0 /*randomSeed*/);

            // The area should be greater than 100 because:
            // 1) The area of the rectangle below would roughly be less than or equal to 100, and this
            //    rectangle shouldn't get chosen by the algorithm because it's the smaller one.
            Assert.GreaterOrEqual(rectangle.Height * rectangle.Width, 100);

            // The center should be above y = 2 (i.e. we shouldn't be choosing the tiny sliver
            // under the sailboat).
            Assert.GreaterOrEqual(rectangle.Center.y, 2);
        }
        private void RunCase(LargestRectangleTestCase testCase)
        {
            InscribedRectangle inscribedRectangle = new InscribedRectangle(testCase.Polygon, 20);
            Vector2            actualCenter;
            float actualAngle;
            float actualWidth;
            float actualHeight;

            inscribedRectangle.GetRectangleParams(out actualCenter, out actualAngle, out actualWidth, out actualHeight);

            bool passed =
                FloatsEqual(testCase.ExpectedCenter.x, actualCenter.x) &&
                FloatsEqual(testCase.ExpectedCenter.y, actualCenter.y) &&
                FloatsEqual(testCase.ExpectedAngle, actualAngle) &&
                FloatsEqual(testCase.ExpectedWidth, actualWidth) &&
                FloatsEqual(testCase.ExpectedHeight, actualHeight);

            if (!passed)
            {
                var message = string.Format("Test Case \"{0}\" failed\r\nExpected: ({1},{2})  {3}  {4}  {5}\r\nActual: ({6},{7})  {8}  {9}  {10}",
                                            testCase.Name,
                                            testCase.ExpectedCenter.x,
                                            testCase.ExpectedCenter.y,
                                            testCase.ExpectedAngle,
                                            testCase.ExpectedWidth,
                                            testCase.ExpectedHeight,
                                            actualCenter.x,
                                            actualCenter.y,
                                            actualAngle,
                                            actualWidth,
                                            actualHeight
                                            );
                Assert.Fail(message);
            }
        }
        public void TestSimpleRectangle()
        {
            // A set of edges that represents a 10x10 square.
            Edge[] edges = new Edge[]
            {
                new Edge(new Vector2(0, 0), new Vector2(0, 10)),
                new Edge(new Vector2(0, 10), new Vector2(100, 10)),
                new Edge(new Vector2(100, 10), new Vector2(100, 0)),
                new Edge(new Vector2(100, 0), new Vector2(0, 0))
            };

            InscribedRectangle rectangle = new InscribedRectangle(edges, 0 /*randomSeed*/);

            AssertWithinTolerance(10.0, rectangle.Height);
            AssertWithinTolerance(100.0, rectangle.Width);
        }
Esempio n. 4
0
        /// <summary>
        /// Retrieves the boundary geometry and creates the boundary and inscribed play space volumes.
        /// </summary>
        private void CalculateBoundaryBounds()
        {
            // Reset the bounds
            Bounds            = new Edge[0];
            FloorHeight       = null;
            rectangularBounds = null;

            // Boundaries are supported for Room Scale experiences only.
            if (XRDevice.GetTrackingSpaceType() != TrackingSpaceType.RoomScale)
            {
                return;
            }

            // Get the boundary geometry.
            var boundaryGeometry = new List <Vector3>(0);
            var boundaryEdges    = new List <Edge>(0);

            if (Boundary.TryGetGeometry(boundaryGeometry, Boundary.Type.TrackedArea))
            {
                // FloorHeight starts out as null. Use a suitably high value for the floor to ensure
                // that we do not accidentally set it too low.
                float floorHeight = float.MaxValue;

                for (int i = 0; i < boundaryGeometry.Count; i++)
                {
                    Vector3 pointA = boundaryGeometry[i];
                    Vector3 pointB = boundaryGeometry[(i + 1) % boundaryGeometry.Count];
                    boundaryEdges.Add(new Edge(pointA, pointB));

                    floorHeight = Mathf.Min(floorHeight, boundaryGeometry[i].y);
                }

                FloorHeight = floorHeight;
                Bounds      = boundaryEdges.ToArray();
                CreateInscribedBounds();
            }
            else
            {
                Debug.LogWarning("Failed to calculate boundary bounds.");
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Creates the two dimensional volume described by the largest rectangle that
 /// is contained withing the play space geometry and the configured height.
 /// </summary>
 private void CreateInscribedBounds()
 {
     // We always use the same seed so that from run to run, the inscribed bounds are consistent.
     rectangularBounds = new InscribedRectangle(Bounds, Mathf.Abs("Mixed Reality Toolkit".GetHashCode()));
 }