vec2: distance implementation

This commit is contained in:
Recep Aslantas
2019-06-04 19:03:31 +03:00
parent 0729fd40a4
commit 047ed259ae
2 changed files with 43 additions and 10 deletions

View File

@@ -1,13 +1,20 @@
// /*
// vec2.h * Copyright (c), Recep Aslantas.
// glm *
// * MIT License (MIT), http://opensource.org/licenses/MIT
// Created by Recep Aslantas on 3/31/19. * Full license can be found in the LICENSE file
// Copyright © 2019 Recep Aslantas. All rights reserved. */
//
#ifndef vec2_h #ifndef cglmc_vec2_h
#define vec2_h #define cglmc_vec2_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
#endif /* vec2_h */ #ifdef __cplusplus
}
#endif
#endif /* cglmc_vec2_h */

View File

@@ -432,6 +432,32 @@ glm_vec2_normalize_to(vec2 vec, vec2 dest) {
glm_vec2_scale(vec, 1.0f / norm, dest); glm_vec2_scale(vec, 1.0f / norm, dest);
} }
/**
* @brief squared distance between two vectors
*
* @param[in] a vector1
* @param[in] b vector2
* @return returns squared distance (distance * distance)
*/
CGLM_INLINE
float
glm_vec2_distance2(vec2 a, vec2 b) {
return glm_pow2(b[0] - a[0]) + glm_pow2(b[1] - a[1]);
}
/**
* @brief distance between two vectors
*
* @param[in] a vector1
* @param[in] b vector2
* @return returns distance
*/
CGLM_INLINE
float
glm_vec2_distance(vec2 a, vec2 b) {
return sqrtf(glm_vec2_distance2(a, b));
}
/*! /*!
* @brief max values of vectors * @brief max values of vectors
* *