当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle.Contains方法代码示例

本文整理汇总了C#中Rectangle.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Contains方法的具体用法?C# Rectangle.Contains怎么用?C# Rectangle.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rectangle的用法示例。


在下文中一共展示了Rectangle.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 static void Main(string[] args)
 {
     Rectangle room = new Rectangle() { A = GetPoint(), B = GetPoint(), C = GetPoint(), D = GetPoint() };
     double radius = double.Parse(Console.ReadLine());
     double step = double.Parse(Console.ReadLine());
     int positionsCount = 0;
     for (double x = 0; x <= radius; x += step)
     {
         for (double y = 0; y <= radius; y += step)
             if (room.Contains(x, y) && Math.Sqrt(x * x + y * y) <= radius)
                 positionsCount++;
         for (double y = -step; y >= -radius; y -= step)
             if (room.Contains(x, y) && Math.Sqrt(x * x + y * y) <= radius)
                 positionsCount++;
     }
     for (double x = -step; x >= -radius; x -= step)
     {
         for (double y = 0; y <= radius; y += step)
             if (room.Contains(x, y) && Math.Sqrt(x * x + y * y) <= radius)
                 positionsCount++;
         for (double y = -step; y >= -radius; y -= step)
             if (room.Contains(x, y) && Math.Sqrt(x * x + y * y) <= radius)
                 positionsCount++;
     }
     Console.WriteLine(positionsCount);
 }
开发者ID:astambi,项目名称:Programming-Basics,代码行数:26,代码来源:04+Teleport+Points.cs

示例2: Contains

 public void Contains()
 {
     var rect = new Rectangle(1, 2, 10, 20);
     Assert.IsTrue(rect.Contains(new Point(1, 2)));
     Assert.IsTrue(rect.Contains(new Point(5, 5)));
     Assert.IsFalse(rect.Contains(new Point(11, 5)));
     Assert.IsFalse(rect.Contains(new Point(5, 22)));
 }
开发者ID:hillwhite,项目名称:DeltaEngine,代码行数:8,代码来源:RectangleTests.cs

示例3: ContainsCornerPixelsTest

 public void ContainsCornerPixelsTest()
 {
     var _Rectangle = new Rectangle<Double>(10, 20, 30, 40);
     var _Pixel1    = new Pixel<Double>(10, 20);
     var _Pixel2    = new Pixel<Double>(30, 20);
     var _Pixel3    = new Pixel<Double>(10, 40);
     var _Pixel4    = new Pixel<Double>(30, 40);
     Assert.IsTrue(_Rectangle.Contains(_Pixel1));
     Assert.IsTrue(_Rectangle.Contains(_Pixel2));
     Assert.IsTrue(_Rectangle.Contains(_Pixel3));
     Assert.IsTrue(_Rectangle.Contains(_Pixel4));
 }
开发者ID:Vanaheimr,项目名称:Illias,代码行数:12,代码来源:RectangleTests.cs

示例4: TestContainsRect

        public void TestContainsRect()
        {
            Rectangle r1 = new Rectangle() { X = 0, Y = 0, Height = 10, Width = 10 };
            Rectangle r2 = new Rectangle() { X = 1, Y = 1, Height = 5, Width = 5 };

            Assert.IsTrue(r1.Contains(r2));
            Assert.IsFalse(r2.Contains(r1));
        }
开发者ID:bytetrail,项目名称:Hexiverse,代码行数:8,代码来源:RectangleTest.cs

示例5: TestBoundaryContainsRect

        public void TestBoundaryContainsRect()
        {
            Rectangle r1 = new Rectangle() { X = 0, Y = 0, Height = 10, Width = 10 };
            Rectangle r2 = new Rectangle() { X = 0, Y = 0, Height = 10, Width = 10 };

            Assert.IsTrue(r1.Contains(r2));
            Assert.IsTrue(r2.Contains(r1));
        }
开发者ID:bytetrail,项目名称:Hexiverse,代码行数:8,代码来源:RectangleTest.cs

示例6: ListFeatures

 /// <summary>
 /// Gets all features contained within the given bounding rectangle.
 /// </summary>
 public async Task ListFeatures(Rectangle request, Grpc.Core.IServerStreamWriter<Feature> responseStream, Grpc.Core.ServerCallContext context)
 {
     var responses = features.FindAll( (feature) => feature.Exists() && request.Contains(feature.Location) );
     foreach (var response in responses)
     {
         await responseStream.WriteAsync(response);
     }
 }
开发者ID:xianglinghui,项目名称:grpc,代码行数:11,代码来源:RouteGuideImpl.cs

