mirror of
https://github.com/recp/cglm.git
synced 2025-12-24 20:34:58 +00:00
vec2: distance implementation
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
//
|
||||
// vec2.h
|
||||
// glm
|
||||
//
|
||||
// Created by Recep Aslantas on 3/31/19.
|
||||
// Copyright © 2019 Recep Aslantas. All rights reserved.
|
||||
//
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#ifndef vec2_h
|
||||
#define vec2_h
|
||||
#ifndef cglmc_vec2_h
|
||||
#define cglmc_vec2_h
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
|
||||
|
||||
#endif /* vec2_h */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* cglmc_vec2_h */
|
||||
|
||||
@@ -432,6 +432,32 @@ glm_vec2_normalize_to(vec2 vec, vec2 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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user