本文整理汇总了C#中Rect.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Intersects方法的具体用法?C# Rect.Intersects怎么用?C# Rect.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rect
的用法示例。
在下文中一共展示了Rect.Intersects方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRoomsPhase
/**
* Phases
*/
public void AddRoomsPhase(int frames)
{
int room = this.CurrentPhase.FramesElapsed;
int finalRoomForStep = room + frames;
if (finalRoomForStep > this.NumberOfRooms)
finalRoomForStep = this.NumberOfRooms;
while (room < finalRoomForStep && _retries < this.MaxRetries)
{
int w = Random.Range(this.RoomMinSize, this.RoomMaxSize + 1);
int h = Random.Range(this.RoomMinSize, this.RoomMaxSize + 1);
int x = Random.Range(0, this.Map.Width - w);
int y = Random.Range(0, this.Map.Height - h);
Rect newRoom = new Rect(x, y, w, h);
bool failed = false;
foreach (Rect otherRoom in this.Rooms)
{
if (newRoom.Intersects(otherRoom))
{
failed = true;
++_retries;
break;
}
}
if (!failed)
{
createRoom(newRoom);
if (this.Rooms.Count > 0) // First room has no previous room to connect to
{
Vector2 prevRoomCenter = this.Rooms[this.Rooms.Count - 1].center;
List<LevelGenMap.Coordinate> corridor = new List<LevelGenMap.Coordinate>();
if (Random.Range(0, 2) == 1)
{
createHTunnel((int)prevRoomCenter.x, (int)newRoom.center.x, (int)prevRoomCenter.y, corridor);
createVTunnel((int)prevRoomCenter.y, (int)newRoom.center.y, (int)newRoom.center.x, corridor);
}
else
{
createVTunnel((int)prevRoomCenter.y, (int)newRoom.center.y, (int)newRoom.center.x, corridor);
createHTunnel((int)prevRoomCenter.x, (int)newRoom.center.x, (int)prevRoomCenter.y, corridor);
}
_corridorTiles.Add(corridor);
}
this.Rooms.Add(newRoom);
++room;
}
}
if (finalRoomForStep == this.NumberOfRooms)
this.NextPhase();
}
示例2: GenerateMap
public void GenerateMap()
{
for(int y=0;y<MapHeight;y++){
for(int x=0;x<MapWidth;x++){
CurrentMap[x,y]= 1;
}
}
Rect last_room = new Rect();
int room = 0;
int retries = 0;
_rooms.Clear();
while ((room < numberOfRooms) && (retries < maxRetries)) {
int w = Random.Range(roomMinSize,roomMaxSize+1);
int h = Random.Range(roomMinSize,roomMaxSize+1);
int x = Random.Range(0,MapWidth - w - 1);
int y = Random.Range(0,MapHeight - h - 1);
Rect new_room = new Rect(x,y,w,h);
bool failed = false;
foreach(Rect other_room in _rooms){
if(new_room.Intersects(other_room)){
failed = true;
retries++;
break;
}
}
if(!failed){
CreateRoom(new_room);
if(_rooms.Count == 0){//First room has no previous room to connect to
}else{
Vector2 prev_room_center = _rooms[_rooms.Count-1].center;
if(Random.Range(0,2) == 1){
CreateHTunnel((int)prev_room_center.x,(int)new_room.center.x,(int)prev_room_center.y);
CreateVTunnel((int)prev_room_center.y,(int)new_room.center.y,(int)new_room.center.x);
}else{
CreateVTunnel((int)prev_room_center.y,(int)new_room.center.y,(int)new_room.center.x);
CreateHTunnel((int)prev_room_center.x,(int)new_room.center.x,(int)prev_room_center.y);
}
}
_rooms.Add(new_room);
last_room = new_room;
room++;
}
}
}
示例3: PickRenderersIn
/// <summary>
/// Picks all <see cref="Duality.ICmpRenderer">ICmpRenderers</see> contained within the specified
/// rectangular area.
/// </summary>
/// <param name="x">x-Coordinate of the Rect.</param>
/// <param name="y">y-Coordinate of the Rect.</param>
/// <param name="w">Width of the Rect.</param>
/// <param name="h">Height of the Rect.</param>
/// <returns>A set of all <see cref="Duality.ICmpRenderer">ICmpRenderers</see> that have been picked.</returns>
public HashSet<ICmpRenderer> PickRenderersIn(int x, int y, int w, int h)
{
Rect dstRect = new Rect(x, y, w, h);
Rect srcRect = new Rect(DualityApp.TargetResolution);
if (!dstRect.Intersects(srcRect)) return new HashSet<ICmpRenderer>();
dstRect = dstRect.Intersection(srcRect);
this.RenderPickingMap();
x = Math.Max((int)dstRect.X, 0);
y = Math.Max((int)dstRect.Y, 0);
w = Math.Min((int)dstRect.W, this.pickingTex.PixelWidth - x);
h = Math.Min((int)dstRect.H, this.pickingTex.PixelHeight - y);
HashSet<ICmpRenderer> result = new HashSet<ICmpRenderer>();
int rendererIdLast = 0;
for (int j = 0; j < h; ++j)
{
int offset = 4 * (x + (y + j) * this.pickingTex.PixelWidth);
for (int i = 0; i < w; ++i)
{
int rendererId = (this.pickingBuffer[offset] << 16) |
(this.pickingBuffer[offset + 1] << 8) |
(this.pickingBuffer[offset + 2] << 0);
if (rendererId != rendererIdLast)
{
if (rendererId - 1 > this.pickingMap.Count)
Log.Core.WriteWarning("Unexpected picking result: {0}", ColorRgba.FromIntArgb(rendererId));
else if (rendererId != 0 && !(this.pickingMap[rendererId - 1] as Component).Disposed)
result.Add(this.pickingMap[rendererId - 1]);
rendererIdLast = rendererId;
}
offset += 4;
}
}
return result;
}
示例4: PickRenderersIn
/// <summary>
/// Picks all <see cref="Duality.ICmpRenderer">ICmpRenderers</see> contained within the specified
/// rectangular area.
/// The resulting information is only accurate if <see cref="RenderPickingMap"/> has been called this frame.
/// </summary>
/// <param name="x">x-Coordinate of the Rect.</param>
/// <param name="y">y-Coordinate of the Rect.</param>
/// <param name="w">Width of the Rect.</param>
/// <param name="h">Height of the Rect.</param>
/// <returns>A set of all <see cref="Duality.ICmpRenderer">ICmpRenderers</see> that have been picked.</returns>
public IEnumerable<ICmpRenderer> PickRenderersIn(int x, int y, int w, int h)
{
if (this.pickingBuffer == null)
return Enumerable.Empty<ICmpRenderer>();
if ((x + w) + (y + h) * this.pickingTex.PixelWidth >= this.pickingBuffer.Length)
return Enumerable.Empty<ICmpRenderer>();
Rect dstRect = new Rect(x, y, w, h);
Rect availRect = new Rect(this.pickingTex.PixelWidth, this.pickingTex.PixelHeight);
if (!dstRect.Intersects(availRect)) return Enumerable.Empty<ICmpRenderer>();
dstRect = dstRect.Intersection(availRect);
x = Math.Max((int)dstRect.X, 0);
y = Math.Max((int)dstRect.Y, 0);
w = Math.Min((int)dstRect.W, this.pickingTex.PixelWidth - x);
h = Math.Min((int)dstRect.H, this.pickingTex.PixelHeight - y);
HashSet<ICmpRenderer> result = new HashSet<ICmpRenderer>();
int rendererIdLast = 0;
for (int j = 0; j < h; ++j)
{
int offset = 4 * (x + (y + j) * this.pickingTex.PixelWidth);
for (int i = 0; i < w; ++i)
{
int rendererId =
(this.pickingBuffer[offset] << 16) |
(this.pickingBuffer[offset + 1] << 8) |
(this.pickingBuffer[offset + 2] << 0);
if (rendererId != rendererIdLast)
{
if (rendererId - 1 > this.pickingMap.Count)
Log.Core.WriteWarning("Unexpected picking result: {0}", ColorRgba.FromIntArgb(rendererId));
else if (rendererId != 0 && !(this.pickingMap[rendererId - 1] as Component).Disposed)
result.Add(this.pickingMap[rendererId - 1]);
rendererIdLast = rendererId;
}
offset += 4;
}
}
return result;
}
示例5: processRenderData
private bool processRenderData( ref dfRenderData buffer, dfRenderData controlData, ref Bounds bounds, ref Rect screenRect, uint checksum, dfTriangleClippingRegion clipInfo, ref bool wasClipped )
{
wasClipped = false;
// This shouldn't happen in practice, but need to make certain
if( controlData == null || controlData.Material == null || !controlData.IsValid() )
return false;
// A new draw call is needed every time the current Material, Texture, or Shader
// changes. If the control returned a buffer that is not empty and uses a
// different Material, need to grab a new draw call buffer from the object pool.
bool needNewDrawcall = false;
if( buffer == null )
{
needNewDrawcall = true;
}
else
{
if( !Material.Equals( controlData.Material, buffer.Material ) )
{
needNewDrawcall = true;
}
else if( !textureEqual( controlData.Material.mainTexture, buffer.Material.mainTexture ) )
{
needNewDrawcall = true;
}
else if( !shaderEqual( buffer.Shader, controlData.Shader ) )
{
needNewDrawcall = true;
}
else if( !this.clipInfo.IsEmpty && drawCallBuffers.Count == 1 )
{
needNewDrawcall = true;
}
}
if( needNewDrawcall )
{
buffer = getDrawCallBuffer( controlData.Material );
buffer.Material = controlData.Material;
buffer.Material.mainTexture = controlData.Material.mainTexture;
buffer.Material.shader = controlData.Shader ?? controlData.Material.shader;
}
if( !Application.isPlaying || clipType == dfClippingMethod.Software )
{
// Ensure that the control's render data is properly clipped to the
// current clipping region
if( clipInfo.PerformClipping( buffer, ref bounds, checksum, controlData ) )
{
return true;
}
// If PerformClipping() returns FALSE, then the control was outside of
// the active clipping region
wasClipped = true;
}
else
{
if( clipRect.IsEmpty() || screenRect.Intersects( clipRect ) )
{
buffer.Merge( controlData );
}
else
{
// Control was not inside of the active clipping rectangle
wasClipped = true;
}
}
return false;
}
示例6: IntersectionCheking
public void IntersectionCheking(int x, int y, int w, int h)
{
Rect rect = new Rect(x, y, w, h);
// Intersection with self and offset-variants
Assert.IsTrue(rect.Intersects(rect));
Assert.IsTrue(rect.Intersects(rect.Offset(1, 0)));
Assert.IsTrue(rect.Intersects(rect.Offset(-1, 0)));
Assert.IsTrue(rect.Intersects(rect.Offset(0, 1)));
Assert.IsTrue(rect.Intersects(rect.Offset(0, -1)));
// Intersection with crossing rect: Horizontal
Assert.IsTrue(rect.Intersects(rect.MinX - 1, rect.MinY, rect.MaxX - rect.MinX + 2, rect.MaxY - rect.MinY));
Assert.IsTrue(rect.Intersects(rect.MinX - 1, rect.MinY - 1, rect.MaxX - rect.MinX + 2, 2));
Assert.IsTrue(rect.Intersects(rect.MinX - 1, rect.MaxY - 1, rect.MaxX - rect.MinX + 2, 2));
// Intersection with crossing rect: Vertical
Assert.IsTrue(rect.Intersects(rect.MinX, rect.MinY - 1, rect.MaxX - rect.MinX, rect.MaxY - rect.MinY + 2));
Assert.IsTrue(rect.Intersects(rect.MinX - 1, rect.MinY - 1, 2, rect.MaxY - rect.MinY + 2));
Assert.IsTrue(rect.Intersects(rect.MaxX - 1, rect.MinY - 1, 2, rect.MaxY - rect.MinY + 2));
// Intersection with corners
Assert.IsTrue(rect.Intersects(rect.TopLeft.X - 1, rect.TopLeft.Y - 1, 2, 2));
Assert.IsTrue(rect.Intersects(rect.TopRight.X - 1, rect.TopRight.Y - 1, 2, 2));
Assert.IsTrue(rect.Intersects(rect.BottomLeft.X - 1, rect.BottomLeft.Y - 1, 2, 2));
Assert.IsTrue(rect.Intersects(rect.BottomRight.X - 1, rect.BottomRight.Y - 1, 2, 2));
// Non-intersection
Assert.IsFalse(rect.Intersects(rect.MinX - 2, rect.MinY, 1, rect.MaxY - rect.MinY));
Assert.IsFalse(rect.Intersects(rect.MaxX + 2, rect.MinY, 1, rect.MaxY - rect.MinY));
Assert.IsFalse(rect.Intersects(rect.MinX, rect.MinY - 2, rect.MaxX - rect.MinX, 1));
Assert.IsFalse(rect.Intersects(rect.MinX, rect.MaxY + 2, rect.MaxX - rect.MinX, 1));
// Non-intersection with corners
Assert.IsFalse(rect.Intersects(rect.TopLeft.X - 2, rect.TopLeft.Y - 2, 1, 1));
Assert.IsFalse(rect.Intersects(rect.TopRight.X + 2, rect.TopRight.Y - 2, 1, 1));
Assert.IsFalse(rect.Intersects(rect.BottomLeft.X - 2, rect.BottomLeft.Y + 2, 1, 1));
Assert.IsFalse(rect.Intersects(rect.BottomRight.X + 2, rect.BottomRight.Y + 2, 1, 1));
}
示例7: IntersectTest2
public void IntersectTest2()
{
double minValue = -100000;
double maxValue = 100000;
Action test = () => {
var rect1 = new Rect (TestHelper.NextDouble(minValue),
TestHelper.NextDouble(minValue),
TestHelper.NextDouble(maxValue),
TestHelper.NextDouble(maxValue));
var rect2 = new Rect (TestHelper.NextDouble(minValue),
TestHelper.NextDouble(minValue),
TestHelper.NextDouble(maxValue),
TestHelper.NextDouble(maxValue));
var nrect3 = rect1.Intersects (rect2);
if(nrect3.HasValue){
var rect3 = nrect3.Value;
Assert.GreaterOrEqual (rect3.Left + 1e-5 ,rect1.Left);
Assert.LessOrEqual (rect3.Right,rect1.Right + 1e-5);
Assert.GreaterOrEqual (rect3.Top + 1e-5,rect1.Top);
Assert.LessOrEqual (rect3.Bottom,rect1.Bottom + 1e-5);
Assert.GreaterOrEqual (rect3.Left + 1e-5 ,rect2.Left);
Assert.LessOrEqual (rect3.Right,rect2.Right + 1e-5);
Assert.GreaterOrEqual (rect3.Top + 1e-5,rect2.Top);
Assert.LessOrEqual (rect3.Bottom,rect2.Bottom + 1e-5);
}
};
test.RunBatch (batchCount);
}
示例8: IntersectTest1
public void IntersectTest1()
{
var rect1 = new Rect (0, 0, 100, 100);
var rect2 = new Rect (50, 50, 100, 100);
var rect3 = rect1.Intersects (rect2).Value;
Assert.AreEqual (50, rect3.X);
Assert.AreEqual (50, rect3.Y);
Assert.AreEqual (50, rect3.Width);
Assert.AreEqual (50, rect3.Height);
}