Rename gmio_vec3 structs

*gmio_vec3_f32 -> gmio_vec3f
*gmio_vec3_f64 -> gmio_vec3d
This commit is contained in:
Hugues Delorme 2016-03-14 16:31:48 +01:00
parent 2764e77c56
commit 2f873e3089
16 changed files with 114 additions and 106 deletions

View File

@ -43,16 +43,16 @@ static unsigned totalTriangleCount(const aiScene* scene)
return meshnum;
}
GMIO_INLINE void copy_gmio_vec3_f32(
aiVector3D* vec3, const gmio_vec3_f32& coords)
GMIO_INLINE void copy_gmio_vec3f(
aiVector3D* vec3, const gmio_vec3f& coords)
{
*vec3 = *((aiVector3D*)&coords);
}
GMIO_INLINE void copy_aiVector3D(
gmio_vec3_f32* coords, const aiVector3D& vec3)
gmio_vec3f* coords, const aiVector3D& vec3)
{
*coords = *((gmio_vec3_f32*)&vec3);
*coords = *((gmio_vec3f*)&vec3);
}
namespace BmkAssimp {
@ -198,13 +198,13 @@ static void add_triangle(
aiVector3D* vp = &pMesh->mVertices[tri_id * 3];
aiVector3D* vn = &pMesh->mNormals[tri_id * 3];
copy_gmio_vec3_f32(vn, triangle->n);
copy_gmio_vec3f(vn, triangle->n);
*(vn+1) = *vn;
*(vn+2) = *vn;
copy_gmio_vec3_f32(vp, triangle->v1);
copy_gmio_vec3_f32(vp+1, triangle->v2);
copy_gmio_vec3_f32(vp+2, triangle->v3);
copy_gmio_vec3f(vp, triangle->v1);
copy_gmio_vec3f(vp+1, triangle->v2);
copy_gmio_vec3f(vp+2, triangle->v3);
if (helper->hasToCountTriangle)
++(helper->totalTriangleCount);

View File

@ -66,7 +66,7 @@ static void my_3d_mesh__copy_triangle(
{ /* Copy new triangle */
struct my_3d_triangle* my_tri = &my_mesh->triangle_array[triangle_id];
const struct gmio_vec3_f32* tri_vertices = &triangle->v1;
const struct gmio_vec3f* tri_vertices = &triangle->v1;
int i;
for (i = 0; i < 3; ++i) {
my_tri->vertex[i].coords[0] = tri_vertices[i].x;

View File

@ -25,7 +25,7 @@ static void my_3d_mesh__get_triangle(
{
const struct my_3d_mesh* my_mesh = (const struct my_3d_mesh*)cookie;
const struct my_3d_triangle* my_tri = &my_mesh->triangle_array[tri_id];
struct gmio_vec3_f32* tri_vertices = &triangle->v1;
struct gmio_vec3f* tri_vertices = &triangle->v1;
int i;
for (i = 0; i < 3; ++i) {
tri_vertices[i].x = (float)my_tri->vertex[i].coords[0];

View File

@ -18,29 +18,29 @@
#include "../global.h"
/*! Computes in-place cross product of float32 coords (ux,uy,uz) ^ (vx,vy,vz) */
GMIO_INLINE void gmio_cross_product_f32(
float ux, float uy, float uz,
float vx, float vy, float vz,
float* nx, float* ny, float* nz);
/*! Computes in-place cross product of two gmio_vec3f objects */
GMIO_INLINE void gmio_vec3f_cross_product(
const struct gmio_vec3f* u,
const struct gmio_vec3f* v,
struct gmio_vec3f* n);
/*! Computes in-place cross product of float64 coords (ux,uy,uz) ^ (vx,vy,vz) */
GMIO_INLINE void gmio_cross_product_f64(
double ux, double uy, double uz,
double vx, double vy, double vz,
double* nx, double* ny, double* nz);
/*! Computes in-place cross product of two gmio_vec3d objects */
GMIO_INLINE void gmio_vec3d_cross_product(
const struct gmio_vec3d* u,
const struct gmio_vec3d* v,
struct gmio_vec3d* n);
/*! Returns the squared length of float32 vector (x, y, z) */
GMIO_INLINE float gmio_sqr_length_f32(float x, float y, float z);
/*! Returns the squared length of a gmio_vec3f object */
GMIO_INLINE float gmio_vec3f_sqr_length(const struct gmio_vec3f* v);
/*! Returns the squared length of float64 vector (x, y, z) */
GMIO_INLINE double gmio_sqr_length_f64(double x, double y, double z);
/*! Returns the squared length of a gmio_vec3d object */
GMIO_INLINE double gmio_vec3d_sqr_length(const struct gmio_vec3d* v);
/*! Normalizes in-place the float32 (x,y,z) coords */
GMIO_INLINE void gmio_normalize_f32(float* x, float* y, float* z);
/*! Normalizes in-place a gmio_vec3f object */
GMIO_INLINE void gmio_vec3f_normalize(struct gmio_vec3f* v);
/*! Normalizes in-place the float64 (x,y,z) coords */
GMIO_INLINE void gmio_normalize_f64(double* x, double* y, double* z);
/*! Normalizes in-place a gmio_vec3d object */
GMIO_INLINE void gmio_vec3d_normalize(struct gmio_vec3d* v);
/*
* Implementation
@ -48,51 +48,61 @@ GMIO_INLINE void gmio_normalize_f64(double* x, double* y, double* z);
#include <math.h>
void gmio_cross_product_f32(
float ux, float uy, float uz,
float vx, float vy, float vz,
float* nx, float* ny, float* nz)
void gmio_vec3f_cross_product(
const struct gmio_vec3f* u,
const struct gmio_vec3f* v,
struct gmio_vec3f* n)
{
*nx = uy*vz - uz*vx;
*ny = uz*vx - ux*vz;
*nz = ux*vy - uy*vx;
gmio_normalize_f32(nx, ny, nz);
const float ux = u->x, uy = u->y, uz = u->z;
const float vx = v->x, vy = v->y, vz = v->z;
n->x = uy*vz - uz*vx;
n->y = uz*vx - ux*vz;
n->z = ux*vy - uy*vx;
gmio_vec3f_normalize(n);
}
void gmio_cross_product_f64(
double ux, double uy, double uz,
double vx, double vy, double vz,
double* nx, double* ny, double* nz)
void gmio_vec3d_cross_product(
const struct gmio_vec3d* u,
const struct gmio_vec3d* v,
struct gmio_vec3d* n)
{
*nx = uy*vz - uz*vx;
*ny = uz*vx - ux*vz;
*nz = ux*vy - uy*vx;
gmio_normalize_f64(nx, ny, nz);
const double ux = u->x, uy = u->y, uz = u->z;
const double vx = v->x, vy = v->y, vz = v->z;
n->x = uy*vz - uz*vx;
n->y = uz*vx - ux*vz;
n->z = ux*vy - uy*vx;
gmio_vec3d_normalize(n);
}
float gmio_sqr_length_f32(float x, float y, float z)
{ return x*x + y*y + z*z; }
double gmio_sqr_length_f64(double x, double y, double z)
{ return x*x + y*y + z*z; }
void gmio_normalize_f32(float* x, float* y, float* z)
float gmio_vec3f_sqr_length(const struct gmio_vec3f* v)
{
const float d = (float)sqrt(gmio_sqr_length_f32(*x, *y, *z));
const float vx = v->x, vy = v->y, vz = v->z;
return vx*vx + vy*vy + vz*vz;
}
double gmio_vec3d_sqr_length(const struct gmio_vec3d* v)
{
const double vx = v->x, vy = v->y, vz = v->z;
return vx*vx + vy*vy + vz*vz;
}
void gmio_vec3f_normalize(struct gmio_vec3f* v)
{
const float d = (float)sqrt(gmio_vec3f_sqr_length(v));
if (d > 0.f) {
*x /= d;
*y /= d;
*z /= d;
v->x /= d;
v->y /= d;
v->z /= d;
}
}
void gmio_normalize_f64(double* x, double* y, double* z)
void gmio_vec3d_normalize(struct gmio_vec3d* v)
{
const double d = sqrt(gmio_sqr_length_f64(*x, *y, *z));
const double d = sqrt(gmio_vec3d_sqr_length(v));
if (d > 0.) {
*x /= d;
*y /= d;
*z /= d;
v->x /= d;
v->y /= d;
v->z /= d;
}
}

View File

@ -23,16 +23,16 @@
#ifndef GMIO_CORE_VECGEOM_H
#define GMIO_CORE_VECGEOM_H
/*! Vector of three float32 coords */
struct gmio_vec3_f32
/*! Vector of three float coords */
struct gmio_vec3f
{
float x;
float y;
float z;
};
/*! Vector of three float64 coords */
struct gmio_vec3_f64
/*! Vector of three double coords */
struct gmio_vec3d
{
double x;
double y;

View File

@ -119,7 +119,7 @@ GMIO_INLINE char* gmio_write_stdio_format(
GMIO_INLINE char* gmio_write_coords(
char* buffer,
const char* coords_format,
const struct gmio_vec3_f32* coords)
const struct gmio_vec3f* coords)
{
return buffer + sprintf(buffer,
coords_format, coords->x, coords->y, coords->z);

View File

@ -27,7 +27,7 @@
enum gmio_stl_constants
{
/*! Compact size of a gmio_vec3_f32 object */
/*! Compact size of a gmio_vec3f object */
GMIO_STL_COORDS_RAWSIZE = (3 * sizeof(float)),
/*! Compact size of a gmio_stl_triangle object, STL ascii format */

View File

@ -33,11 +33,6 @@
enum { GMIO_FIXED_BUFFER_SIZE = 1024 };
GMIO_INLINE float gmio_sqrlen(const struct gmio_vec3_f32* c)
{
return gmio_sqr_length_f32(c->x, c->y, c->z);
}
/* Does \p str contains <SPC>token ? */
static bool gmio_str_has_token(const char* str, const char* token)
{
@ -72,7 +67,9 @@ static enum gmio_stl_format gmio_stlb_format(
memcpy(&tri,
buff + GMIO_STLB_HEADER_SIZE + 4,
GMIO_STLB_TRIANGLE_RAWSIZE);
if (gmio_float32_ulp_equals(gmio_sqrlen(&tri.n), 1.f, 100)) {
if (gmio_float32_ulp_equals(
gmio_vec3f_sqr_length(&tri.n), 1.f, 100))
{
#ifdef GMIO_HOST_IS_BIG_ENDIAN
return GMIO_STL_FORMAT_BINARY_BE;
#else
@ -80,7 +77,9 @@ static enum gmio_stl_format gmio_stlb_format(
#endif
}
gmio_stl_triangle_bswap(&tri);
if (gmio_float32_ulp_equals(gmio_sqrlen(&tri.n), 1.f, 100)) {
if (gmio_float32_ulp_equals(
gmio_vec3f_sqr_length(&tri.n), 1.f, 100))
{
#ifdef GMIO_HOST_IS_BIG_ENDIAN
return GMIO_STL_FORMAT_BINARY_LE;
#else

View File

@ -17,10 +17,10 @@
#include "../gmio_core/internal/vecgeom_utils.h"
GMIO_INLINE struct gmio_vec3_f32 gmio_vec3_f32_diff(
const struct gmio_vec3_f32* u, const struct gmio_vec3_f32* v)
GMIO_INLINE struct gmio_vec3f gmio_vec3f_sub(
const struct gmio_vec3f* u, const struct gmio_vec3f* v)
{
struct gmio_vec3_f32 diff;
struct gmio_vec3f diff;
diff.x = u->x - v->x;
diff.y = u->y - v->y;
diff.z = u->z - v->z;
@ -29,8 +29,7 @@ GMIO_INLINE struct gmio_vec3_f32 gmio_vec3_f32_diff(
void gmio_stl_triangle_compute_normal(struct gmio_stl_triangle* tri)
{
const struct gmio_vec3_f32 u = gmio_vec3_f32_diff(&tri->v2, &tri->v1);
const struct gmio_vec3_f32 v = gmio_vec3_f32_diff(&tri->v3, &tri->v1);
struct gmio_vec3_f32* n = &tri->n;
gmio_cross_product_f32(u.x, u.y, u.z, v.x, v.y, v.z, &n->x, &n->y, &n->z);
const struct gmio_vec3f u = gmio_vec3f_sub(&tri->v2, &tri->v1);
const struct gmio_vec3f v = gmio_vec3f_sub(&tri->v3, &tri->v1);
gmio_vec3f_cross_product(&u, &v, &tri->n);
}

View File

@ -29,10 +29,10 @@
/*! STL mesh triangle */
struct gmio_stl_triangle
{
struct gmio_vec3_f32 n; /*!< Normal vector */
struct gmio_vec3_f32 v1; /*!< Vertex 1 */
struct gmio_vec3_f32 v2; /*!< Vertex 2 */
struct gmio_vec3_f32 v3; /*!< Vertex 3 */
struct gmio_vec3f n; /*!< Normal vector */
struct gmio_vec3f v1; /*!< Vertex 1 */
struct gmio_vec3f v2; /*!< Vertex 2 */
struct gmio_vec3f v3; /*!< Vertex 3 */
uint16_t attribute_byte_count; /*!< Useful only for STL binary format */
};

View File

@ -243,7 +243,7 @@ static bool parse_endsolid(struct gmio_stla_parse_data* data);
/* Parses STL (x,y,z) coords, each coord being separated by whitespaces */
GMIO_INLINE int parse_xyz_coords(
struct gmio_stla_parse_data* data, struct gmio_vec3_f32* coords);
struct gmio_stla_parse_data* data, struct gmio_vec3f* coords);
/* Parses a STL facet, ie. facet ... endfacet */
static int parse_facet(
@ -588,7 +588,7 @@ GMIO_INLINE int is_float_char(const char* str)
|| c == '+';
}
int parse_xyz_coords(struct gmio_stla_parse_data* data, struct gmio_vec3_f32* coords)
int parse_xyz_coords(struct gmio_stla_parse_data* data, struct gmio_vec3f* coords)
{
int errc = 0;
struct gmio_stringstream* sstream = &data->strstream;

View File

@ -36,10 +36,10 @@ static void occmesh_add_triangle(
StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie);
if (tri_id == 0)
mesh->AddDomain();
const gmio_vec3_f32& v1 = tri->v1;
const gmio_vec3_f32& v2 = tri->v2;
const gmio_vec3_f32& v3 = tri->v3;
const gmio_vec3_f32& n = tri->n;
const gmio_vec3f& v1 = tri->v1;
const gmio_vec3f& v2 = tri->v2;
const gmio_vec3f& v3 = tri->v3;
const gmio_vec3f& n = tri->n;
mesh->AddTriangle(mesh->AddOnlyNewVertex(v1.x, v1.y, v1.z),
mesh->AddOnlyNewVertex(v2.x, v2.y, v2.z),
mesh->AddOnlyNewVertex(v3.x, v3.y, v3.z),
@ -47,7 +47,7 @@ static void occmesh_add_triangle(
}
static inline void gmio_stl_occ_copy_xyz(
gmio_vec3_f32* stl_coords, const gp_XYZ& coords)
gmio_vec3f* stl_coords, const gp_XYZ& coords)
{
stl_coords->x = static_cast<float>(coords.X());
stl_coords->y = static_cast<float>(coords.Y());
@ -66,7 +66,7 @@ static void occmesh_get_triangle(
int idV1, idV2, idV3;
double xN, yN, zN;
occTri->GetVertexAndOrientation(idV1, idV2, idV3, xN, yN, zN);
gmio_vec3_f32& n = tri->n;
gmio_vec3f& n = tri->n;
n.x = static_cast<float>(xN);
n.y = static_cast<float>(yN);
n.z = static_cast<float>(zN);

View File

@ -31,9 +31,9 @@ void gmio_string_trim_from_end(char *str, size_t len)
}
}
bool gmio_vec3_f32_equal(
const struct gmio_vec3_f32 *lhs,
const struct gmio_vec3_f32 *rhs,
bool gmio_vec3f_equal(
const struct gmio_vec3f *lhs,
const struct gmio_vec3f *rhs,
uint32_t max_ulp_diff)
{
return gmio_float32_ulp_equals(lhs->x, rhs->x, max_ulp_diff)

View File

@ -25,9 +25,9 @@
void gmio_string_trim_from_end(char* str, size_t len);
/*! Does \p lhs == \p rhs using gmio_float32_ulp_equals() on coords ? */
bool gmio_vec3_f32_equal(
const struct gmio_vec3_f32* lhs,
const struct gmio_vec3_f32* rhs,
bool gmio_vec3f_equal(
const struct gmio_vec3f* lhs,
const struct gmio_vec3f* rhs,
uint32_t max_ulp_diff);
#endif /* GMIO_TESTS_CORE_UTILS_H */

View File

@ -133,10 +133,10 @@ bool gmio_stl_triangle_equal(
const struct gmio_stl_triangle *rhs,
uint32_t max_ulp_diff)
{
return gmio_vec3_f32_equal(&lhs->n, &rhs->n, max_ulp_diff)
&& gmio_vec3_f32_equal(&lhs->v1, &rhs->v1, max_ulp_diff)
&& gmio_vec3_f32_equal(&lhs->v2, &rhs->v2, max_ulp_diff)
&& gmio_vec3_f32_equal(&lhs->v3, &rhs->v3, max_ulp_diff)
return gmio_vec3f_equal(&lhs->n, &rhs->n, max_ulp_diff)
&& gmio_vec3f_equal(&lhs->v1, &rhs->v1, max_ulp_diff)
&& gmio_vec3f_equal(&lhs->v2, &rhs->v2, max_ulp_diff)
&& gmio_vec3f_equal(&lhs->v3, &rhs->v3, max_ulp_diff)
&& lhs->attribute_byte_count == rhs->attribute_byte_count;
}

View File

@ -27,10 +27,10 @@ GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(4127)
const char* test_stl_coords_packing()
{
UTEST_COMPARE_UINT(0, offsetof(struct gmio_vec3_f32, x));
UTEST_COMPARE_UINT(4, offsetof(struct gmio_vec3_f32, y));
UTEST_COMPARE_UINT(8, offsetof(struct gmio_vec3_f32, z));
UTEST_COMPARE_UINT(GMIO_STL_COORDS_RAWSIZE, sizeof(struct gmio_vec3_f32));
UTEST_COMPARE_UINT(0, offsetof(struct gmio_vec3f, x));
UTEST_COMPARE_UINT(4, offsetof(struct gmio_vec3f, y));
UTEST_COMPARE_UINT(8, offsetof(struct gmio_vec3f, z));
UTEST_COMPARE_UINT(GMIO_STL_COORDS_RAWSIZE, sizeof(struct gmio_vec3f));
return NULL;
}