| 138 | } |
| 139 | |
| 140 | void QuerySphere(Vec3 center, float radius, std::vector<int>& indices) |
| 141 | { |
| 142 | // find start point in the array |
| 143 | int low = 0; |
| 144 | int high = int(entries.size()); |
| 145 | |
| 146 | // the point we are trying to find |
| 147 | float queryLower = center[longestAxis] - radius; |
| 148 | float queryUpper = center[longestAxis] + radius; |
| 149 | |
| 150 | // binary search to find the start point in the sorted entries array |
| 151 | while (low < high) |
| 152 | { |
| 153 | const int mid = (high+low)/2; |
| 154 | |
| 155 | if (queryLower > entries[mid].point[longestAxis]) |
| 156 | low = mid+1; |
| 157 | else |
| 158 | high = mid; |
| 159 | } |
| 160 | |
| 161 | // scan forward over potential overlaps |
| 162 | float radiusSq = radius*radius; |
| 163 | |
| 164 | for (int i=low; i < int(entries.size()); ++i) |
| 165 | { |
| 166 | Vec3 p = entries[i].point; |
| 167 | |
| 168 | if (LengthSq(p-center) < radiusSq) |
| 169 | { |
| 170 | indices.push_back(entries[i].index); |
| 171 | } |
| 172 | else if (entries[i].point[longestAxis] > queryUpper) |
| 173 | { |
| 174 | // early out if ther are no more possible candidates |
| 175 | break; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | int longestAxis; // [0,2] -> x,y,z |
| 181 |
no test coverage detected