本文整理汇总了C#中Windows.Foundation.Rect.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Intersect方法的具体用法?C# Rect.Intersect怎么用?C# Rect.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Foundation.Rect
的用法示例。
在下文中一共展示了Rect.Intersect方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RectsOverlap
private static bool RectsOverlap(Rect r1, Rect r2)
{
r1.Intersect(r2);
if (r1.Width > 0 || r1.Height > 0)
return true;
return false;
}
示例2: GetCoordinatesInView
public Point GetCoordinatesInView()
{
// TODO reasearch posibility to replace this code to GetClickablePoint()
var visualRoot = WiniumVirtualRoot.Current.VisualRoot.Element;
var element = this.Element;
var point = element.TransformToVisual(visualRoot).TransformPoint(new Point(0, 0));
var center = new Point(point.X + (int)(element.ActualWidth / 2), point.Y + (int)(element.ActualHeight / 2));
var bounds = new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
var boundsInView = new Rect(new Point(0, 0), visualRoot.RenderSize);
boundsInView.Intersect(bounds);
var result = boundsInView.IsEmpty
? center
: new Point(
boundsInView.X + (int)(boundsInView.Width / 2),
boundsInView.Y + (int)(boundsInView.Height / 2));
return ScreenCoordinatesHelper.LogicalPointToScreenPoint(result);
}
示例3: PlacePopup
private Point PlacePopup(Rect window, Point[] target, Point[] flyout, PlacementMode placement)
{
Point[] pointArray;
double y = 0.0;
double x = 0.0;
Rect bounds = GetBounds(target);
Rect rect2 = GetBounds(flyout);
double width = rect2.Width;
double height = rect2.Height;
if (placement == PlacementMode.Right)
{
double num5 = Math.Max(0.0, target[0].X);
double num6 = window.Width - Math.Min(window.Width, target[1].X + 1.0);
if ((num6 < width) && (num6 < num5))
{
placement = PlacementMode.Left;
}
}
else if (placement == PlacementMode.Left)
{
double num7 = window.Width - Math.Min(window.Width, target[1].X + 1.0);
double num8 = Math.Max(0.0, target[0].X);
if ((num8 < width) && (num8 < num7))
{
placement = PlacementMode.Right;
}
}
else if (placement == PlacementMode.Top)
{
double num9 = Math.Max(0.0, target[0].Y);
double num10 = window.Height - Math.Min(window.Height, target[2].Y + 1.0);
if ((num9 < height) && (num9 < num10))
{
placement = PlacementMode.Bottom;
}
}
else if (placement == PlacementMode.Bottom)
{
double num11 = Math.Max(0.0, target[0].Y);
double num12 = window.Height - Math.Min(window.Height, target[2].Y + 1.0);
if ((num12 < height) && (num12 < num11))
{
placement = PlacementMode.Top;
}
}
switch (placement)
{
case PlacementMode.Bottom:
pointArray = new Point[] { new Point(target[2].X, Math.Max((double)0.0, (double)(target[2].Y + 1.0))), new Point((target[3].X - width) + 1.0, Math.Max((double)0.0, (double)(target[2].Y + 1.0))), new Point(0.0, Math.Max((double)0.0, (double)(target[2].Y + 1.0))) };
break;
case PlacementMode.Right:
pointArray = new Point[] { new Point(Math.Max((double)0.0, (double)(target[1].X + 1.0)), target[1].Y), new Point(Math.Max((double)0.0, (double)(target[3].X + 1.0)), (target[3].Y - height) + 1.0), new Point(Math.Max((double)0.0, (double)(target[1].X + 1.0)), 0.0) };
break;
case PlacementMode.Left:
pointArray = new Point[] { new Point(Math.Min(window.Width, target[0].X) - width, target[1].Y), new Point(Math.Min(window.Width, target[2].X) - width, (target[3].Y - height) + 1.0), new Point(Math.Min(window.Width, target[0].X) - width, 0.0) };
break;
case PlacementMode.Top:
pointArray = new Point[] { new Point(target[0].X, Math.Min(target[0].Y, window.Height) - height), new Point((target[1].X - width) + 1.0, Math.Min(target[0].Y, window.Height) - height), new Point(0.0, Math.Min(target[0].Y, window.Height) - height) };
break;
default:
pointArray = new Point[] { new Point(0.0, 0.0) };
break;
}
double num13 = width * height;
int index = 0;
double num15 = 0.0;
for (int i = 0; i < pointArray.Length; i++)
{
Rect rect3 = new Rect(pointArray[i].X, pointArray[i].Y, width, height);
rect3.Intersect(window);
double d = rect3.Width * rect3.Height;
if (double.IsInfinity(d))
{
index = pointArray.Length - 1;
break;
}
if (d > num15)
{
index = i;
num15 = d;
}
if (d == num13)
{
index = i;
break;
}
}
// x = pointArray[index].X;
x = pointArray[0].X; // TODO: taking this solves my horizontal nudging, but is a hack...keeping it though until a better solution
y = pointArray[index].Y;
if (index > 1)
{
if ((placement == PlacementMode.Left) || (placement == PlacementMode.Right))
{
if (((y != target[0].Y) && (y != target[1].Y)) && (((y + height) != target[0].Y) && ((y + height) != target[1].Y)))
{
//.........这里部分代码省略.........
示例4: CheckCollision
//Check collision with flower and butterfly
public void CheckCollision()
{
// get rectangles
Rect r1 = new Rect(butterfly.LocationX, butterfly.LocationY, butterfly.ActualWidth, butterfly.ActualHeight);
Rect r2 = new Rect(flower.LocationX, flower.LocationY, flower.ActualWidth, flower.ActualHeight);
// does intersect...
r1.Intersect(r2);
if(!r1.IsEmpty) //not empty --> intersect happened
{
//remove flower
MyCanvas.Children.Remove(flower);
//play tada
mediaElement.Play();
//Add a new flower
AddFlower();
}
}
示例5: Blit
public static void Blit(BitmapContext destContext, int dpw, int dph, Rect destRect, BitmapContext srcContext, Rect sourceRect, int sourceWidth)
{
const BlendMode blendMode = BlendMode.Alpha;
int dw = (int)destRect.Width;
int dh = (int)destRect.Height;
Rect intersect = new Rect(0, 0, dpw, dph);
intersect.Intersect(destRect);
if (intersect.IsEmpty)
{
return;
}
#if WPF
var isPrgba = srcContext.Format == PixelFormats.Pbgra32 || srcContext.Format == PixelFormats.Prgba64 || srcContext.Format == PixelFormats.Prgba128Float;
#endif
var sourcePixels = srcContext.Pixels;
var destPixels = destContext.Pixels;
int sourceLength = srcContext.Length;
int sourceIdx = -1;
int px = (int)destRect.X;
int py = (int)destRect.Y;
int x;
int y;
int idx;
double ii;
double jj;
int sr = 0;
int sg = 0;
int sb = 0;
int dr, dg, db;
int sourcePixel;
int sa = 0;
int da;
var sw = (int)sourceRect.Width;
var sdx = sourceRect.Width / destRect.Width;
var sdy = sourceRect.Height / destRect.Height;
int sourceStartX = (int)sourceRect.X;
int sourceStartY = (int)sourceRect.Y;
int lastii, lastjj;
lastii = -1;
lastjj = -1;
jj = sourceStartY;
y = py;
for (var j = 0; j < dh; j++)
{
if (y >= 0 && y < dph)
{
ii = sourceStartX;
idx = px + y * dpw;
x = px;
sourcePixel = sourcePixels[0];
// Pixel by pixel copying
for (var i = 0; i < dw; i++)
{
if (x >= 0 && x < dpw)
{
if ((int)ii != lastii || (int)jj != lastjj)
{
sourceIdx = (int)ii + (int)jj * sourceWidth;
if (sourceIdx >= 0 && sourceIdx < sourceLength)
{
sourcePixel = sourcePixels[sourceIdx];
sa = ((sourcePixel >> 24) & 0xff);
sr = ((sourcePixel >> 16) & 0xff);
sg = ((sourcePixel >> 8) & 0xff);
sb = ((sourcePixel) & 0xff);
}
else
{
sa = 0;
}
}
if (sa > 0)
{
int destPixel = destPixels[idx];
da = ((destPixel >> 24) & 0xff);
if ((sa == 255 || da == 0))
{
destPixels[idx] = sourcePixel;
}
else
{
dr = ((destPixel >> 16) & 0xff);
dg = ((destPixel >> 8) & 0xff);
db = ((destPixel) & 0xff);
var isa = 255 - sa;
#if NETFX_CORE
// Special case for WinRT since it does not use pARGB (pre-multiplied alpha)
destPixel = ((da & 0xff) << 24) |
((((sr * sa + isa * dr) >> 8) & 0xff) << 16) |
((((sg * sa + isa * dg) >> 8) & 0xff) << 8) |
(((sb * sa + isa * db) >> 8) & 0xff);
#elif WPF
if (isPrgba)
{
//.........这里部分代码省略.........
示例6: UpdateImageSource
private void UpdateImageSource(Rect updateRectangle)
{
if (Window.Current.Visible)
{
var imageRectangle = new Rect(new Point(), _canvasImageSource.Size);
updateRectangle.Intersect(imageRectangle);
using (var drawingSession = _canvasImageSource.CreateDrawingSession(Colors.Transparent, updateRectangle))
{
drawingSession.DrawImage(_accumulationRenderTarget); // Render target has the composed frame
}
}
}
示例7: CheckCollision
// Check Collision of Flower and Butterfly
public void CheckCollision()
{
// Get Rectangles
Rect r1 = new Rect(butterfly.LocationX, butterfly.LocationY, butterfly.ActualWidth, butterfly.ActualHeight);
Rect r2 = new Rect(flower.LocationX, flower.LocationY, flower.ActualWidth, flower.ActualHeight);
// Does Intersect...
r1.Intersect(r2);
if (!r1.IsEmpty) // Not Empty --> Intersected
{
// Remove Flower
MyCanvas.Children.Remove(flower);
// Play Tada
mediaElement.Play();
// Add a New Flower
AddFlower();
}
}
示例8: IsUserVisible
internal bool IsUserVisible()
{
/* TODO: There is IsOffscreen method on AutomationPeer that can be used.
* But it returns true even if currentElement is on another pivot (i.e. invisible)
* var peer = FrameworkElementAutomationPeer.FromElement(this.Element);
* return peer != null && peer.IsOffscreen();
* This might improve speed but will make all non user interactable elements, like border, scrollbiew "invisible"
*/
var visualRoot = WiniumVirtualRoot.Current.VisualRoot.Element;
var currentElement = this.Element;
var currentElementSize = new Size(currentElement.ActualWidth, currentElement.ActualHeight);
// Check if currentElement is of zero size
if (currentElementSize.Width <= 0 || currentElementSize.Height <= 0)
{
return false;
}
var zero = new Point(0, 0);
var rect = new Rect(zero, currentElementSize);
var bound = currentElement.TransformToVisual(visualRoot).TransformBounds(rect);
var rootRect = new Rect(zero, visualRoot.RenderSize);
rootRect.Intersect(bound);
// Check if currentElement is offscreen. Save time on traversing tree if currentElement is not in root rect
if (rootRect.IsEmpty)
{
return false;
}
while (true)
{
if (currentElement.Visibility != Visibility.Visible || !currentElement.IsHitTestVisible
|| !(currentElement.Opacity > 0))
{
return false;
}
var container = VisualTreeHelper.GetParent(currentElement) as FrameworkElement;
if (container == null)
{
return true;
}
if (container.RenderSize.IsEmpty)
{
// There are some currentElements in UI tree that always return zero size, e.g. ContentControl, etc.
continue;
}
// FIXME we only check if currentElement is visible in parent and parent visible in his parent and so on
// we do not actully check if any part of original currentElement is visible in grandparents
currentElementSize = new Size(currentElement.ActualWidth, currentElement.ActualHeight);
rect = new Rect(zero, currentElementSize);
bound = currentElement.TransformToVisual(container).TransformBounds(rect);
var containerRect = new Rect(zero, container.RenderSize);
containerRect.Intersect(bound);
// Check if currentElement is offscreen
if (containerRect.IsEmpty)
{
return false;
}
currentElement = container;
}
}
示例9: CheckCollision
//check collision with flower and butterfly
public void CheckCollision()
{
//get rects
Rect r1 = new Rect(butterfly.LocationX,butterfly.LocationY,butterfly.ActualWidth,butterfly.ActualHeight);
Rect r2 = new Rect(flower.LocationX, flower.LocationY,flower.ActualWidth,flower.ActualHeight);
//does intersect
r1.Intersect(r2);
if (!r1.IsEmpty) //not empty, intersect happened
{
// remove flower
MyCanvas.Children.Remove(flower);
// add a new flower
AddFlower();
//play sound
mediaElement.Play();
points++;
textBlock.Text = points.ToString();
}
}
示例10: CheckBounds
private bool CheckBounds(Vector2 bounds)
{
foreach(var rect in MapManager.Map)
{
var rectPac = new Rect(x + dx, y + dy, size, size);
rectPac.Intersect(rect);
if(!rectPac.IsEmpty)
return false;
}
return true;
//if (x < -size)
//{
// x = bounds.X;
//}
//else if (x > bounds.X)
//{
// x = 0;
//}
//if (y < -size)
//{
// y = bounds.Y;
//}
//else if (y > bounds.Y)
//{
// y = 0;
//}
}
示例11: RectsOverlap
/// <summary>
/// Checks if two rectangles overlapping
/// </summary>
/// <param name="r1">First rectangle</param>
/// <param name="r2">Second rectangle</param>
/// <returns>True if rectangles overlapping</returns>
private static bool RectsOverlap(Rect r1, Rect r2)
{
r1.Intersect(r2); // Saves intersection rectangle to r1
if (r1.Width > 0 || r1.Height > 0)
return true;
else
return false;
}
示例12: consillionMouseAnother
public bool consillionMouseAnother(Image at)
{
Rect r1 = new Rect(Canvas.GetLeft(Mouse), Canvas.GetTop(Mouse), Mouse.Width, Mouse.Height);
Rect r2 = new Rect(Canvas.GetLeft(at), Canvas.GetTop(at), at.Width, at.Height);
r1.Intersect(r2);
if (!r1.IsEmpty)
{
createCheese();
return true;
}
else
{
return false;
}
}
示例13: consillionMatrix
public bool consillionMatrix(Image a)
{
Rect rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
Rect rt1 = new Rect(Canvas.GetLeft(rec1), Canvas.GetTop(rec1), rec1.Width, rec1.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec2), Canvas.GetTop(rec2), rec2.Width, rec2.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec3), Canvas.GetTop(rec3), rec3.Width, rec3.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec4), Canvas.GetTop(rec4), rec4.Width, rec4.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec5), Canvas.GetTop(rec5), rec5.Width, rec5.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec6), Canvas.GetTop(rec6), rec6.Width, rec6.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec7), Canvas.GetTop(rec7), rec7.Width, rec7.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec8), Canvas.GetTop(rec8), rec8.Width, rec8.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec9), Canvas.GetTop(rec9), rec9.Width, rec9.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec10), Canvas.GetTop(rec10), rec10.Width, rec10.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
else
{
rt = new Rect(Canvas.GetLeft(a), Canvas.GetTop(a), a.Width, a.Height);
rt1 = new Rect(Canvas.GetLeft(rec11), Canvas.GetTop(rec11), rec11.Width, rec11.Height);
rt.Intersect(rt1);
if (!rt.IsEmpty)
{
return true;
}
//.........这里部分代码省略.........