/// <summary> /// Return true if there are any nodes in this Quadrant that intersect the given bounds. /// </summary> /// <param name="bounds">The bounds to test</param> /// <returns>boolean</returns> internal Boolean HasIntersectingNodes(Rect bounds) { if (bounds.IsEmpty) { return(false); } Double w = Bounds.Width / 2; Double h = Bounds.Height / 2; // assumption that the Rect struct is almost as fast as doing the operations // manually since Rect is a value type. Rect topLeft = new Rect(Bounds.Left, Bounds.Top, w, h); Rect topRight = new Rect(Bounds.Left + w, Bounds.Top, w, h); Rect bottomLeft = new Rect(Bounds.Left, Bounds.Top + h, w, h); Rect bottomRight = new Rect(Bounds.Left + w, Bounds.Top + h, w, h); Boolean found = false; // See if any child quadrants completely contain this node. if (topLeft.IntersectsWith(bounds) && TopLeft != null) { found = TopLeft.HasIntersectingNodes(bounds); } if (!found && topRight.IntersectsWith(bounds) && TopRight != null) { found = TopRight.HasIntersectingNodes(bounds); } if (!found && bottomLeft.IntersectsWith(bounds) && BottomLeft != null) { found = BottomLeft.HasIntersectingNodes(bounds); } if (!found && bottomRight.IntersectsWith(bounds) && BottomRight != null) { found = BottomRight.HasIntersectingNodes(bounds); } if (!found) { found = HasIntersectingNodes(Nodes, bounds); } return(found); }
public void Redraw() { if (_cropTool.Height <= 0 && _cropTool.Width <= 0) { ShowThumbs(false); return; } BottomMiddle.Redraw(_cropTool.TopLeftX + _cropTool.Width / 2, _cropTool.TopLeftY + _cropTool.Height); LeftMiddle.Redraw(_cropTool.TopLeftX, _cropTool.TopLeftY + _cropTool.Height / 2); TopMiddle.Redraw(_cropTool.TopLeftX + _cropTool.Width / 2, _cropTool.TopLeftY); RightMiddle.Redraw(_cropTool.TopLeftX + _cropTool.Width, _cropTool.TopLeftY + _cropTool.Height / 2); TopLeft.Redraw(_cropTool.TopLeftX, _cropTool.TopLeftY); TopRight.Redraw(_cropTool.TopLeftX + _cropTool.Width, _cropTool.TopLeftY); BottomLeft.Redraw(_cropTool.TopLeftX, _cropTool.TopLeftY + _cropTool.Height); BottomRight.Redraw(_cropTool.TopLeftX + _cropTool.Width, _cropTool.TopLeftY + _cropTool.Height); ShowThumbs(true); }
protected override void WndProc(ref Message message) { base.WndProc(ref message); if (message.Msg == 0x84) { var cp = MousePosition; var cursor = this.PointToClient(cp); if (TopLeft.Contains(cursor)) { message.Result = (IntPtr)HTTOPLEFT; } else if (TopRight.Contains(cursor)) { message.Result = (IntPtr)HTTOPRIGHT; } else if (BottomLeft.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMLEFT; } else if (BottomRight.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMRIGHT; } else if (TopBorder.Contains(cursor)) { message.Result = (IntPtr)HTTOP; } else if (LeftBorder.Contains(cursor)) { message.Result = (IntPtr)HTLEFT; } else if (RightBorder.Contains(cursor)) { message.Result = (IntPtr)HTRIGHT; } else if (BottomBorder.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOM; } } }
/// <summary> /// Retrieves the items that intersect with the given bounds. /// </summary> public IEnumerable <T> GetItemsIntersecting(Rect bounds) { if (TopRight?.Extent.IntersectsWith(bounds) ?? false) { foreach (var item in TopRight.GetItemsIntersecting(bounds)) { yield return(item); } } if (TopLeft?.Extent.IntersectsWith(bounds) ?? false) { foreach (var item in TopLeft.GetItemsIntersecting(bounds)) { yield return(item); } } if (BottomRight?.Extent.IntersectsWith(bounds) ?? false) { foreach (var item in BottomRight.GetItemsIntersecting(bounds)) { yield return(item); } } if (BottomLeft?.Extent.IntersectsWith(bounds) ?? false) { foreach (var item in BottomLeft.GetItemsIntersecting(bounds)) { yield return(item); } } //add all the items in this quadrant that intersect the given bounds foreach (var item in ItemsInQuadrant) { if (item.Bounds.IntersectsWith(bounds)) { yield return(item); } } }
protected override void WndProc(ref Message message) { base.WndProc(ref message); if (message.Msg == 0x84) // WM_NCHITTEST { var cursor = this.PointToClient(Cursor.Position); if (TopLeft.Contains(cursor)) { message.Result = (IntPtr)HTTOPLEFT; } else if (TopRight.Contains(cursor)) { message.Result = (IntPtr)HTTOPRIGHT; } else if (BottomLeft.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMLEFT; } else if (BottomRight.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMRIGHT; } else if (Top.Contains(cursor)) { message.Result = (IntPtr)HTTOP; } else if (Left.Contains(cursor)) { message.Result = (IntPtr)HTLEFT; } else if (Right.Contains(cursor)) { message.Result = (IntPtr)HTRIGHT; } else if (Bottom.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOM; } } }
/// <summary> /// Statictial information for rendering use. /// </summary> /// <param name="c"></param> public void ShowQuadTree(Canvas c) { Rectangle r = new Rectangle { Width = Bounds.Width, Height = Bounds.Height }; Canvas.SetLeft(r, Bounds.Left); Canvas.SetTop(r, Bounds.Top); r.Stroke = Brushes.DarkRed; r.StrokeThickness = 1; r.StrokeDashArray = new DoubleCollection(new Double[] { 2.0, 3.0 }); c.Children.Add(r); TopLeft?.ShowQuadTree(c); TopRight?.ShowQuadTree(c); BottomLeft?.ShowQuadTree(c); BottomRight?.ShowQuadTree(c); }
public IEnumerable <Vec> Trace() { if ((Width > 1) && (Height > 1)) { // trace all four sides foreach (Vec top in Row(TopLeft, Width - 1)) { yield return(top); } foreach (Vec right in Column(TopRight.OffsetX(-1), Height - 1)) { yield return(right); } foreach (Vec bottom in Row(Width - 1)) { yield return(BottomRight.Offset(-1, -1) - bottom); } foreach (Vec left in Column(Height - 1)) { yield return(BottomLeft.OffsetY(-1) - left); } } else if ((Width > 1) && (Height == 1)) { // a single row foreach (Vec pos in Row(TopLeft, Width)) { yield return(pos); } } else if ((Height >= 1) && (Width == 1)) { // a single column, or one unit foreach (Vec pos in Column(TopLeft, Height)) { yield return(pos); } } // otherwise, the rect doesn't have a positive size, so there's nothing to trace }
/// <summary> /// Returns all nodes in this quadrant that intersect the given bounds. /// The nodes are returned in pretty much random order as far as the caller is concerned. /// </summary> /// <param name="nodes">List of nodes found in the given bounds</param> /// <param name="bounds">The bounds that contains the nodes you want returned</param> public void GetIntersectingNodes(IList <IMesQuadNode <T> > nodes, RectangleF bounds) { if (bounds.IsEmpty) { return; } Single w = Bounds.Width / 2; Single h = Bounds.Height / 2; // assumption that the Rect struct is almost as fast as doing the operations // manually since Rect is a value type. RectangleF topLeft = new RectangleF(Bounds.Left, Bounds.Top, w, h); RectangleF topRight = new RectangleF(Bounds.Left + w, Bounds.Top, w, h); RectangleF bottomLeft = new RectangleF(Bounds.Left, Bounds.Top + h, w, h); RectangleF bottomRight = new RectangleF(Bounds.Left + w, Bounds.Top + h, w, h); // See if any child quadrants completely contain this node. if (topLeft.IntersectsWith(bounds) && TopLeft != null) { TopLeft.GetIntersectingNodes(nodes, bounds); } if (topRight.IntersectsWith(bounds) && TopRight != null) { TopRight.GetIntersectingNodes(nodes, bounds); } if (bottomLeft.IntersectsWith(bounds) && BottomLeft != null) { BottomLeft.GetIntersectingNodes(nodes, bounds); } if (bottomRight.IntersectsWith(bounds) && BottomRight != null) { BottomRight.GetIntersectingNodes(nodes, bounds); } GetIntersectingNodes(Nodes, nodes, bounds); }
void GetAgentsInChildrenAll(List <Agent> buffer) { if (TopRight.HasChildren()) { TopRight.GetAgentsInChildrenAll(buffer); } else { buffer.AddRange(TopRight.Agents); } if (TopLeft.HasChildren()) { TopLeft.GetAgentsInChildrenAll(buffer); } else { buffer.AddRange(TopLeft.Agents); } if (BottomRight.HasChildren()) { BottomRight.GetAgentsInChildrenAll(buffer); } else { buffer.AddRange(BottomRight.Agents); } if (BottomLeft.HasChildren()) { BottomLeft.GetAgentsInChildrenAll(buffer); } else { buffer.AddRange(BottomLeft.Agents); } }
/// <summary> /// Retrieves a list of Rects that make up this quadrant and the quadrants beneath it. /// Used when debugging to draw quadrants to a canvas. /// </summary> /// <param name="rects"></param> public IEnumerable <Rect> GetQuadrantRects() { yield return(Extent); if (TopLeft != null) { foreach (var rect in TopLeft.GetQuadrantRects()) { yield return(rect); } } if (TopRight != null) { foreach (var rect in TopRight.GetQuadrantRects()) { yield return(rect); } } if (BottomLeft != null) { foreach (var rect in BottomLeft.GetQuadrantRects()) { yield return(rect); } } if (BottomRight != null) { foreach (var rect in BottomRight.GetQuadrantRects()) { yield return(rect); } } }
/// <summary> /// Retrieves the <see cref="Quadrant"/> containing the given bounds /// </summary> public Quadrant GetContainingQuadrant(Rect bounds) { if (TopRight?.Extent.Contains(bounds) ?? false) { return(TopRight.GetContainingQuadrant(bounds)); } else if (TopLeft?.Extent.Contains(bounds) ?? false) { return(TopLeft.GetContainingQuadrant(bounds)); } else if (BottomRight?.Extent.Contains(bounds) ?? false) { return(BottomRight.GetContainingQuadrant(bounds)); } else if (BottomLeft?.Extent.Contains(bounds) ?? false) { return(BottomLeft.GetContainingQuadrant(bounds)); } else if (Extent.Contains(bounds)) { return(this); } return(null); }
public float GetHeight() { return(TopRight.Distance(BottomRight)); }
public override int GetHashCode() { return(TopLeft.GetHashCode() ^ TopRight.GetHashCode() ^ BottomLeft.GetHashCode() ^ BottomRight.GetHashCode()); }
public void Draw(SpriteBatch spr, Rectangle bounds, Color color) { if (spr == null) { throw new ArgumentNullException(nameof(spr)); } Point pos = bounds.Location; Point size = bounds.Size; if (size.X < 0) { size.X = 0; } if (size.Y < 0) { size.Y = 0; } int minWidth = TopLeft.Region.Width + TopRight.Region.Width; int innerWidth = size.X - minWidth; if (innerWidth < 0) { innerWidth = 0; } int minHeight = TopLeft.Region.Height + BottomLeft.Region.Height; int innerHeight = size.Y - minHeight; if (innerHeight < 0) { innerHeight = 0; } // Top left. TopLeft.Draw(spr, pos, color); //// Top center. if (innerWidth != 0) { TopCenter.Draw(spr, new Rectangle(pos + new Point(TopLeft.Region.Width, 0), new Point(innerWidth, TopCenter.Region.Height)), color); } //// Top right. TopRight.Draw(spr, pos + new Point(TopLeft.Region.Width + innerWidth, 0), color); // Center left. if (innerHeight != 0) { CenterLeft.Draw(spr, new Rectangle(pos + new Point(0, TopLeft.Region.Height), new Point(TopLeft.Region.Width, innerHeight)), color); } // Center. if (innerWidth != 0 && innerHeight != 0) { Center.Draw(spr, new Rectangle(pos + TopLeft.Region.Size, new Point(innerWidth, innerHeight)), color); } // Center right. if (innerHeight != 0) { CenterRight.Draw(spr, new Rectangle(pos + new Point(TopLeft.Region.Width + innerWidth, TopLeft.Region.Height), new Point(CenterRight.Region.Width, innerHeight)), color); } // Bottom left. BottomLeft.Draw(spr, pos + new Point(0, TopLeft.Region.Height + innerHeight), color); // Bottom center. if (innerWidth != 0) { BottomCenter.Draw(spr, new Rectangle(pos + new Point(TopLeft.Region.Width, TopLeft.Region.Height + innerHeight), new Point(innerWidth, BottomCenter.Region.Height)), color); } // Bottom right. BottomRight.Draw(spr, pos + new Point(innerWidth, innerHeight) + TopLeft.Region.Size, color); }
public override int GetHashCode() => (BottomLeft.GetHashCode() * 397) ^ TopRight.GetHashCode();
protected override void WndProc(ref Message message) { try { if (message.Msg == WM_SYSCOMMAND && (message.WParam.ToInt32() & 0xfff0) == SC_SIZE) { if (FormResizable) { GetSystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, out int isDragFullWindow, 0); if (isDragFullWindow != 0) { SetSystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 0, 0, 0); } base.WndProc(ref message); if (isDragFullWindow != 0) { SetSystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 1, 0, 0); } } } else { if (message.Msg == 0x84) // WM_NCHITTEST { if (FormResizable) { // Always add grid styles regardless of border type var cursor = PointToClient(Cursor.Position); if (TopLeft.Contains(cursor)) { message.Result = (IntPtr)HTTOPLEFT; } else if (TopRight.Contains(cursor)) { message.Result = (IntPtr)HTTOPRIGHT; } else if (BottomLeft.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMLEFT; } else if (BottomRight.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMRIGHT; } else if (Top.Contains(cursor)) { message.Result = (IntPtr)HTTOP; } else if (Left.Contains(cursor)) { message.Result = (IntPtr)HTLEFT; } else if (Right.Contains(cursor)) { message.Result = (IntPtr)HTRIGHT; } else if (Bottom.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOM; } } else { Cursor.Current = Cursors.Arrow; message.Result = (IntPtr)1; // Processed6 return; } } base.WndProc(ref message); } } catch (Exception e) { MessageBox.Show( "The application encountered a fatal error and must be restarted. Please contact the service desk with this message: " + e.Message, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Creates a new <see cref="PdfRectangle"/> which is the current rectangle moved in the x and y directions relative to its current position by a value. /// </summary> /// <param name="dx">The distance to move the rectangle in the x direction relative to its current location.</param> /// <param name="dy">The distance to move the rectangle in the y direction relative to its current location.</param> /// <returns>A new rectangle shifted on the y axis by the given delta value.</returns> public PdfRectangle Translate(double dx, double dy) { return(new PdfRectangle(TopLeft.Translate(dx, dy), TopRight.Translate(dx, dy), BottomLeft.Translate(dx, dy), BottomRight.Translate(dx, dy))); }
protected override void WndProc(ref Message message) { try { if (message.Msg == WM_SYSCOMMAND && (message.WParam.ToInt32() & 0xfff0) == SC_SIZE) { int isDragFullWindow; GetSystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, out isDragFullWindow, 0); if (isDragFullWindow != 0) { SetSystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 0, 0, 0); } base.WndProc(ref message); if (isDragFullWindow != 0) { SetSystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 1, 0, 0); } } else { base.WndProc(ref message); if (message.Msg == 0x84) // WM_NCHITTEST { var cursor = PointToClient(Cursor.Position); if (TopLeft.Contains(cursor)) { message.Result = (IntPtr)HTTOPLEFT; } else if (TopRight.Contains(cursor)) { message.Result = (IntPtr)HTTOPRIGHT; } else if (BottomLeft.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMLEFT; } else if (BottomRight.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMRIGHT; } else if (Top.Contains(cursor)) { message.Result = (IntPtr)HTTOP; } else if (Left.Contains(cursor)) { message.Result = (IntPtr)HTLEFT; } else if (Right.Contains(cursor)) { message.Result = (IntPtr)HTRIGHT; } else if (Bottom.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOM; } } } } catch (Exception e) { MessageBox.Show( "Google Geolocation encountered a fatal error and must be restarted. Please contact support with this message: " + e.Message, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool Equals(GridSegment other) { return(TopLeft.Equals(other.TopLeft) && TopRight.Equals(other.TopRight) && BottomLeft.Equals(other.BottomLeft) && BottomRight.Equals(other.BottomRight)); }
public override double GetSurfacePointAltitude(double lat, double lng, bool meters) { if (Level < lastDeepestLevel) { //interate children for (int ii = 0; ii < 4; ii++) { Tile child = children[ii]; if (child != null) { if (child.IsPointInTile(lat, lng)) { double retVal = child.GetSurfacePointAltitude(lat, lng, meters); if (retVal != 0) { return(retVal); } else { break; } } } } } TileTargetLevel = Level; TileTargetX = tileX; TileTargetY = tileY; Vector3d testPoint = Coordinates.GeoTo3dDouble(-lat, lng); testPoint = Vector3d.SubtractVectors(new Vector3d(), testPoint); Vector2d uv = DistanceCalc.GetUVFromInnerPoint(TopLeft.Copy(), TopRight.Copy(), BottomLeft.Copy(), BottomRight.Copy(), testPoint.Copy()); //Document.Title = "u:" + uv.X + ", v:" + uv.Y; //uv.X = 1 - uv.X; //uv.Y = 1 - uv.Y; // Get 4 samples and interpolate double uud = Math.Max(0, Math.Min(16, (uv.X * 16))); double vvd = Math.Max(0, Math.Min(16, (uv.Y * 16))); int uu = Math.Max(0, Math.Min(15, (int)(uv.X * 16))); int vv = Math.Max(0, Math.Min(15, (int)(uv.Y * 16))); double ha = uud - uu; double va = vvd - vv; if (demArray != null) { // 4 nearest neighbors double ul = demArray[uu + 17 * vv]; double ur = demArray[(uu + 1) + 17 * vv]; double ll = demArray[uu + 17 * (vv + 1)]; double lr = demArray[(uu + 1) + 17 * (vv + 1)]; double top = ul * (1 - ha) + ha * ur; double bottom = ll * (1 - ha) + ha * lr; double val = top * (1 - va) + va * bottom; return(val / DemScaleFactor); } return(demAverage / DemScaleFactor); }
protected override void WndProc(ref Message message) { switch (message.Msg) { // box shadow case WM_NCPAINT: if (m_aeroEnabled) { var v = 2; DwmSetWindowAttribute(this.Handle, 2, ref v, 4); MARGINS margins = new MARGINS() { bottomHeight = 1, leftWidth = 1, rightWidth = 1, topHeight = 1 }; DwmExtendFrameIntoClientArea(this.Handle, ref margins); } break; default: break; } base.WndProc(ref message); if (message.Msg == 0x84) // WM_NCHITTEST { var cursor = this.PointToClient(Cursor.Position); if (TopLeft.Contains(cursor)) { message.Result = (IntPtr)HTTOPLEFT; } else if (TopRight.Contains(cursor)) { message.Result = (IntPtr)HTTOPRIGHT; } else if (BottomLeft.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMLEFT; } else if (BottomRight.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOMRIGHT; } else if (Top.Contains(cursor)) { message.Result = (IntPtr)HTTOP; } else if (Left.Contains(cursor)) { message.Result = (IntPtr)HTLEFT; } else if (Right.Contains(cursor)) { message.Result = (IntPtr)HTRIGHT; } else if (Bottom.Contains(cursor)) { message.Result = (IntPtr)HTBOTTOM; } } }
public override string ToString() { return(string.Format("Bottom Left at {0}, Top Right at {1}", BottomLeft.ToString(), TopRight.ToString())); }
public override Shape clone() { return(new Rectangle((Point)TopLeft.clone(), (Point)TopRight.clone(), (Point)DownLeft.clone(), (Point)DownRight.clone())); }
bool Equals(CornerRadius other) { return(TopLeft.Equals(other.TopLeft) && TopRight.Equals(other.TopRight) && BottomRight.Equals(other.BottomRight) && BottomLeft.Equals(other.BottomLeft)); }
/// <inheritdoc /> public override int GetHashCode() => TopLeft.GetHashCode() ^ TopRight.GetHashCode() ^ BottomLeft.GetHashCode() ^ BottomRight.GetHashCode();