Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: third_party/prediction/suggest/core/layout/geometry_utils.h

Issue 1247903003: Add spellcheck and word suggestion to the prediction service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef LATINIME_GEOMETRY_UTILS_H
18 #define LATINIME_GEOMETRY_UTILS_H
19
20 #include <cmath>
21
22 #include "third_party/prediction/defines.h"
23
24 #define ROUND_FLOAT_10000(f) \
25 ((f) < 1000.0f && (f) > 0.001f) ? (floorf((f)*10000.0f) / 10000.0f) : (f)
26
27 namespace latinime {
28
29 class GeometryUtils {
30 public:
31 static inline float SQUARE_FLOAT(const float x) { return x * x; }
32
33 static AK_FORCE_INLINE float getAngle(const int x1,
34 const int y1,
35 const int x2,
36 const int y2) {
37 const int dx = x1 - x2;
38 const int dy = y1 - y2;
39 if (dx == 0 && dy == 0)
40 return 0.0f;
41 return atan2f(static_cast<float>(dy), static_cast<float>(dx));
42 }
43
44 static AK_FORCE_INLINE float getAngleDiff(const float a1, const float a2) {
45 const float deltaA = fabsf(a1 - a2);
46 const float diff = ROUND_FLOAT_10000(deltaA);
47 if (diff > M_PI_F) {
48 const float normalizedDiff = 2.0f * M_PI_F - diff;
49 return ROUND_FLOAT_10000(normalizedDiff);
50 }
51 return diff;
52 }
53
54 static AK_FORCE_INLINE int getDistanceInt(const int x1,
55 const int y1,
56 const int x2,
57 const int y2) {
58 return static_cast<int>(
59 hypotf(static_cast<float>(x1 - x2), static_cast<float>(y1 - y2)));
60 }
61
62 private:
63 DISALLOW_IMPLICIT_CONSTRUCTORS(GeometryUtils);
64 };
65 } // namespace latinime
66 #endif // LATINIME_GEOMETRY_UTILS_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698