commit 3e8307a2b0bbea497ec1f282ec853ed63e6db78d
parent a2e88200a6d586ec2ad0f8f06362843b9879eff3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 23 Apr 2025 19:15:25 +0200
Fix vertex registration
The function that compares vertices was not working correctly: it was
converting the first component of the first input argument to char
instead of converting the result of the equality by component. And the
problem was not highlighted by the tests that used coordinates that can
be encoded as char.
This commit updates the tests to reveal the problem and corrects the
comparison function accordingly.
Diffstat:
4 files changed, 75 insertions(+), 75 deletions(-)
diff --git a/src/sstl_c.h b/src/sstl_c.h
@@ -43,9 +43,9 @@ static INLINE char
eq_vertex(const struct vertex* a, const struct vertex* b)
{
return (char)
- a->xyz[0] == b->xyz[0]
- && a->xyz[1] == b->xyz[1]
- && a->xyz[2] == b->xyz[2];
+ ( a->xyz[0] == b->xyz[0]
+ && a->xyz[1] == b->xyz[1]
+ && a->xyz[2] == b->xyz[2]);
}
/* Declare the hash table that map a vertex to its index */
diff --git a/src/test_sstl_load_ascii.c b/src/test_sstl_load_ascii.c
@@ -329,29 +329,29 @@ check_tetrahedron(struct sstl* sstl)
" facet normal 0.0 -1.0 0.0\n",
" outer loop\n",
" vertex 0.0 0.0 0.0\n",
- " vertex 1.0 0.0 0.0\n",
- " vertex 0.0 0.0 1.0\n",
+ " vertex 0.1 0.0 0.0\n",
+ " vertex 0.0 0.0 0.1\n",
" endloop\n",
" endfacet\n",
" facet normal 0.0 0.0 -1.0\n",
" outer loop\n",
" vertex 0.0 0.0 0.0\n",
- " vertex 0.0 1.0 0.0\n",
- " vertex 1.0 0.0 0.0\n",
+ " vertex 0.0 0.1 0.0\n",
+ " vertex 0.1 0.0 0.0\n",
" endloop\n",
" endfacet\n",
" facet normal -1.0 0.0 0.0\n",
" outer loop\n",
" vertex 0.0 0.0 0.0\n",
- " vertex 0.0 0.0 1.0\n",
- " vertex 0.0 1.0 0.0\n",
+ " vertex 0.0 0.0 0.1\n",
+ " vertex 0.0 0.1 0.0\n",
" endloop\n",
" endfacet\n",
" facet normal 0.577 0.577 0.577\n",
" outer loop\n",
- " vertex 1.0 0.0 0.0\n",
- " vertex 0.0 1.0 0.0\n",
- " vertex 0.0 0.0 1.0\n",
+ " vertex 0.1 0.0 0.0\n",
+ " vertex 0.0 0.1 0.0\n",
+ " vertex 0.0 0.0 0.1\n",
" endloop\n",
" endfacet\n",
"endsolid\n"
@@ -382,18 +382,18 @@ check_tetrahedron(struct sstl* sstl)
CHK(desc.vertices_count == 4);
CHK(desc.triangles_count == 4);
- CHK(f3_eq(desc.vertices + desc.indices[0]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[1]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[2]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[3]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[4]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[5]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[6]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[7]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[8]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[9]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[10]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[11]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[0]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[1]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[2]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[3]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[4]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[5]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[6]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[7]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[8]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[9]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[10]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[11]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
CHK(f3_eq(desc.normals + 0*3, f3(v, 0.f,-1.f, 0.f)) == 1);
CHK(f3_eq(desc.normals + 1*3, f3(v, 0.f, 0.f,-1.f)) == 1);
diff --git a/src/test_sstl_load_binary.c b/src/test_sstl_load_binary.c
@@ -276,28 +276,28 @@ check_tetrahedron(struct sstl* sstl)
CHK(fwrite(header, sizeof(header), 1, fp) == 1);
CHK(fwrite(&ntris, sizeof(ntris), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f,-1.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 0.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 1.f, 0.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 0.f, 1.f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f,-1.0f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.0f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.1f, 0.0f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.0f, 0.1f), sizeof(v), 1, fp) == 1);
CHK(fwrite(&nattrs, sizeof(nattrs), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 0.f,-1.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 0.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 1.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 1.f, 0.f, 0.f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.0f,-1.f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.0f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.1f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.1f, 0.0f, 0.0f), sizeof(v), 1, fp) == 1);
CHK(fwrite(&nattrs, sizeof(nattrs), 1, fp) == 1);
- CHK(fwrite(f3(v,-1.f, 0.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 0.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 0.f, 1.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 1.f, 0.f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v,-1.0f, 0.0f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.0f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.0f, 0.1f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.1f, 0.0f), sizeof(v), 1, fp) == 1);
CHK(fwrite(&nattrs, sizeof(nattrs), 1, fp) == 1);
CHK(fwrite(f3(v, 0.577f, 0.577f, 0.577f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 1.f, 0.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 1.f, 0.f), sizeof(v), 1, fp) == 1);
- CHK(fwrite(f3(v, 0.f, 0.f, 1.f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.1f, 0.0f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.1f, 0.0f), sizeof(v), 1, fp) == 1);
+ CHK(fwrite(f3(v, 0.0f, 0.0f, 0.1f), sizeof(v), 1, fp) == 1);
CHK(fwrite(&nattrs, sizeof(nattrs), 1, fp) == 1);
rewind(fp);
@@ -312,18 +312,18 @@ check_tetrahedron(struct sstl* sstl)
CHK(desc.vertices_count == 4);
CHK(desc.triangles_count == 4);
- CHK(f3_eq(desc.vertices + desc.indices[0]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[1]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[2]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[3]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[4]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[5]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[6]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[7]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[8]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[9]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[10]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[11]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[0]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[1]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[2]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[3]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[4]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[5]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[6]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[7]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[8]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[9]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[10]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[11]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
CHK(f3_eq(desc.normals + 0*3, f3(v, 0.f,-1.f, 0.f)) == 1);
CHK(f3_eq(desc.normals + 1*3, f3(v, 0.f, 0.f,-1.f)) == 1);
diff --git a/src/test_sstl_writer.c b/src/test_sstl_writer.c
@@ -162,27 +162,27 @@ check_tetrahedron(struct sstl* sstl, const enum sstl_type type)
CHK(sstl_writer_create(&args, &writer) == RES_OK);
f3(facet.normal, 0.f,-1.f, 0.f);
- f3(facet.vertices[0], 0.f, 0.f, 0.f);
- f3(facet.vertices[1], 1.f, 0.f, 0.f);
- f3(facet.vertices[2], 0.f, 0.f, 1.f);
+ f3(facet.vertices[0], 0.0f, 0.0f, 0.0f);
+ f3(facet.vertices[1], 0.1f, 0.0f, 0.0f);
+ f3(facet.vertices[2], 0.0f, 0.0f, 0.1f);
CHK(sstl_write_facet(writer, &facet) == RES_OK);
f3(facet.normal, 0.f, 0.f, -1.f);
- f3(facet.vertices[0], 0.f, 0.f, 0.f);
- f3(facet.vertices[1], 0.f, 1.f, 0.f);
- f3(facet.vertices[2], 1.f, 0.f, 0.f);
+ f3(facet.vertices[0], 0.0f, 0.0f, 0.0f);
+ f3(facet.vertices[1], 0.0f, 0.1f, 0.0f);
+ f3(facet.vertices[2], 0.1f, 0.0f, 0.0f);
CHK(sstl_write_facet(writer, &facet) == RES_OK);
f3(facet.normal,-1.f, 0.f, 0.f);
- f3(facet.vertices[0], 0.f, 0.f, 0.f);
- f3(facet.vertices[1], 0.f, 0.f, 1.f);
- f3(facet.vertices[2], 0.f, 1.f, 0.f);
+ f3(facet.vertices[0], 0.0f, 0.0f, 0.0f);
+ f3(facet.vertices[1], 0.0f, 0.0f, 0.1f);
+ f3(facet.vertices[2], 0.0f, 0.1f, 0.0f);
CHK(sstl_write_facet(writer, &facet) == RES_OK);
f3(facet.normal, 0.577f, 0.577f, 0.577f);
- f3(facet.vertices[0], 1.f, 0.f, 0.f);
- f3(facet.vertices[1], 0.f, 1.f, 0.f);
- f3(facet.vertices[2], 0.f, 0.f, 1.f);
+ f3(facet.vertices[0], 0.1f, 0.0f, 0.0f);
+ f3(facet.vertices[1], 0.0f, 0.1f, 0.0f);
+ f3(facet.vertices[2], 0.0f, 0.0f, 0.1f);
CHK(sstl_write_facet(writer, &facet) == RES_OK);
CHK(sstl_writer_ref_put(writer) == RES_OK);
@@ -198,18 +198,18 @@ check_tetrahedron(struct sstl* sstl, const enum sstl_type type)
CHK(desc.vertices_count == 4);
CHK(desc.triangles_count == 4);
- CHK(f3_eq(desc.vertices + desc.indices[0]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[1]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[2]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[3]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[4]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[5]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[6]*3, f3(v, 0.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[7]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[8]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[9]*3, f3(v, 1.f, 0.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[10]*3, f3(v, 0.f, 1.f, 0.f)) == 1);
- CHK(f3_eq(desc.vertices + desc.indices[11]*3, f3(v, 0.f, 0.f, 1.f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[0]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[1]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[2]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[3]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[4]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[5]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[6]*3, f3(v, 0.0f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[7]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[8]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[9]*3, f3(v, 0.1f, 0.0f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[10]*3, f3(v, 0.0f, 0.1f, 0.0f)) == 1);
+ CHK(f3_eq(desc.vertices + desc.indices[11]*3, f3(v, 0.0f, 0.0f, 0.1f)) == 1);
CHK(f3_eq(desc.normals + 0*3, f3(v, 0.f,-1.f, 0.f)) == 1);
CHK(f3_eq(desc.normals + 1*3, f3(v, 0.f, 0.f,-1.f)) == 1);