------------------------------------------------------------------------------ Calculate the distance between the point x and the specified bounds WARNING!!!!! Be very careful altering this routine. Simple changes to this routine can make is 25% slower!!!!
| 199 | // WARNING!!!!! Be very careful altering this routine. Simple changes to this |
| 200 | // routine can make is 25% slower!!!! |
| 201 | double vtkBucketList2D::Distance2ToBounds(const double x[3], const double bounds[6]) |
| 202 | { |
| 203 | double distance; |
| 204 | double deltas[3]; |
| 205 | |
| 206 | // Are we within the bounds? |
| 207 | if (x[0] >= bounds[0] && x[0] <= bounds[1] && x[1] >= bounds[2] && x[1] <= bounds[3]) |
| 208 | { |
| 209 | return 0.0; |
| 210 | } |
| 211 | |
| 212 | deltas[0] = deltas[1] = deltas[2] = 0.0; |
| 213 | |
| 214 | // dx |
| 215 | // |
| 216 | if (x[0] < bounds[0]) |
| 217 | { |
| 218 | deltas[0] = bounds[0] - x[0]; |
| 219 | } |
| 220 | else if (x[0] > bounds[1]) |
| 221 | { |
| 222 | deltas[0] = x[0] - bounds[1]; |
| 223 | } |
| 224 | |
| 225 | // dy |
| 226 | // |
| 227 | if (x[1] < bounds[2]) |
| 228 | { |
| 229 | deltas[1] = bounds[2] - x[1]; |
| 230 | } |
| 231 | else if (x[1] > bounds[3]) |
| 232 | { |
| 233 | deltas[1] = x[1] - bounds[3]; |
| 234 | } |
| 235 | |
| 236 | distance = vtkMath::Dot(deltas, deltas); |
| 237 | return distance; |
| 238 | } |
| 239 | |
| 240 | //------------------------------------------------------------------------------ |
| 241 | // Given a position x, return the id of the point closest to it. |
no test coverage detected