/// <summary> /// set current rectangle with the merge of given rectangle. /// </summary> internal void Merge(MBRectangle rectangleToMerge) { var merged = getMergedRectangle(rectangleToMerge); LeftTopCorner = merged.LeftTopCorner; RightBottomCorner = merged.RightBottomCorner; }
/// <summary> /// Set current rectangle with the merge of given rectangle. /// </summary> internal void Merge(MBRectangle rectangleToMerge) { var merged = getMergedRectangle(rectangleToMerge); LeftTop = merged.LeftTop; RightBottom = merged.RightBottom; }
/// <summary> /// Merge the current rectangle with given rectangle. /// </summary> /// <param name="rectangleToMerge">The new rectangle.</param> private Rectangle getMergedRectangle(MBRectangle rectangleToMerge) { var leftTopCorner = new Point(LeftTopCorner.X > rectangleToMerge.LeftTopCorner.X ? rectangleToMerge.LeftTopCorner.X : LeftTopCorner.X, LeftTopCorner.Y < rectangleToMerge.LeftTopCorner.Y ? rectangleToMerge.LeftTopCorner.Y : LeftTopCorner.Y); var rightBottomCorner = new Point(RightBottomCorner.X <rectangleToMerge.RightBottomCorner.X?rectangleToMerge.RightBottomCorner.X : RightBottomCorner.X, RightBottomCorner.Y> rectangleToMerge.RightBottomCorner.Y ? rectangleToMerge.RightBottomCorner.Y : RightBottomCorner.Y); return(new MBRectangle(leftTopCorner, rightBottomCorner)); }
/// <summary> /// Select the child node whose MBR will require the minimum area enlargement /// to cover the given polygon. /// </summary> /// <param name="newPolygon"></param> /// <returns></returns> internal RTreeNode GetMinimumEnlargementAreaMBR(MBRectangle newPolygon) { //order by enlargement area //then by minimum area return(Children[Children.Take(KeyCount) .Select((node, index) => new { node, index }) .OrderBy(x => x.node.MBRectangle.GetEnlargementArea(newPolygon)) .ThenBy(x => x.node.MBRectangle.Area()) .First().index]); }
/// <summary> /// Set the child at specifid index. /// </summary> /// <param name="index"></param> /// <param name="child"></param> internal void SetChild(int index, RTreeNode child) { Children[index] = child; Children[index].Parent = this; Children[index].Index = index; if (MBRectangle == null) { MBRectangle = new MBRectangle(child.MBRectangle); } else { MBRectangle.Merge(child.MBRectangle); } Height = child.Height + 1; }
/// <summary> /// returns the required enlargement area to fit the given rectangle inside this minimum bounded rectangle. /// </summary> /// <param name="polygonToFit">The rectangle to fit inside current MBR.</param> internal double GetEnlargementArea(MBRectangle rectangleToFit) { return(Math.Abs(getMergedRectangle(rectangleToFit).Area() - Area())); }
/// <summary> /// Set current rectangle with the merge of given rectangle. /// </summary> internal void Merge(MBRectangle rectangleToMerge) { var merged = getMergedRectangle(rectangleToMerge); Rect = new Rectangle(merged.Rect.LeftTop, merged.Rect.RightBottom); }