Beispiel #1
0
        public void ContainsTopLeft()
        {
            var rect = new Rect2f(10, 10, 100, 100);

            Assert.True(rect.Contains(rect.TopLeft));
            Assert.True(rect.Contains(rect.Left, rect.Top));
        }
Beispiel #2
0
        public void DoNotContainsBottomRight()
        {
            var rect = new Rect2f(10, 10, 100, 100);

            Assert.False(rect.Contains(rect.BottomRight));
            Assert.False(rect.Contains(rect.Right, rect.Bottom));
        }
Beispiel #3
0
        public static bool LineRectangleIntersection( Vector2f p0, Vector2f p1, Rect2f rect )
        {
            if( rect.Contains( p0 ) || rect.Contains( p1 ) )
            {
                return true;
            }

            if( SegmentSegmentIntersection( p0, p1, rect.Origin, rect.BottomRight ) == IntersectionResult.INTERESECTING )
            {
                return true;
            }
            if( SegmentSegmentIntersection( p0, p1, rect.BottomRight, rect.TopRight ) == IntersectionResult.INTERESECTING )
            {
                return true;
            }
            if( SegmentSegmentIntersection( p0, p1, rect.TopRight, rect.TopLeft ) == IntersectionResult.INTERESECTING )
            {
                return true;
            }
            if( SegmentSegmentIntersection( p0, p1, rect.TopLeft, rect.Origin ) == IntersectionResult.INTERESECTING )
            {
                return true;
            }
            return false;
        }
Beispiel #4
0
        public void ContainsRect()
        {
            var rect = new Rect2f(10, 10, 100, 100);

            Assert.True(rect.Contains(rect));
        }
Beispiel #5
0
        public void Contains()
        {
            var rect = new Rect2f(new Point2f(0, 0), new Size2f(3, 3));

            // OpenCV typically assumes that the top and left boundary of the rectangle are inclusive,
            // while the right and bottom boundaries are not. https://docs.opencv.org/2.4/modules/core/doc/basic_structures.html?highlight=rect

            Assert.False(rect.Contains(0, -1));
            Assert.False(rect.Contains(-1, 0));
            Assert.False(rect.Contains(-1, -1));

            Assert.True(rect.Contains(0, 0));
            Assert.True(rect.Contains(0, 1));
            Assert.True(rect.Contains(1, 0));
            Assert.True(rect.Contains(1, 1));

            Assert.True(rect.Contains(2, 0));
            Assert.True(rect.Contains(2, 1));
            Assert.True(rect.Contains(2, 2));
            Assert.True(rect.Contains(0, 2));
            Assert.True(rect.Contains(1, 2));
            Assert.True(rect.Contains(2, 2));

            Assert.False(rect.Contains(0, 3));
            Assert.False(rect.Contains(1, 3));
            Assert.False(rect.Contains(2, 3));
            Assert.False(rect.Contains(3, 3));
            Assert.False(rect.Contains(3, 0));
            Assert.False(rect.Contains(3, 1));
            Assert.False(rect.Contains(3, 2));
            Assert.False(rect.Contains(3, 3));
        }