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 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 Insert(Point pt) { if (!_rectangle.Contains(pt)) { return; } if (ptList.Count < CAPACITY) { ptList.Add(pt); } else { if (!divided) { SubDivide(); } NorthEast.Insert(pt); SouthEast.Insert(pt); SouthWest.Insert(pt); NorthWest.Insert(pt); } }
public void DrawPoints() { int x = _rectangle._x; int y = _rectangle._y; int w = _rectangle._w; int h = _rectangle._h; SwinGame.DrawRectangle(SwinGame.ColorBlack(), x - w, y - h, w * 2, h * 2); // SwinGame.DrawRectangle(SwinGame.ColorBlack(), _rectangle._x - 1 - _rectangle._w , _rectangle._y - 1 - _rectangle._h, 2 + (_rectangle._w *2),2+( _rectangle._h *2)); //SwinGame.DrawRectangle(SwinGame.ColorWhite(), _rectangle._x - _rectangle._w, _rectangle._y - _rectangle._h, _rectangle._w *2, _rectangle._h *2); foreach (Point pt in ptList) { SwinGame.DrawCircle(SwinGame.ColorBlack(), pt._x, pt._y, 1); } if (divided) { NorthWest.DrawPoints(); NorthEast.DrawPoints(); SouthWest.DrawPoints(); SouthEast.DrawPoints(); } }
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 string ToString() { return(string.Format("geography::Parse('POLYGON(({0}, {1}, {2}, {3}, {0}))')", NorthWest.AsText(), SouthWest.AsText(), SouthEast.AsText(), NorthEast.AsText())); }