OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/prediction/key_set.h" |
| 6 |
| 7 namespace prediction { |
| 8 |
| 9 int KeySet::SquaredDistanceToEdge(int x, int y, Key k) { |
| 10 const int left = k.kx; |
| 11 const int right = left + k.kwidth; |
| 12 const int top = k.ky; |
| 13 const int bottom = top + k.kheight; |
| 14 const int edge_x = x < left ? left : (x > right ? right : x); |
| 15 const int edge_y = y < top ? top : (y > bottom ? bottom : y); |
| 16 const int dx = x - edge_x; |
| 17 const int dy = y - edge_y; |
| 18 return dx * dx + dy * dy; |
| 19 } |
| 20 |
| 21 } // namespace prediction |
OLD | NEW |