apply restrict keyword and fix some typoes in header file

fixes-turtlebasket
Mattia Montanari 2023-04-22 16:37:27 +02:00
parent a31a959d73
commit ad2d6026b8
2 changed files with 14 additions and 14 deletions

View File

@ -46,18 +46,18 @@
/*! @brief Data structure for convex polytopes.
*
* Polytopes are three-dimensional shapes and the GJK algorithm works directly on their convex-hull. However the convex-hull is never computed explicity, instead each GJK-iteraion employs a support function that has a cost linearly dependen on the number of points defining the polytope. */
* Polytopes are three-dimensional shapes and the GJK algorithm works directly on their convex-hull. However the convex-hull is never computed explicitly, instead each GJK-iteration employs a support function that has a cost linearly dependent on the number of points defining the polytope. */
typedef struct gkPolytope_ {
int numpoints; /*!< Number of points defining the polytope. */
gkFloat s
[3]; /*!< Furthest point retunred by the support function and updated at each GJK-iteration. For the first itearion this value is a guess - and this guess not irrelevant. */
[3]; /*!< Furthest point returned by the support function and updated at each GJK-iteration. For the first iteration this value is a guess - and this guess not irrelevant. */
gkFloat**
coord; /*!< Coordinates of the points of the polytope. This is owned by user who manages and garbage-collects the memory for these coordinates. */
} gkPolytope;
/*! @brief Data structure for simplex.
*
* The simplex is updated at each GJK-iteration. For the first itearion this value is a guess - and this guess not irrelevant. */
* The simplex is updated at each GJK-iteration. For the first iteration this value is a guess - and this guess not irrelevant. */
typedef struct gkSimplex_ {
int nvrtx; /*!< Number of points defining the simplex. */
gkFloat vrtx[4][3]; /*!< Coordinates of the points of the simplex. */

View File

@ -153,20 +153,20 @@
s->vrtx[0][2] = s1[2];
inline static gkFloat
determinant(const gkFloat* p, const gkFloat* q, const gkFloat* r) {
determinant(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r) {
return p[0] * ((q[1] * r[2]) - (r[1] * q[2])) - p[1] * (q[0] * r[2] - r[0] * q[2])
+ p[2] * (q[0] * r[1] - r[0] * q[1]);
}
inline static void
crossProduct(const gkFloat* a, const gkFloat* b, gkFloat* c) {
crossProduct(const gkFloat* restrict a, const gkFloat* restrict b, gkFloat* restrict c) {
c[0] = a[1] * b[2] - a[2] * b[1];
c[1] = a[2] * b[0] - a[0] * b[2];
c[2] = a[0] * b[1] - a[1] * b[0];
}
inline static void
projectOnLine(const gkFloat* p, const gkFloat* q, gkFloat* v) {
projectOnLine(const gkFloat* restrict p, const gkFloat* restrict q, gkFloat* restrict v) {
gkFloat pq[3];
gkFloat tmp;
pq[0] = p[0] - q[0];
@ -181,7 +181,7 @@ projectOnLine(const gkFloat* p, const gkFloat* q, gkFloat* v) {
}
inline static void
projectOnPlane(const gkFloat* p, const gkFloat* q, const gkFloat* r, gkFloat* v) {
projectOnPlane(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r, gkFloat* restrict v) {
gkFloat n[3], pq[3], pr[3];
gkFloat tmp;
@ -201,7 +201,7 @@ projectOnPlane(const gkFloat* p, const gkFloat* q, const gkFloat* r, gkFloat* v)
}
inline static int
hff1(const gkFloat* p, const gkFloat* q) {
hff1(const gkFloat* restrict p, const gkFloat* restrict q) {
gkFloat tmp = 0;
for (int i = 0; i < 3; i++) {
@ -215,7 +215,7 @@ hff1(const gkFloat* p, const gkFloat* q) {
}
inline static int
hff2(const gkFloat* p, const gkFloat* q, const gkFloat* r) {
hff2(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r) {
gkFloat ntmp[3];
gkFloat n[3], pq[3], pr[3];
gkFloat tmp = 0;
@ -242,7 +242,7 @@ hff2(const gkFloat* p, const gkFloat* q, const gkFloat* r) {
}
inline static int
hff3(const gkFloat* p, const gkFloat* q, const gkFloat* r) {
hff3(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r) {
gkFloat n[3], pq[3], pr[3];
gkFloat tmp = 0;
@ -268,8 +268,8 @@ hff3(const gkFloat* p, const gkFloat* q, const gkFloat* r) {
inline static void
S1D(gkSimplex* s, gkFloat* v) {
gkFloat* s1p = s->vrtx[1];
gkFloat* s2p = s->vrtx[0];
const gkFloat* restrict s1p = s->vrtx[1];
const gkFloat* restrict s2p = s->vrtx[0];
if (hff1(s1p, s2p)) {
projectOnLine(s1p, s2p, v); // Update v, no need to update s
@ -622,7 +622,7 @@ S3D(gkSimplex* s, gkFloat* v) {
}
inline static void
support(gkPolytope* body, const gkFloat* v) {
support(gkPolytope* restrict body, const gkFloat* restrict v) {
gkFloat s, maxs;
gkFloat* vrt;
int better = -1;
@ -663,7 +663,7 @@ subalgorithm(gkSimplex* s, gkFloat* v) {
}
gkFloat
compute_minimum_distance(gkPolytope bd1, gkPolytope bd2, gkSimplex* s) {
compute_minimum_distance(gkPolytope bd1, gkPolytope bd2, gkSimplex* restrict s) {
int k = 0; /**< Iteration counter */
int i; /**< General purpose counter */
int mk = 25; /**< Maximum number of iterations of the GJK algorithm */