示例7: TestPointContains

        public void TestPointContains()
        {
            Rectangle r1 = new Rectangle() { X = 0, Y = 0, Height = 10, Width = 10 };

            PointD2D p1 = new PointD2D() { X = 5, Y = 5 };
            Assert.IsTrue(r1.Contains(p1));

            p1 = new PointD2D() { X = 0, Y = 0 };
            Assert.IsTrue(r1.Contains(p1));

            p1 = new PointD2D() { X = 9, Y = 9 };
            Assert.IsTrue(r1.Contains(p1));

            p1 = new PointD2D() { X = -1, Y = 0 };
            Assert.IsFalse(r1.Contains(p1));

            p1 = new PointD2D() { X = 10, Y = 0 };
            Assert.IsFalse(r1.Contains(p1));
        }
开发者ID:bytetrail,项目名称:Hexiverse,代码行数:19,代码来源:RectangleTest.cs

示例8: HitTest

    //
    // Interface
    public static bool HitTest(Point a, Point b, Point p, Point q)
    {
        // Validate arguments.
        if (a == b) throw new ArgumentException("Line segment AB is a singular point.");
        if (p == q) throw new ArgumentException("Line segment PQ is a singular point.");

        // Take cross product from A to B, through P and then Q;
        // return false if same sign.
        double apb = Math.Sign(Geometry.CrossABC(a,p,b));
        double aqb = Math.Sign(Geometry.CrossABC(a,q,b));
        if (apb < 0 && aqb < 0) return false;
        if (apb > 0 && aqb > 0) return false;

        // Now, do the same from P to Q, through A and then B.
        double paq = Math.Sign(Geometry.CrossABC(p,a,q));
        double pbq = Math.Sign(Geometry.CrossABC(p,b,q));
        if (paq < 0 && pbq < 0) return false;
        if (paq > 0 && pbq > 0) return false;

        // We either intersect, or have a collinear case; we check the more common first
        // (whereby none of the signs is zero).
        if (apb*aqb*paq*pbq != 0)
            return true;

        // At least one of our endpoints is collinear with the other segment; we test
        // the endpoints against the bounding boxes, to determine intersection.
        Point abUL = new Point(Math.Min(a.X,b.X),Math.Min(a.Y,b.Y));
        Size abWH = new Size(Math.Abs(a.X-b.X)+1,Math.Abs(a.Y-b.Y)+1);
        Rectangle abRect = new Rectangle(abUL,abWH);

        if (apb == 0 && abRect.Contains(p)) return true;
        if (aqb == 0 && abRect.Contains(q)) return true;

        Point pqUL = new Point(Math.Min(p.X,q.X),Math.Min(p.Y,q.Y));
        Size pqWH = new Size(Math.Abs(p.X-q.X)+1,Math.Abs(p.Y-q.Y)+1);
        Rectangle pqRect = new Rectangle(pqUL,pqWH);

        if (paq == 0 && pqRect.Contains(a)) return true;
        if (pbq == 0 && pqRect.Contains(b)) return true;

        // If we made it this far, the segments are not touching.
        return false;
    }
开发者ID:pichiliani,项目名称:CoPhysicsSimulator,代码行数:45,代码来源:SegmentCollision.cs

示例9: BothRectanglesMustContainEachPointOfTheirIntersection

        public void BothRectanglesMustContainEachPointOfTheirIntersection()
        {
            Rectangle a = new Rectangle (1, 1, 5, 5);
            Rectangle b = new Rectangle (3, 3, 5, 5);
            Rectangle c = a.IntersectionWith (b);

            foreach (Point p in c) {
                Assert.That (a.Contains (p), Is.True);
                Assert.That (b.Contains (p), Is.True);
            }
        }
开发者ID:manicolosi,项目名称:questar,代码行数:11,代码来源:RectangleFixture.cs

示例10: TestContains

        public void TestContains()
        {
            var rectZero = new Rectangle(Vector2.Zero, Vector2.Zero);
            var rect1_2 = new Rectangle(new Vector2(1, 1), new Vector2(2, 2));
            var rectNeg10_20 = new Rectangle(new Vector2(-10, -10), new Vector2(20, 20));
            Assert.IsTrue(rectZero.Contains(rectZero));
            Assert.IsFalse(rectZero.Contains(rect1_2));
            Assert.IsFalse(rect1_2.Contains(rectZero));
            Assert.IsTrue(rectNeg10_20.Contains(rectZero));
            Assert.IsTrue(rectNeg10_20.Contains(rect1_2));
            Assert.IsFalse(rectZero.Contains(rectNeg10_20));
            Assert.IsFalse(rect1_2.Contains(rectNeg10_20));

            var fixedRect = new Rectangle(new Vector2(1, 51), new Vector2(3, 53));
            for (int maxX = 0; maxX < 3; maxX++)
                for (int minX = 0; minX <= maxX; minX++)
                    for (int maxY = 0; maxY < 3; maxY++)
                        for (int minY = 0; minY <= maxY; minY++)
                        {
                            var testRect = new Rectangle(new Vector2(2 * minX, 50 + 2 * minY), new Vector2(2 * maxX, 50 + 2 * maxY));
                            Assert.AreEqual(minX == 1 && maxX == 1 && minY == 1 && maxY == 1, fixedRect.Contains(testRect), "testRect = {0}", testRect);
                        }
        }
