本文整理汇总了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);
}
示例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)));
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
}
示例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));
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
}
}
}
示例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!!!"); }
}
示例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;
}
示例15: InDrawRange
public bool InDrawRange(Rectangle playerScreen)
{
return playerScreen.Contains(this._position.ToPoint());
}