ListBox3d SearchPrivate(PredicateBox3D query, Box3D box) { if (box.LengthX() == 1) { ListBox3d l1 = newListBox3d(); l1.count = 1; l1.arr[0] = box; return(l1); } ListBox3d l = newListBox3d(); l.count = 0; ListBox3d children = Children(box); for (int k = 0; k < children.count; k++) { Box3D child = children.arr[k]; if (query.Hit(child)) { ListBox3d l2 = SearchPrivate(query, child); for (int i = 0; i < l2.count; i++) { Box3D n = l2.arr[i]; l.arr[l.count++] = n; } recycleListBox3d(l2); } } recycleListBox3d(children); return(l); }
ListBox3d Children(Box3D box) { ListBox3d l = newListBox3d(); l.count = 8; Box3D[] c = l.arr; for (int i = 0; i < 8; i++) { c[i] = newBox3d(); } float x = box.MinEdge[0]; float y = box.MinEdge[1]; float z = box.MinEdge[2]; float size = box.LengthX() / 2; c[0].Set(x, y, z, size); c[1].Set(x + size, y, z, size); c[2].Set(x, y, z + size, size); c[3].Set(x + size, y, z + size, size); c[4].Set(x, y + size, z, size); c[5].Set(x + size, y + size, z, size); c[6].Set(x, y + size, z + size, size); c[7].Set(x + size, y + size, z + size, size); return(l); }
ListBox3d Search(PredicateBox3D query) { pool_i = 0; listpool_i = 0; if (StartBox.LengthX() == 0 && StartBox.LengthY() == 0 && StartBox.LengthZ() == 0) { return(new ListBox3d()); } return(SearchPrivate(query, StartBox)); }
ListBox3d SearchPrivate(PredicateBox3D query, Box3D box) { if (box.LengthX() == 1) { ListBox3d l1 = newListBox3d(); l1.count = 1; l1.arr[0] = box; return l1; } ListBox3d l = newListBox3d(); l.count = 0; ListBox3d children = Children(box); for (int k = 0; k < children.count; k++) { Box3D child = children.arr[k]; if (query.Hit(child)) { ListBox3d l2 = SearchPrivate(query, child); for (int i = 0; i < l2.count; i++) { Box3D n = l2.arr[i]; l.arr[l.count++] = n; } recycleListBox3d(l2); } } recycleListBox3d(children); return l; }
ListBox3d Children(Box3D box) { ListBox3d l = newListBox3d(); l.count = 8; Box3D[] c = l.arr; for (int i = 0; i < 8; i++) { c[i] = newBox3d(); } float x = box.MinEdge[0]; float y = box.MinEdge[1]; float z = box.MinEdge[2]; float size = box.LengthX() / 2; c[0].Set(x, y, z, size); c[1].Set(x + size, y, z, size); c[2].Set(x, y, z + size, size); c[3].Set(x + size, y, z + size, size); c[4].Set(x, y + size, z, size); c[5].Set(x + size, y + size, z, size); c[6].Set(x, y + size, z + size, size); c[7].Set(x + size, y + size, z + size, size); return l; }