commit 7f1ebe8fd29611c5ba2935850d36678e7b5996b3
parent af568056554cdd2b5b044c2db8c113ab7c6f32b1
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 20 Apr 2023 17:40:28 +0200
Increase precision when writing positions in ascii
Diffstat:
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/sstl.c b/src/sstl.c
@@ -560,7 +560,7 @@ load_binary_stream
unsigned triangles_count;
struct solid solid = SOLID_NULL;
unsigned i;
-
+
ASSERT(sstl && stream && stream_name && already_read_count <= 80);
clear(sstl);
@@ -726,13 +726,13 @@ get_sstl_triangle_normal
res = RES_BAD_ARG;
goto error;
}
-
+
OK(sstl_get_desc(sstl, &desc));
if(idx >= desc.triangles_count) {
res = RES_BAD_ARG;
goto error;
}
-
+
ASSERT(3*idx+2 < sa_size(desc.normals));
f3_set(normal, desc.normals + 3*idx);
@@ -757,13 +757,13 @@ get_sstl_triangle_vertices
res = RES_BAD_ARG;
goto error;
}
-
+
OK(sstl_get_desc(sstl, &desc));
if(idx >= desc.triangles_count) {
res = RES_BAD_ARG;
goto error;
}
-
+
for(n = 0; n < 3; n++) {
size_t vtx_idx = desc.indices[3*idx + n];
ASSERT(3*vtx_idx+2 < sa_size(desc.vertices));
@@ -876,11 +876,11 @@ write_stream
res = data->get_triangle_normal(i, data->data, normal);
OKP(fprintf(stream, " facet normal %g %g %g\n", SPLIT3(normal)));
-
+
res = data->get_triangle_vertices(i, data->data, vtx);
OKP(fprintf(stream, " outer loop\n"));
for(n = 0; n < 3; n++) {
- OKP(fprintf(stream, " vertex %g %g %g\n", SPLIT3(vtx[n])));
+ OKP(fprintf(stream, " vertex %.16g %.16g %.16g\n", SPLIT3(vtx[n])));
}
OKP(fprintf(stream, " endloop\n"));
OKP(fprintf(stream, " endfacet\n"));
diff --git a/src/sstl.h b/src/sstl.h
@@ -77,6 +77,8 @@ struct sstl_write_data {
void (*print_error_log)(const void* data, const char* msg, ...);
unsigned triangles_count;
};
+#define SSTL_WRITE_DATA_NULL__ { NULL, NULL, NULL, NULL, NULL, 0 }
+static const struct sstl_write_data SSTL_WRITE_DATA_NULL = SSTL_WRITE_DATA_NULL__;
/* Forward declaration of external types */
struct logger;
@@ -144,7 +146,7 @@ sstl_load_stream
FILE* stream);
/* Create a sstl_write_data from a sstl.
- * The returned descriptor is valid until a new load process */
+ * The result is valid as long as the input sstl is valid */
SSTL_API res_T
sstl_pack_write_data
(const struct sstl* sstl,
diff --git a/src/test_sstl_load.c b/src/test_sstl_load.c
@@ -188,13 +188,13 @@ test_basic(struct sstl* sstl)
file = tmpfile();
CHK(file != NULL);
fwrite(test1, sizeof(char), strlen(test1), file);
-
+
rewind(file);
CHK(sstl_load_stream_ascii(NULL, NULL) == RES_BAD_ARG);
CHK(sstl_load_stream_ascii(sstl, NULL) == RES_BAD_ARG);
CHK(sstl_load_stream_ascii(NULL, file) == RES_BAD_ARG);
CHK(sstl_load_stream_ascii(sstl, file) == RES_OK);
-
+
rewind(file);
CHK(sstl_load_stream_binary(NULL, NULL) == RES_BAD_ARG);
CHK(sstl_load_stream_binary(sstl, NULL) == RES_BAD_ARG);
@@ -238,7 +238,7 @@ test_basic(struct sstl* sstl)
rewind(file);
CHK(sstl_load_stream_binary(sstl,file) == RES_OK);
fclose(file);
-
+
CHK(sstl_get_desc(sstl, &desc) == RES_OK);
CHK(desc.solid_name == NULL);
CHK(desc.vertices_count == 3);