private void UpTree(ref NativeQuadTreeNode now) { if (now.Has == false) { return; } var s = float4.zero; var k = 0L; for (int i = 0; i < 4; i++) { if (now[i] >= 0) { var childNode = this[now[i]]; var temp = childNode.Max - childNode.Min; s += childNode.Data * (temp.x + 1) * (temp.y + 1); k += (long)(temp.x + 1) * (temp.y + 1); } } now.Data = s / k; for (int i = 0; i < 4; i++) { if (now[i] >= 0) { if (this[now[i]].Flag == false) { return; } else { var b = this[now[i]].Data - now.Data > _eps; if (b.x && b.y && b.z && b.w) { return; } } } } now.Flag = true; for (var i = 0; i < 4; i++) { if (now[i] >= 0) { CollectNodeId(now[i]); now[i] = -1; } } }
/// <summary> /// 创建子节点 /// </summary> /// <param name="now"></param> private void CreateChildren(ref NativeQuadTreeNode now) { for (var i = 0; i < 4; i++) { if (now[i] == -1) { if (i == 0 || (i == 1 && now.Max.x != now.Min.x) || (i == 2 && now.Max.y != now.Min.y) || (i == 3 && now.Max.x != now.Min.x && now.Max.y != now.Min.y)) { CreateChildren(ref now, i); } } } }
private bool DownTree(ref NativeQuadTreeNode now) { if (now.Flag == false) { return(false); } for (int i = 0; i < 4; i++) { if (now[i] >= 0) { var child = this[now[i]]; child.Flag = true; child.Data = now.Data; } } now.Flag = false; return(true); }
/// <summary> /// 创建子节点 /// </summary> /// <param name="now"></param> /// <param name="index"></param> private void CreateChildren(ref NativeQuadTreeNode now, int index) { var id = 0; var min = int2.zero; var max = int2.zero; switch (index) { case 0: id = now[0] = CreateNodeId(); min = now.Min; max = now.Min + (now.Max - now.Min) / 2; break; case 1: id = now[1] = CreateNodeId(); min = new int2(now.Min.x + (now.Max.x - now.Min.x) / 2 + 1, now.Min.y); max = new int2(now.Max.x, now.Min.y + (now.Max.y - now.Min.y) / 2); break; case 2: id = now[2] = CreateNodeId(); min = new int2(now.Min.x, now.Min.y + (now.Max.y - now.Min.y) / 2 + 1); max = new int2(now.Min.x + (now.Max.x - now.Min.x) / 2, now.Max.y); break; case 3: id = now[3] = CreateNodeId(); min = now.Min + (now.Max - now.Min) / 2 + new int2(1, 1); max = now.Max; break; } if (id < m_ListData->Length) { this[id] = new NativeQuadTreeNode(id, 0, min, max, m_AllocatorLabel); } else { m_ListData->Add(new NativeQuadTreeNode(id, 0, min, max, m_AllocatorLabel)); } }