public void InsertRec(RectangleF rec) { if (CompareF.RectangleFVsRectangleF(Boundary, rec) == true) { if (LevelSize < QuadTreeSizes.Size_32) { if (HasChilds == false) { HasChilds = true; LeftTop = new QuadTree(Boundary.Position.X, Boundary.Position.Y, LevelSize + 1); RightTop = new QuadTree(Boundary.Position.X + (LevelSizeInt / 2), Boundary.Position.Y, LevelSize + 1); LeftBottom = new QuadTree(Boundary.Position.X, Boundary.Position.Y + (LevelSizeInt / 2), LevelSize + 1); RightBottom = new QuadTree(Boundary.Position.X + (LevelSizeInt / 2), Boundary.Position.Y + (LevelSizeInt / 2), LevelSize + 1); } LeftTop.InsertRec(rec); RightTop.InsertRec(rec); LeftBottom.InsertRec(rec); RightBottom.InsertRec(rec); } else { Holder = rec; } } }
public string GetStr() { string leftTopStr = LeftTop.GetStr(); string rightBottomStr = RightBottom.GetStr(); string result = $"{TableName}!{leftTopStr}:{rightBottomStr}"; return(result); }
public int CompareTo(Object obj) { var rectangle = (ScreenRectangle)obj; var res = LeftTop.CompareTo(rectangle.LeftTop); if (res != 0) { return(res); } return(RightBottom.CompareTo(rectangle.RightBottom)); }
internal void RelinkNeighbors(Trapezoid newGuy, bool doLinkToLeftNeighbor) { if (doLinkToLeftNeighbor) { LeftTop?.LinkTo(this, newGuy, true); LeftBottom?.LinkTo(this, newGuy, true); } else { RightTop?.LinkTo(this, newGuy, false); RightBottom?.LinkTo(this, newGuy, false); } }
public Rectangle GetScreenRect(ScreenRectangle screenView) { if (Level != screenView.Level) { screenView = new ScreenRectangle( new CoordinateRectangle(screenView.LeftTop, screenView.RightBottom), Level); } var pt1 = LeftTop.GetScreenPoint(screenView); var pt2 = RightBottom.GetScreenPoint(screenView); return(Rectangle.FromLTRB(pt1.X, pt1.Y, pt2.X, pt2.Y)); }
public void Draw() { if (HasChilds == false) { if (LevelSize == QuadTreeSizes.Size_1024) { Game1.SpriteBatchGlobal.Draw(Game1.TestRec, position: Boundary.Position, scale: new Vector2(32), color: Color.Red); } if (LevelSize == QuadTreeSizes.Size_512) { Game1.SpriteBatchGlobal.Draw(Game1.TestRec, position: Boundary.Position, scale: new Vector2(16), color: Color.Orange); } if (LevelSize == QuadTreeSizes.Size_256) { Game1.SpriteBatchGlobal.Draw(Game1.TestRec, position: Boundary.Position, scale: new Vector2(8), color: Color.Yellow); } if (LevelSize == QuadTreeSizes.Size_128) { Game1.SpriteBatchGlobal.Draw(Game1.TestRec, position: Boundary.Position, scale: new Vector2(4), color: Color.Green); } if (LevelSize == QuadTreeSizes.Size_64) { Game1.SpriteBatchGlobal.Draw(Game1.TestRec, position: Boundary.Position, scale: new Vector2(2), color: Color.Blue); } if (LevelSize == QuadTreeSizes.Size_32) { Game1.SpriteBatchGlobal.Draw(Game1.TestRec, position: Boundary.Position, scale: new Vector2(1), color: Color.Black); if (Holder != null) { Game1.SpriteBatchGlobal.Draw(Game1.tileMask, position: Boundary.Position, scale: new Vector2(1), color: Color.White); } } } else { LeftTop.Draw(); RightTop.Draw(); LeftBottom.Draw(); RightBottom.Draw(); } }
//Test public List <Vector2Object> FindIntersectLine(LineSegmentF line) { List <Vector2Object> vectors = new List <Vector2Object>(); if (HasChilds == true) { if (CompareF.LineIntersectionRectangle(LeftBottom.Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(LeftBottom.Boundary, line.End)) { vectors.AddRange(LeftBottom.FindIntersectLine(line)); } if (CompareF.LineIntersectionRectangle(LeftTop.Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(LeftTop.Boundary, line.End)) { vectors.AddRange(LeftTop.FindIntersectLine(line)); } if (CompareF.LineIntersectionRectangle(RightBottom.Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(RightBottom.Boundary, line.End)) { vectors.AddRange(RightBottom.FindIntersectLine(line)); } if (CompareF.LineIntersectionRectangle(RightTop.Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(RightTop.Boundary, line.End)) { vectors.AddRange(RightTop.FindIntersectLine(line)); } return(vectors); } else { if (LevelSize == QuadTreeSizes.Size_32 && Holder != null && (CompareF.LineIntersectionRectangle(Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(Boundary, line.End))) { vectors = CompareF.LineIntersectionRectangle(Boundary, new LineObject(null, line)); return(vectors); } return(vectors); } }
public List <RectangleF> FindIntersectRec(RectangleF rec) { List <RectangleF> rectangles = new List <RectangleF>(); if (HasChilds == true) { if (CompareF.RectangleFVsRectangleF(LeftBottom.Boundary, rec) == true) { rectangles.AddRange(LeftBottom.FindIntersectRec(rec)); } if (CompareF.RectangleFVsRectangleF(LeftTop.Boundary, rec) == true) { rectangles.AddRange(LeftTop.FindIntersectRec(rec)); } if (CompareF.RectangleFVsRectangleF(RightBottom.Boundary, rec) == true) { rectangles.AddRange(RightBottom.FindIntersectRec(rec)); } if (CompareF.RectangleFVsRectangleF(RightTop.Boundary, rec) == true) { rectangles.AddRange(RightTop.FindIntersectRec(rec)); } return(rectangles); } else { if (LevelSize == QuadTreeSizes.Size_32 && Holder != null && CompareF.RectangleFVsRectangleF(rec, Boundary) == true) { rectangles.Add(Holder); return(rectangles); } return(rectangles); } }
public List <RectangleF> FindRecWithVector(Vector2 vec) { List <RectangleF> rectangles = new List <RectangleF>(); if (HasChilds == true) { if (CompareF.RectangleVsVector2NotEq(LeftBottom.Boundary, vec) == true) { rectangles.AddRange(LeftBottom.FindRecWithVector(vec)); } if (CompareF.RectangleVsVector2NotEq(LeftTop.Boundary, vec) == true) { rectangles.AddRange(LeftTop.FindRecWithVector(vec)); } if (CompareF.RectangleVsVector2NotEq(RightBottom.Boundary, vec) == true) { rectangles.AddRange(RightBottom.FindRecWithVector(vec)); } if (CompareF.RectangleVsVector2NotEq(RightTop.Boundary, vec) == true) { rectangles.AddRange(RightTop.FindRecWithVector(vec)); } return(rectangles); } else { if (LevelSize == QuadTreeSizes.Size_32 && Holder != null && CompareF.RectangleVsVector2NotEq(vec, Boundary) == true) { rectangles.Add(Holder); return(rectangles); } return(rectangles); } }
private void BmpForm_MouseMove(object sender, MouseEventArgs e) { if (IsLBtnPress == true) // 鼠标左键按下时发生的事件 { CopyBmp = (Bitmap)OriginBmp.Clone(); CopyBmp.SetResolution(96, 96); CopyGraphics = Graphics.FromImage(CopyBmp); // 把屏幕原始图像复制到CopyBmp上 DrawPen = new Pen(Color.DeepSkyBlue, 2); // 新建画笔DrawPen BackSolidBr = new SolidBrush(Color.FromArgb(130, Color.Gray)); if (IsStart) // 开始截屏 { RecBeginPoint = e.Location; RecWidth = Math.Abs(BeginPoint.X - RecBeginPoint.X); // 截屏区域矩形宽度 RecHeigth = Math.Abs(BeginPoint.Y - RecBeginPoint.Y); // 截屏区域矩形高度 if (BeginPoint.X < RecBeginPoint.X) { RecBeginPoint.X = BeginPoint.X; } if (BeginPoint.Y < RecBeginPoint.Y) { RecBeginPoint.Y = BeginPoint.Y; } } else if (IsMove) // 移动截屏区域 { offsetX = e.X - DownPoint.X; // X方向平移的偏移量 offsetY = e.Y - DownPoint.Y; // Y方向平移的偏移量 RecBeginPoint.Offset(offsetX, offsetY); if (RecBeginPoint.Y <= 0) // 防止移动出屏幕外 { RecBeginPoint.Y = 0; } else if (RecBeginPoint.Y + RecHeigth >= ScreenHeight) { RecBeginPoint.Y = ScreenHeight - RecHeigth; } if (RecBeginPoint.X <= 0) { RecBeginPoint.X = 0; } else if (RecBeginPoint.X + RecWidth >= ScreenWidth) { RecBeginPoint.X = ScreenWidth - RecWidth; } DownPoint = e.Location; } else if (IsResize) // 改变截屏区域大小 { switch (resize_type) { case Resize_Type.LeftTop: // 从左上方拖动 RecWidth = Math.Abs(e.X - RecRightBottom.X); RecHeigth = Math.Abs(e.Y - RecRightBottom.Y); if (e.X > RecRightBottom.X) { RecBeginPoint.X = RecRightBottom.X; } else { RecBeginPoint.X = e.X; } if (e.Y > RecRightBottom.Y) { RecBeginPoint.Y = RecRightBottom.Y; } else { RecBeginPoint.Y = e.Y; } break; case Resize_Type.LeftMid: // 从左中拖动 RecWidth = Math.Abs(e.X - RecRightTop.X); if (e.X > RecRightTop.X) { RecBeginPoint.X = RecRightTop.X; } else { RecBeginPoint.X = e.X; } break; case Resize_Type.LeftBottom: // 从左下方拖动 RecWidth = Math.Abs(e.X - RecRightTop.X); RecHeigth = Math.Abs(e.Y - RecRightTop.Y); if (e.X < RecRightTop.X) { RecBeginPoint.X = e.X; } else { RecBeginPoint.X = RecRightTop.X; } if (e.Y < RecRightTop.Y) { RecBeginPoint.Y = e.Y; } else { RecBeginPoint.Y = RecRightTop.Y; } break; case Resize_Type.MidTop: RecHeigth = Math.Abs(e.Y - RecLeftBottom.Y); if (e.Y < RecLeftBottom.Y) { RecBeginPoint.Y = e.Y; } else { RecBeginPoint.Y = RecLeftBottom.Y; } break; case Resize_Type.MidBottom: RecHeigth = Math.Abs(e.Y - RecLeftTop.Y); if (e.Y > RecLeftTop.Y) { RecBeginPoint = RecLeftTop; } else { RecBeginPoint.Y = e.Y; } break; case Resize_Type.RightTop: RecWidth = Math.Abs(e.X - RecLeftBottom.X); RecHeigth = Math.Abs(e.Y - RecLeftBottom.Y); if (e.X < RecLeftBottom.X) { RecBeginPoint.X = e.X; } else { RecBeginPoint.X = RecLeftBottom.X; } if (e.Y < RecLeftBottom.Y) { RecBeginPoint.Y = e.Y; } else { RecBeginPoint.Y = RecLeftBottom.Y; } break; case Resize_Type.RightMid: RecWidth = Math.Abs(e.X - RecLeftTop.X); if (e.X < RecLeftTop.X) { RecBeginPoint.X = e.X; } else { RecBeginPoint.X = RecLeftTop.X; } break; case Resize_Type.RightBottom: RecWidth = Math.Abs(e.X - RecLeftTop.X); RecHeigth = Math.Abs(e.Y - RecLeftTop.Y); if (e.X < RecLeftTop.X) { RecBeginPoint.X = e.X; } else { RecBeginPoint.X = RecLeftTop.X; } if (e.Y < RecLeftTop.Y) { RecBeginPoint.Y = e.Y; } else { RecBeginPoint.Y = RecLeftTop.Y; } break; } } RefreshRec(); return; } else if (IsLBtnPress == true && this.paintmode == PaintMode.EditMode) { SolidBrush solidBrush = new SolidBrush(Color.Red); lineendpoint = e.Location; RefreshPaintRegion(); } // 鼠标移动时没有任何键按下时发生的事件 CurrentPoint = e.Location; if (LeftTop.Contains(CurrentPoint) || RightBottom.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeNWSE; } else if (RightTop.Contains(CurrentPoint) || LeftBottom.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeNESW; } else if (MidTop.Contains(CurrentPoint) || MidBottom.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeNS; } else if (LeftMid.Contains(CurrentPoint) || RightMid.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeWE; } else if (CapRec.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeAll; } else { this.Cursor = Cursors.Arrow; } }
private void BmpForm_MouseDown(object sender, MouseEventArgs e) { if (this.paintmode == PaintMode.EditMode) { linebeginpoint = e.Location; IsLBtnPress = true; Graphics grah = this.CreateGraphics(); grah.DrawLine(new Pen(new SolidBrush(Color.Red)), new Point(0, 0), new Point(500, 500)); } else if (this.paintmode == PaintMode.none) { if (e.Button == MouseButtons.Left) // 左键被按下时 { this.toolStrip1.Hide(); IsLBtnPress = true; CurrentPoint = e.Location; Rectangle NewCapRec = new Rectangle(new Point(CapRec.X + 5, CapRec.Y + 5), new Size(CapRec.Width - 10, CapRec.Height - 10)); RecRightBottom = new Point(RecBeginPoint.X + RecWidth, RecBeginPoint.Y + RecHeigth); RecRightTop = new Point(RecBeginPoint.X + RecWidth, RecBeginPoint.Y); RecLeftTop = RecBeginPoint; RecLeftBottom = new Point(RecBeginPoint.X, RecBeginPoint.Y + RecHeigth); if (NewCapRec.Contains(CurrentPoint)) // 左键按下时,如果落在矩形区域内,则表示要移动已经选择了的矩形 { this.Cursor = Cursors.SizeAll; IsMove = true; DownPoint = e.Location; } else if (LeftTop.Contains(CurrentPoint)) // 左键按下时,如果落在八个小矩形对应的范围内,则表示择了的矩形 { this.Cursor = Cursors.SizeNWSE; IsResize = true; resize_type = Resize_Type.LeftTop; } else if (LeftMid.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeWE; IsResize = true; resize_type = Resize_Type.LeftMid; } else if (LeftBottom.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeNESW; IsResize = true; resize_type = Resize_Type.LeftBottom; } else if (MidTop.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeNS; IsResize = true; resize_type = Resize_Type.MidTop; } else if (MidBottom.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeNS; IsResize = true; resize_type = Resize_Type.MidBottom; } else if (RightTop.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeNESW; IsResize = true; resize_type = Resize_Type.RightTop; } else if (RightMid.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeWE; IsResize = true; resize_type = Resize_Type.RightMid; } else if (RightBottom.Contains(CurrentPoint)) { this.Cursor = Cursors.SizeNWSE; IsResize = true; resize_type = Resize_Type.RightBottom; } else if (!CapRec.Contains(CurrentPoint)) { this.Cursor = Cursors.Cross; IsStart = true; BeginPoint = e.Location; } } } }
private void DownLoad() { DownLoadCount = 0; DownLoadErrorCount = 0; DownLoadedCount = 0; Task.Run(() => { try { for (var zoomindex = Downloadmin; zoomindex <= Downloadmax; zoomindex++) { _Level = zoomindex; var lefttopPosition = GetPicLocation(new Position(LeftTop.Split(',')), true); var leftbottomPosition = GetPicLocation(new Position(LeftBottom.Split(',')), true); var righttopPosition = GetPicLocation(new Position(RightTop.Split(',')), true); var rightbottomPosition = GetPicLocation(new Position(RightBottom.Split(',')), true); var xCount = righttopPosition.Item1 - lefttopPosition.Item1; var yCount = leftbottomPosition.Item2 - lefttopPosition.Item2; DownLoadCount += xCount * yCount == 0 ? 1 : xCount * yCount; if (xCount * yCount == 0) { xCount = 1; yCount = 1; } //new ParallelOptions() { MaxDegreeOfParallelism = 8 } Parallel.For(0, xCount, (i) => { Parallel.For(0, yCount, async(index) => { var filename = string.Empty; var imageurl = GetUrl(_Level, lefttopPosition.Item1 + i, lefttopPosition.Item2 + index, out filename); var result = true; if (!System.IO.File.Exists(filename)) { result = await Utils.DownLoadFile(imageurl, filename); } lock (lockobj) { if (result) { DownLoadedCount += 1; } else { DownLoadErrorCount += 1; } } }); }); } } catch (Exception ex) { Log.Error(ex); } }); }
void Update() { if (alive) { timeLeft -= Time.deltaTime; if (timeLeft < 0) { if (Input.touchCount == 1) // user is touching the screen with a single touch { Touch touch = Input.GetTouch(0); // get the touch if (touch.phase == TouchPhase.Began) //check for the first touch { fp = touch.position; lp = touch.position; } else if (touch.phase == TouchPhase.Moved) // update the last position based on where they moved { lp = touch.position; } else if (touch.phase == TouchPhase.Ended) //check if the finger is removed from the screen { lp = touch.position; //last touch position. Ommitted if you use list //Check if drag distance is greater than 15% of the screen height if (Mathf.Abs(lp.x - fp.x) > dragDistance || Mathf.Abs(lp.y - fp.y) > dragDistance) {//It's a drag //check if the drag is vertical or horizontal if ((lp.x - fp.x) > 0 && (lp.y - fp.y) > 0) { if (transform.position.x < xR)//Right swipe { this.transform.Translate(1 * movementScale, 0, 0); } } if ((lp.x - fp.x) < 0 && (lp.y - fp.y) > 0) { //lewo if (transform.position.y < yT) // Debug.Log("Up Swipe"); { this.transform.Translate(0, 1 * movementScale, 0); } } if ((lp.x - fp.x) > 0 && (lp.y - fp.y) < 0) { //gora if (transform.position.y > yB) // Debug.Log("Down Swipe"); { this.transform.Translate(0, -1 * movementScale, 0); } } if ((lp.x - fp.x) < 0 && (lp.y - fp.y) < 0) { //dol if (transform.position.x > xL) // Debug.Log("Left Swipe"); { this.transform.Translate(-1 * movementScale, 0, 0); } } } else { //It's a tap as the drag distance is less than 20% of the screen height //Here we can make tap.postion as desiredPostion to move object rounded to the nearest block //Debug.Log("Tap"); } } } } foreach (GameObject red in CubeRed) { if (red.transform.position.x == transform.position.x && red.transform.position.y == transform.position.y) { Bomb(); alive = false; } } if (transform.position.y == yT && transform.position.x == xR) { RightBottom.GetComponent <FinalGoindUp>().Colour(); RightBottom.GetComponent <FinalGoindUp>().Metod(); Up.GetComponent <MoveGoingUp>().Metod(); Invoke("next", 2); } } }