开发者ID:vvnurmi,项目名称:assaultwing,代码行数:23,代码来源:RectangleTest.cs

示例11: Main

 static void Main()
 {
     string x = null;
     string y = null;
     Console.Write("Enter width: ");
     x = Console.ReadLine();
     Console.Write("Enter height: ");
     y = Console.ReadLine();
     int intX = int.Parse(x);
     int intY = int.Parse(y);
     Rectangle rect = new Rectangle(1, -1, 6, 2);
     bool isInCirleAndOutRectangle = ((intX - 1) * (intX - 1) + (intY - 1) * (intY - 1) < 3 * 3)
         && !rect.Contains(intX, intY) ? true : false;
     Console.WriteLine("The point [{0}; {1}] is inside the cirle and outside the rectangle? {2}",
         intX, intY, isInCirleAndOutRectangle);
 }
开发者ID:xakepa,项目名称:csharp_part1,代码行数:16,代码来源:IsInCircleOutRectangle.cs

示例12: OnMouseDown

    protected override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);

        for (int i = 0; i < TabPages.Count; i++)
        {
            Rectangle bounds = GetTabRect(i);

            int offset = (bounds.Height - 16) / 2;
            Rectangle closeButton = new Rectangle(bounds.X + bounds.Width - 20, bounds.Y + offset, 14, 16);

            if (closeButton.Contains(e.Location))
            {
                if (MessageBox.Show(onCloseMsg, "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    TabPages.RemoveAt(i);
                    break;
                }
            }
        }
    }
开发者ID:TylerDev905,项目名称:CSharpCustomTabs,代码行数:21,代码来源:TabControlEx.cs

示例13: Main

    static void Main(string[] args)
    {
        double centerX = 1;
        double centerY = 1;
        double radius = 3;

        Console.WriteLine("Enter pointX:");
        int pointX = int.Parse(Console.ReadLine());
        Console.WriteLine("Enter pointY:");
        int pointY = int.Parse(Console.ReadLine());

        Rectangle rectangle = new Rectangle(1,-1,6,2);
        Point pt3 = new Point(pointX,pointY);

        bool IsInCircle = (Math.Pow((pointX - centerX), 2) + Math.Pow((pointY - centerY), 2) < Math.Pow(radius, 2));
        bool IsOutRectangle = rectangle.Contains(pointX,pointY );

        if (IsInCircle == true && IsOutRectangle == true)
        {
            Console.WriteLine("Point is in the circle and out of rectangle");
        }
        else { Console.WriteLine("Conditions not accomplished!!!"); }
    }
开发者ID:velinsi,项目名称:TelerikAcademySpring,代码行数:23,代码来源:InCircleOutRectangle.cs

示例14: DrunkWalk

        public static MovementPath DrunkWalk(Point start, Point end, Rectangle acceptableArea)
        {
            MovementPath newPath = new MovementPath(null);
            newPath.AddPoint(start);
            Point currentPoint = start;
            Point midPoint = end;

            Point point1 = end;
            Point point2 = null;

            for (int deviations = 0; deviations < 7; deviations++)
            {
                point1 = Point.MidPoint(start, point1).Shift(MovementPath.randomDirection(), 3);
                if (acceptableArea.Contains(point1))
                {
                    newPath.AddPoint(point1);
                }

                if (point2 != null)
                {
                    point2 = Point.MidPoint(point2, end).Shift(MovementPath.randomDirection(), 3);
                    if (acceptableArea.Contains(point2))
                    {
                        newPath.AddPoint(point2);
                    }
                }
                else
                {
                    point2 = point1;
                }
            }

            newPath.AddPoint(end);

            return newPath;
        }
开发者ID:DisruptionTheory,项目名称:WebDE,代码行数:36,代码来源:MovementPath_Static.cs

示例15: InDrawRange

 public bool InDrawRange(Rectangle playerScreen)
 {
     return playerScreen.Contains(this._position.ToPoint());
 }
开发者ID:sylar605,项目名称:TshockCN,代码行数:4,代码来源:MoonlordDeathDrama.cs


注:本文中的Rectangle.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。