mirror of
https://github.com/recp/cglm.git
synced 2025-12-26 02:25:02 +00:00
squared distance for vec3
This commit is contained in:
@@ -148,6 +148,10 @@ CGLM_EXPORT
|
||||
void
|
||||
glmc_vec_center(vec3 v1, vec3 v2, vec3 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_vec_distance2(vec3 v1, vec3 v2);
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_vec_distance(vec3 v1, vec3 v2);
|
||||
|
||||
@@ -633,6 +633,21 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) {
|
||||
glm_vec_scale(dest, 0.5f, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief squared distance between two vectors
|
||||
*
|
||||
* @param[in] v1 vector1
|
||||
* @param[in] v2 vector2
|
||||
* @return returns squared distance (distance * distance)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_vec_distance2(vec3 v1, vec3 v2) {
|
||||
return glm_pow2(v2[0] - v1[0])
|
||||
+ glm_pow2(v2[1] - v1[1])
|
||||
+ glm_pow2(v2[2] - v1[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief distance between two vectors
|
||||
*
|
||||
@@ -643,9 +658,7 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) {
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_vec_distance(vec3 v1, vec3 v2) {
|
||||
return sqrtf(glm_pow2(v2[0] - v1[0])
|
||||
+ glm_pow2(v2[1] - v1[1])
|
||||
+ glm_pow2(v2[2] - v1[2]));
|
||||
return sqrtf(glm_vec_distance2(v1, v2));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user