private void Draw(Bitmap bitmap, GeometryShader2D shader, Matrix4x4 transform) { var geometries = new List <IMarkGeometry>(); var border = (MarkGeometryRectangle)Boundary.Clone(); border.Stroke = Color.White; border.Transform(transform); geometries.Add(border); // apply transformation to geometries foreach (var line in Segments) { var geometry = ((IMarkGeometry)line.Clone()); geometry.Transform(transform); geometries.Add(geometry); } // draw used cells in red shader.Draw( bitmap, geometries ); if (ChildrenExists) { NorthWest.Draw(bitmap, shader, transform); NorthEast.Draw(bitmap, shader, transform); SouthWest.Draw(bitmap, shader, transform); SouthEast.Draw(bitmap, shader, transform); } }
public List <NamedPoint> GetPointsInArea(Rectangle area) { List <NamedPoint> allPoints = new List <NamedPoint>(); if (this.Bounds.IntersectsWith(area) == false) { return(allPoints); } if (Point != null) { bool pointInArea = Program.PointWithinSquare(area, Point); if (pointInArea == true) { allPoints.Add(Point); } } if (NorthWest == null) { return(allPoints); } allPoints.AddRange(NorthWest.GetPointsInArea(area)); allPoints.AddRange(NorthEast.GetPointsInArea(area)); allPoints.AddRange(SouthWest.GetPointsInArea(area)); allPoints.AddRange(SouthEast.GetPointsInArea(area)); return(allPoints); }
/// <summary> /// Get all objects within the provided range. /// </summary> /// <param name="range">The area to get objects from.</param> /// <returns>Returns all objects that are within the provided range.</returns> public List <T> Query(RectangleF range) { List <T> found = new List <T>(); if (Boundary.Intersects(range)) { foreach (Tuple <Vector2, T> point in points) { if (range.Contains(point.Item1)) { found.Add(point.Item2); } } } else { return(found); } if (divided) { found = found.Concat(NorthWest.Query(range)).ToList(); found = found.Concat(NorthEast.Query(range)).ToList(); found = found.Concat(SouthWest.Query(range)).ToList(); found = found.Concat(SouthEast.Query(range)).ToList(); } return(found); }
/// <summary> /// Checks to see if the actual point is in the quad tree as opposed to being bounded by it /// </summary> /// <param name="point"></param> /// <returns></returns> public bool Contains(Point2Int point) { if (!BoundingBox.ContainsPoint(point)) { return(false); } if (Points != null) { return(Points.Contains(point)); } var center = BoundingBox.CenterPoint(); if (point.X < center.X) { if (point.Y < center.Y) { // bottom left return(SouthWest.Contains(point)); } //top left return(NorthWest.Contains(point)); } if (point.Y < center.Y) { // bottom right return(SouthEast.Contains(point)); } //top right return(NorthEast.Contains(point)); }
public void Draw(Graphics graphics) { Pen pen = Pens.Black; graphics.DrawRectangle(pen, Bounds); if (Point != null) { Point.Draw(graphics); } if (NorthWest != null) { NorthWest.Draw(graphics); } if (NorthEast != null) { NorthEast.Draw(graphics); } if (SouthWest != null) { SouthWest.Draw(graphics); } if (SouthEast != null) { SouthEast.Draw(graphics); } }
public void Subdivide() { if (isDivided) { return; } NorthEast = Create(transform, gameObject.name + " - North East", this); NorthWest = Create(transform, gameObject.name + " - North West", this); SouthEast = Create(transform, gameObject.name + " - South East", this); SouthWest = Create(transform, gameObject.name + " - South West", this); Vector3 axisA = CurrentFace.axisA / 2; Vector3 axisB = CurrentFace.axisB / 2; NorthEast.Initialize( shapeGenerator, colorSettings, CurrentFace.LocalUp + axisA - axisB, axisA, axisB, CurrentFace.Resolution ); NorthWest.Initialize( shapeGenerator, colorSettings, CurrentFace.LocalUp - axisA - axisB, axisA, axisB, CurrentFace.Resolution ); SouthEast.Initialize( shapeGenerator, colorSettings, CurrentFace.LocalUp + axisA + axisB, axisA, axisB, CurrentFace.Resolution ); SouthWest.Initialize( shapeGenerator, colorSettings, CurrentFace.LocalUp - axisA + axisB, axisA, axisB, CurrentFace.Resolution ); NorthEast.CurrentLevelOfDetail = CurrentLevelOfDetail + 1; NorthWest.CurrentLevelOfDetail = CurrentLevelOfDetail + 1; SouthEast.CurrentLevelOfDetail = CurrentLevelOfDetail + 1; SouthWest.CurrentLevelOfDetail = CurrentLevelOfDetail + 1; isDivided = true; MeshRenderer.enabled = false; }
public bool Insert(MarkGeometryLine line) { if ( !( GeometricArithmeticModule.IsWithin2D(line.StartPoint, Boundary.Extents) && GeometricArithmeticModule.IsWithin2D(line.EndPoint, Boundary.Extents) ) ) { return(false); } // ensure quads exist if (!ChildrenExists) { var radius = 0.5 * SubSize; NorthWest = new ContourQuadTree( Boundary.Extents.MinX + radius, // west Boundary.Extents.MaxY - radius, // north SubSize ); NorthEast = new ContourQuadTree( Boundary.Extents.MaxX - radius, // east Boundary.Extents.MaxY - radius, // north SubSize ); SouthWest = new ContourQuadTree( Boundary.Extents.MinX + radius, // west Boundary.Extents.MinY + radius, // south SubSize ); SouthEast = new ContourQuadTree( Boundary.Extents.MaxX - radius, // east Boundary.Extents.MinY + radius, // south SubSize ); ChildrenExists = true; } if ( (line.Length <= MinSize) || !( NorthWest.Insert(line) || NorthEast.Insert(line) || SouthWest.Insert(line) || SouthEast.Insert(line) ) ) { Segments.Add(line); } return(true); }
public override int GetHashCode() { unchecked { var hashCode = NorthWest.GetHashCode(); hashCode = (hashCode * 397) ^ NorthEast.GetHashCode(); hashCode = (hashCode * 397) ^ SouthEast.GetHashCode(); hashCode = (hashCode * 397) ^ SouthWest.GetHashCode(); return(hashCode); } }
/// <summary> /// Compute matrix from quad tree /// </summary> public void computeMatrix() { if (NorthWest != null) { if (NorthWest.RootColor == Colors.Gray) { NorthWest.computeMatrix(); } else { NorthWest.setMatrix(NorthWest.RootColor); } } if (SouthWest != null) { if (SouthWest.RootColor == Colors.Gray) { SouthWest.computeMatrix(); } else { SouthWest.setMatrix(SouthWest.RootColor); } } if (SouthEast != null) { if (SouthEast.RootColor == Colors.Gray) { SouthEast.computeMatrix(); } else { SouthEast.setMatrix(SouthEast.RootColor); } } if (NorthEast != null) { if (NorthEast.RootColor == Colors.Gray) { NorthEast.computeMatrix(); } else { NorthEast.setMatrix(NorthEast.RootColor); } } mergeMatrices(); }
public void UpdateColors(ColorGenerator colorGenerator) { if (isDivided) { NorthEast.UpdateColors(colorGenerator); NorthWest.UpdateColors(colorGenerator); SouthEast.UpdateColors(colorGenerator); SouthWest.UpdateColors(colorGenerator); return; } CurrentFace.UpdateUVs(colorGenerator); }
public void ConstructMesh() { if (isDivided) { NorthEast.ConstructMesh(); NorthWest.ConstructMesh(); SouthEast.ConstructMesh(); SouthWest.ConstructMesh(); } else { CurrentFace.ConstructMesh(); } }
private IntersectionsBinaryTree Intersect(MarkGeometryLine line, LineEquation equation) { if (!equation.PassesThroughRect(Boundary)) { return(null); } // using binary tree to sort points relative to the line's starting point var intersections = new IntersectionsBinaryTree(line.StartPoint); if (ChildrenExists) { IntersectionsBinaryTree childIntersections; if ((childIntersections = NorthWest.Intersect(line)) != null) { intersections.InsertRange(childIntersections); } if ((childIntersections = NorthEast.Intersect(line)) != null) { intersections.InsertRange(childIntersections); } if ((childIntersections = SouthWest.Intersect(line)) != null) { intersections.InsertRange(childIntersections); } if ((childIntersections = SouthEast.Intersect(line)) != null) { intersections.InsertRange(childIntersections); } } MarkGeometryPoint intersection; for (int i = 0; i < Segments.Count; i++) { if (( intersection = GeometricArithmeticModule.CalculateIntersection2D( line, Segments[i] )) != null ) { intersections.Insert(intersection); } } return(intersections); }
public void GetPointsInArea(Bounding2DBox area, ref List <Point2Int> list) { if (!BoundingBox.DoesBoundaryBoxIntersect(area)) { return; } if (Points != null) { GetLocalPointsInArea(area, ref list); } else { NorthEast.GetPointsInArea(area, ref list); NorthWest.GetPointsInArea(area, ref list); SouthWest.GetPointsInArea(area, ref list); SouthEast.GetPointsInArea(area, ref list); } }
private void AddPointToChildren(Point2Int point) { var center = BoundingBox.CenterPoint(); if (point.X < center.X) { if (point.Y < center.Y) { SouthWest.Add(point); return; } NorthWest.Add(point); return; } if (point.Y < center.Y) { SouthEast.Add(point); return; } NorthEast.Add(point); }
/// <summary> /// Insert a point into the QuadTree. /// </summary> /// <param name="point">Position where to insert the point.</param> /// <param name="obj">The object that is attached to the point.</param> /// <returns>Returns true if the point was successfully inserted into this QuadTree, otherwise false.</returns> public bool Insert(Vector2 point, T obj) { if (!Boundary.Contains(point)) { return(false); } if (points.Count < Capacity) { // Inserted a point successfully. points.Add(new Tuple <Vector2, T>(point, obj)); return(true); } else if (!divided) { Subdivide(); } if (NorthWest.Insert(point, obj)) { return(true); } if (NorthEast.Insert(point, obj)) { return(true); } if (SouthWest.Insert(point, obj)) { return(true); } if (SouthEast.Insert(point, obj)) { return(true); } return(false); }
public QuadTreeTerrainFace FindClosestFace(Vector3 point) { if (isDivided) { var neClosestFace = NorthEast.FindClosestFace(point); var nwClosestFace = NorthWest.FindClosestFace(point); var seClosestFace = SouthEast.FindClosestFace(point); var swClosestFace = SouthWest.FindClosestFace(point); float neDistance = neClosestFace.DistanceTo(point); float nwDistance = nwClosestFace.DistanceTo(point); float seDistance = seClosestFace.DistanceTo(point); float swDistance = swClosestFace.DistanceTo(point); float minDistance = Mathf.Min(neDistance, nwDistance, seDistance, swDistance); if (neDistance == minDistance) { return(neClosestFace); } else if (nwDistance == minDistance) { return(nwClosestFace); } else if (seDistance == minDistance) { return(seClosestFace); } else if (swDistance == minDistance) { return(swClosestFace); } } return(this); }
public override int GetHashCode() { return(SouthWest.GetHashCode() ^ NorthEast.GetHashCode()); }
public override string ToString() { return(string.Format("geography::Parse('POLYGON(({0}, {1}, {2}, {3}, {0}))')", NorthWest.AsText(), SouthWest.AsText(), SouthEast.AsText(), NorthEast.AsText())); }
private void RenderMgrsCellLabels(DrawingContext pDC, MgrsBoundingBox pBoundingBox, double pNorth, double pEast, NorthEast pDirection) { int numberOfDigits; switch (MgrsGridPrecision) { case EGridPrecision.Grid10km: numberOfDigits = 1; break; case EGridPrecision.Grid1km: numberOfDigits = 2; break; case EGridPrecision.Grid100m: numberOfDigits = 3; break; default: return; // Dont render label } var cellSize = CellSizeInPixels(pBoundingBox); if ((cellSize.Width > 30) && (cellSize.Height > 30)) { var eastFont = new FormattedText(pNorth.ToString().Substring(2, numberOfDigits), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, mTypefaceMgrsCellLabel, mFontSizeMgrsCellLabel, mFontColorMgrsCellLabel); var northFont = new FormattedText(pEast.ToString().Substring(1, numberOfDigits), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, mTypefaceMgrsCellLabel, mFontSizeMgrsCellLabel, mFontColorMgrsCellLabel); var lowerLeft = Viewport.EsriMap.MapToScreen(pBoundingBox.LowerLeft.ToEsriGeometry(102100)); int marge = 3; if (pDirection == NorthEast.East) { // Horizontal labels var rectNorth = GetBoundingRect(northFont); rectNorth.Inflate(marge * 2, marge * 2); var northPoint = new Point(lowerLeft.X + (cellSize.Width / 2) - (rectNorth.Width / 2), lowerLeft.Y - (rectNorth.Height / 2)); pDC.DrawRoundedRectangle(mFontColorMgrsFill, mMgrsLabelLinePen, new Rect(northPoint, rectNorth.Size), 2, 2); pDC.DrawText(eastFont, new Point(northPoint.X + marge, northPoint.Y + marge)); } if (pDirection == NorthEast.North) { // Vertical var rectEast = GetBoundingRect(eastFont); rectEast.Inflate(marge * 2, marge * 2); var eastPoint = new Point(lowerLeft.X - (rectEast.Width / 2), lowerLeft.Y - (cellSize.Height / 2) - (rectEast.Height / 2)); pDC.DrawRoundedRectangle(mFontColorMgrsFill, mMgrsLabelLinePen, new Rect(eastPoint, rectEast.Size), 2, 2); pDC.DrawText(northFont, new Point(eastPoint.X + marge, eastPoint.Y + marge)); } } }
public string ToGoogleApi() { return($"new google.maps.LatLngBounds({SouthWest.ToGoogleApi()}, {NorthEast.ToGoogleApi()})"); }
public BoundingBox Validate() { SouthWest = (Point)SouthWest.Validate(); NorthEast = (Point)NorthEast.Validate(); return(this); }