| Index: services/prediction/key_set.cc
|
| diff --git a/services/prediction/key_set.cc b/services/prediction/key_set.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6e83f94f1992875fdc3fb52754330bbe32f5fc6a
|
| --- /dev/null
|
| +++ b/services/prediction/key_set.cc
|
| @@ -0,0 +1,21 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "services/prediction/key_set.h"
|
| +
|
| +namespace prediction {
|
| +
|
| +int KeySet::SquaredDistanceToEdge(int x, int y, Key k) {
|
| + const int left = k.kx;
|
| + const int right = left + k.kwidth;
|
| + const int top = k.ky;
|
| + const int bottom = top + k.kheight;
|
| + const int edge_x = x < left ? left : (x > right ? right : x);
|
| + const int edge_y = y < top ? top : (y > bottom ? bottom : y);
|
| + const int dx = x - edge_x;
|
| + const int dy = y - edge_y;
|
| + return dx * dx + dy * dy;
|
| +}
|
| +
|
| +} // namespace prediction
|
|
|