diff options
Diffstat (limited to 'native/jni/src/geometry_utils.h')
-rw-r--r-- | native/jni/src/geometry_utils.h | 52 |
1 files changed, 8 insertions, 44 deletions
diff --git a/native/jni/src/geometry_utils.h b/native/jni/src/geometry_utils.h index 31359e19d..4cbb127e8 100644 --- a/native/jni/src/geometry_utils.h +++ b/native/jni/src/geometry_utils.h @@ -19,38 +19,23 @@ #include <cmath> -#define DEBUG_DECODER false +#include "defines.h" -#define M_PI_F 3.14159265f #define ROUND_FLOAT_10000(f) ((f) < 1000.0f && (f) > 0.001f) \ ? (floorf((f) * 10000.0f) / 10000.0f) : (f) -#define SQUARE_FLOAT(x) ((x) * (x)) namespace latinime { -static inline float getSquaredDistanceFloat(float x1, float y1, float x2, float y2) { - const float deltaX = x1 - x2; - const float deltaY = y1 - y2; - return SQUARE_FLOAT(deltaX) + SQUARE_FLOAT(deltaY); -} - -static inline float getDistanceFloat(float x1, float y1, float x2, float y2) { - return hypotf(x1 - x2, y1 - y2); -} - -static inline int getDistanceInt(int x1, int y1, int x2, int y2) { - return static_cast<int>(getDistanceFloat(static_cast<float>(x1), static_cast<float>(y1), - static_cast<float>(x2), static_cast<float>(y2))); -} +static inline float SQUARE_FLOAT(const float x) { return x * x; } -static inline float getAngle(int x1, int y1, int x2, int y2) { +static AK_FORCE_INLINE float getAngle(const int x1, const int y1, const int x2, const int y2) { const int dx = x1 - x2; const int dy = y1 - y2; - if (dx == 0 && dy == 0) return 0; + if (dx == 0 && dy == 0) return 0.0f; return atan2f(static_cast<float>(dy), static_cast<float>(dx)); } -static inline float getAngleDiff(float a1, float a2) { +static AK_FORCE_INLINE float getAngleDiff(const float a1, const float a2) { const float deltaA = fabsf(a1 - a2); const float diff = ROUND_FLOAT_10000(deltaA); if (diff > M_PI_F) { @@ -60,30 +45,9 @@ static inline float getAngleDiff(float a1, float a2) { return diff; } -static inline float pointToLineSegSquaredDistanceFloat( - float x, float y, float x1, float y1, float x2, float y2, bool extend) { - const float ray1x = x - x1; - const float ray1y = y - y1; - const float ray2x = x2 - x1; - const float ray2y = y2 - y1; - - const float dotProduct = ray1x * ray2x + ray1y * ray2y; - const float lineLengthSqr = SQUARE_FLOAT(ray2x) + SQUARE_FLOAT(ray2y); - const float projectionLengthSqr = dotProduct / lineLengthSqr; - - float projectionX; - float projectionY; - if (!extend && projectionLengthSqr < 0.0f) { - projectionX = x1; - projectionY = y1; - } else if (!extend && projectionLengthSqr > 1.0f) { - projectionX = x2; - projectionY = y2; - } else { - projectionX = x1 + projectionLengthSqr * ray2x; - projectionY = y1 + projectionLengthSqr * ray2y; - } - return getSquaredDistanceFloat(x, y, projectionX, projectionY); +static AK_FORCE_INLINE int getDistanceInt(const int x1, const int y1, const int x2, + const int y2) { + return static_cast<int>(hypotf(static_cast<float>(x1 - x2), static_cast<float>(y1 - y2))); } } // namespace latinime #endif // LATINIME_GEOMETRY_UTILS_H |