// UNTESTED!!!! public void Add(float key, int val) { BTreeNode newNode = new BTreeNode(key, val); // add element to bottom of the array mArray.Add(newNode); int index = mArray.Count - 1; //compare value to it's parent, swap if parent is larger while ( index > 0 && mArray[(index+1)/2 - 1].mKey > key ) { //swap mArray[index] = mArray[(index+1)/2 - 1]; mArray[(index+1)/2 - 1] = newNode; index = (index+1)/2 - 1; // set new index position } }
/* static ModifiersKnot[,] GetResultMatrix(List<BTreeNode<Wave>> wayOfWave, float minAmplitude, int xSizeOfMatr, int xSizeOfMatr) { }*/ static BTreeNode<Wave> CreateWave(Wave prevWave, List<Polygon> polygons, Polygon room, float minAmplitude, int iteration, int maxIter) { if (prevWave == null || iteration> maxIter || prevWave.waveMod.AmpMod[0].Amplitude< minAmplitude) return null; BTreeNode<Wave> result = new BTreeNode<Wave>(); BTreeNode<Wave> nextT; Wave nextReflWave = new Wave(); Wave nextRefrWave = new Wave(); FindNextWaves(prevWave,polygons,room, out nextReflWave, out nextRefrWave); result.Value = prevWave; if (nextReflWave != null) { nextT = new BTreeNode<Wave>(); nextT = CreateWave(nextReflWave, polygons, room, minAmplitude, iteration + 1, maxIter); if (nextT != null) { nextT.Value = nextReflWave; result.L = nextT; } } if (nextRefrWave != null) { nextT = new BTreeNode<Wave>(); nextT = CreateWave(nextRefrWave, polygons, room, minAmplitude, iteration + 1, maxIter); if (nextT != null) { nextT.Value = nextRefrWave; result.R = nextT; } } return result; }
/// <summary> /// Функция которая создает сетку модификаторов волны /// </summary> /// <param name="polygons">список объектов в помещении</param> /// <param name="sourses"> источники звука</param> /// <param name="room"> комната</param> /// <param name="xSizeOfMatr">размер1 матрицы</param> /// <param name="ySizeOfMatr">размер2 матрицы</param> /// <param name="int">количество лучей для трассировки </param> /// <param name="float">порог энергии волны, поле которого она не рассматривается. </param> /*ModifiersKnot[,]*/ public static List<BTreeNode<Wave>> GetModifiersKnots(List<Polygon> polygons, List<Sourse> sourses, Polygon room, int xSizeOfMatr, int ySizeOfMatr, int RaysCount, float minAmplitude, int reflCount) { Vector vect = new Vector(); //List<Wave> wayOfWave = new List<Wave>(); Wave wave = new Wave(); BTreeNode<Wave> wayOfWave = new BTreeNode<Wave>(); List<BTreeNode<Wave>> r = new List<BTreeNode<Wave>>(); ModifiersKnot[,] result = new ModifiersKnot[xSizeOfMatr + 2, ySizeOfMatr + 2]; for (int i = 0; i < xSizeOfMatr+2; i++) for (int j = 0; j < ySizeOfMatr+2; j++) result[i, j] = new ModifiersKnot(); xSizeOfMatr = xSizeOfMatr - 2; ySizeOfMatr = ySizeOfMatr - 2; float stepX = room.FindMaxDeltaX() / xSizeOfMatr; float stepY = room.FindMaxDeltaY() / ySizeOfMatr; float b=0; float temp; float koef; float x0, y0; float xEnd, yEnd; float d = 0.02f; for (int i = 0; i < sourses.Count; i++) for (int j = 0; j < RaysCount; j++) { // j = 36; vect = new Vector((float)Math.Cos(2 * Math.PI * (float)j / (float)RaysCount), (float)Math.Sin(2 * Math.PI * (float)j / (float)RaysCount), sourses[i].Coords); wave = new Wave(vect); wave.speed = 331.2f; wave.waveMod.soundSpeed = 331.2f; wayOfWave = CreateWave(wave, polygons, room, minAmplitude, 0, reflCount); r.Add(wayOfWave); //result = GetResultMatrix(wayOfWave, minAmplitude, xSizeOfMatr, xSizeOfMatr); /* for (int k = 0; k < wayOfWave.Count; k++) { x0 = (wayOfWave[k].direct.nullP.x / stepX); y0 = (wayOfWave[k].direct.nullP.y / stepY); xEnd = (wayOfWave[k].end.x / stepX); yEnd = (wayOfWave[k].end.y / stepY); if (!(xEnd < x0 + 0.0001 && xEnd > x0 - 0.0001)) { koef = (yEnd - y0) / (xEnd - x0); b = y0 - koef * x0; if (x0 > xEnd) { temp = x0; x0 = xEnd; xEnd = temp; } for (float a = x0; a < xEnd; a = a + 1) { wayOfWave[k].waveMod.SetAmp((float)wayOfWave[k].previousDist + Math.Abs(a * stepX - wayOfWave[k].direct.nullP.x)); wayOfWave[k].SetDelay(Math.Abs(wayOfWave[k].previousDist + Math.Abs(a * stepX - wayOfWave[k].direct.nullP.x))); result[(int)a, (int)(a * koef + b)].AddModifier(wayOfWave[k].waveMod); } } else { if (y0 > xEnd) { temp = y0; y0 = yEnd; yEnd = temp; } for (float a = y0; a < yEnd; a = a + 1) { wayOfWave[k].waveMod.SetAmp(wayOfWave[k].previousDist + Math.Abs(a * stepY - wayOfWave[k].direct.nullP.y)); wayOfWave[k].SetDelay(Math.Abs(wayOfWave[k].previousDist + Math.Abs(a * stepY - wayOfWave[k].direct.nullP.y))); result[(int)x0, (int)a].AddModifier(wayOfWave[k].waveMod); } } }*/ } return /*result*/ r; }
private void Paint_Wave(object sender, PaintEventArgs e, BTreeNode<Wave> A, float scale, Pen p) { if (A.L != null) Paint_Wave(sender, e, A.L,scale, Pens.Green); if(A.R!=null) Paint_Wave(sender, e, A.R, scale, Pens.Red); DrawWave(sender, e, A.Value, scale, p); }
public BTreeNodeCacheEntry(BTreeNode node) { _node = node; }
protected override void AdjustSizeOnRemovalByOtherTransaction(BTree btree, BTreeNode node) { }
public abstract object Commit(Transaction trans, BTree btree, BTreeNode node);
public BTreeNodePrioritySelector(BTreeNode _parentNode, BTreeNodePrecondition _precondition = null) : base(_parentNode, _precondition) { }
public int t; // Minimum degree // Constructor (Initializes tree as empty) Btree(int t) { this.root = null; this.t = t; }
} //minimum degree // Constructor (Initializes tree as empty) public BTree(int _t) { root = null; t = _t; }
// 这个函数属于核心函数 private bool insertPicture(BTreeNode <FontRectKey> node) { /* * 拆分剩余rect为left和right两个分支。 * ●---------●----------------- | picture | right | | | | | ●--------------------------- | | | left | | | | | | | | ---------------------------- | 例如.picture已经占据了【左上角】区域。剩下的区域分为left和right。点(●)的地方就是CGPoint了。 | ● 优化点:如果picture是矩形,那么在生成left和right的时候。可以有两个选择:向下延伸,向右延伸。 | 通常是向值小的一方延伸,这样保证值大的一方可以放进去更多的图片。 | ● 上面的例子是向右延伸。 */ if (node == null) { return(false); } if (!node.isFull && node.virtualPic.width >= m_CurrentPic.width && node.virtualPic.height >= m_CurrentPic.height) { // 是否已经填充 node.isFull = true; // 后面考虑用池来做 node.left = new BTreeNode <FontRectKey>(); node.left.x = node.x; node.left.y = node.y + m_CurrentPic.height; // 后面考虑用池来做 node.left.virtualPic = new PicNode <FontRectKey>(); // 后面考虑用池来做 node.right = new BTreeNode <FontRectKey>(); node.right.x = node.x + m_CurrentPic.width; node.right.y = node.y; // 后面考虑用池来做 node.right.virtualPic = new PicNode <FontRectKey>(); if (m_CurrentPic.width >= m_CurrentPic.height) { node.left.virtualPic.width = node.virtualPic.width; node.left.virtualPic.height = node.virtualPic.height - m_CurrentPic.height; node.right.virtualPic.width = node.virtualPic.width - m_CurrentPic.width; node.right.virtualPic.height = m_CurrentPic.height; } else { node.left.virtualPic.width = m_CurrentPic.width; node.left.virtualPic.height = node.virtualPic.height - m_CurrentPic.height; node.right.virtualPic.width = node.virtualPic.width - m_CurrentPic.width; node.right.virtualPic.height = node.virtualPic.height; } node.virtualPic = m_CurrentPic; return(true); } return(false); }
public void SetRightSubTree(BTreeNode sub) { this.right = sub; }
public void SetLeftSubTree(BTreeNode sub) { this.left = sub; }
public void SetData(BTreeNode data) { this.data = data; }
public void GetIndexAtParentChildren_ParentIsNull_ThrowsException() { var node = new BTreeNode <int, string>(5); int index = node.GetIndexAtParentChildren(); }