commit 179f51f928e62e2c3a7cf4012b347648d990f1c3
parent 9e4d9c638aef45be83743a43153ab6b4a4bdb66f
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 9 Sep 2022 11:10:24 +0200
Spacing and coding style
Diffstat:
4 files changed, 58 insertions(+), 44 deletions(-)
diff --git a/src/scad.c b/src/scad.c
@@ -96,7 +96,7 @@ error:
filename, res_to_cstr(res));
goto exit;
}
-
+
static res_T
write_binary_stl
(const char* filename,
@@ -164,7 +164,7 @@ error:
filename, res_to_cstr(res));
goto exit;
}
-
+
static res_T
write_stl
(const char* filename,
@@ -274,7 +274,7 @@ scad_stl_export
if(get_device()->need_synchro) {
ERR(scad_synchronize());
}
-
+
sz = geometry->gmsh_dimTags_n;
data = geometry->gmsh_dimTags;
ASSERT(sz > 0 && sz % 2 == 0);
@@ -513,7 +513,7 @@ scad_scene_mesh
gmshModelMeshGenerate(2, &ierr);
ERR(gmsh_err_to_res_T(ierr));
-
+
exit:
return res;
error:
diff --git a/src/scad.h b/src/scad.h
@@ -160,7 +160,7 @@ scad_add_cylinder
(const char* name, /* Can be NULL */
const double xyz[3],
const double axis[3],
- const double rad,
+ const double radius,
const double angle,
struct scad_geometry** cylinder); /* Can be NULL: no handler returned. */
@@ -169,7 +169,7 @@ SCAD_API res_T
scad_add_sphere
(const char* name, /* Can be NULL */
const double xyz[3],
- const double rad,
+ const double radius,
struct scad_geometry** sphere); /* Can be NULL: no handler returned. */
SCAD_API res_T
@@ -209,8 +209,8 @@ scad_intersect_geometries
const size_t tools_count,
struct scad_geometry** out_geometry);
-/* compute boundary intersection (the common part) of in `geometries' and
- * `tools'. */
+/* compute boundary intersection (the common part) of the geometries in
+ * `geometries' and `tools'. */
SCAD_API res_T
scad_geometries_common_boundaries
(const char* name, /* Can be NULL */
diff --git a/src/scad_device.h b/src/scad_device.h
@@ -39,7 +39,7 @@ hash_str(const struct str* a)
#define HTABLE_NAME names
#define HTABLE_DATA struct scad_geometry*
-#define HTABLE_KEY struct str
+#define HTABLE_KEY struct str
#define HTABLE_KEY_FUNCTOR_INIT str_init
#define HTABLE_KEY_FUNCTOR_RELEASE str_release
#define HTABLE_KEY_FUNCTOR_COPY str_copy
@@ -101,7 +101,7 @@ log_warning
__attribute((format(printf, 2, 3)))
#endif
;
-
+
/* Conditionally log a message on the LOG_OUTPUT stream of the device logger,
* with respect to the device verbose flag */
extern LOCAL_SYM void
diff --git a/src/scad_geometry.c b/src/scad_geometry.c
@@ -43,7 +43,7 @@ scad_geometry_create
ASSERT(out_geometry);
str_init(dev->allocator, &str_name);
- if(name) {
+ if(name) {
if(strlen(name) == 0) {
res = RES_BAD_ARG;
log_error(get_device(), "Geometry name '' is invalid.\n");
@@ -59,8 +59,7 @@ scad_geometry_create
}
}
- geom = (struct scad_geometry*)MEM_CALLOC(dev->allocator, 1,
- sizeof(*geom));
+ geom = (struct scad_geometry*)MEM_CALLOC(dev->allocator, 1, sizeof(*geom));
if(!geom) {
res = RES_MEM_ERR;
goto error;
@@ -118,7 +117,7 @@ gather_tags
}
*out_dimTags_n = c;
*out_dimTags = tags;
-
+
exit:
return res;
error:
@@ -341,13 +340,15 @@ scad_add_rectangle
ERR(scad_geometry_create(name, &geom));
geom->gmsh_dimTags_n = 2;
- geom->gmsh_dimTags = malloc(geom->gmsh_dimTags_n * sizeof(int));
- if(! geom->gmsh_dimTags_n) {
+ geom->gmsh_dimTags
+ = malloc(geom->gmsh_dimTags_n * sizeof(*geom->gmsh_dimTags));
+ if(!geom->gmsh_dimTags) {
res = RES_MEM_ERR;
goto error;
}
geom->gmsh_dimTags[0] = 2;
geom->gmsh_dimTags[1] = gmsh_ID;
+
ERR(device_register_tags(geom));
exit:
@@ -384,13 +385,15 @@ scad_add_disk
ERR(scad_geometry_create(name, &geom));
geom->gmsh_dimTags_n = 2;
- geom->gmsh_dimTags = malloc(geom->gmsh_dimTags_n * sizeof(int));
- if(! geom->gmsh_dimTags_n) {
+ geom->gmsh_dimTags
+ = malloc(geom->gmsh_dimTags_n * sizeof(*geom->gmsh_dimTags));
+ if(!geom->gmsh_dimTags) {
res = RES_MEM_ERR;
goto error;
}
geom->gmsh_dimTags[0] = 2;
geom->gmsh_dimTags[1] = gmsh_ID;
+
ERR(device_register_tags(geom));
exit:
@@ -428,7 +431,7 @@ scad_add_polygon
ERR(check_device(FUNC_NAME));
- points = malloc(count * sizeof(int));
+ points = malloc(count * sizeof(*points));
if(!points) {
res = RES_MEM_ERR;
goto error;
@@ -438,7 +441,7 @@ scad_add_polygon
ERR(gmsh_err_to_res_T(ierr));
}
- lines = malloc(count * sizeof(int));
+ lines = malloc(count * sizeof(*lines));
if(!lines) {
res = RES_MEM_ERR;
goto error;
@@ -454,18 +457,20 @@ scad_add_polygon
loop = gmshModelOccAddCurveLoop(lines, count, -1, &ierr);
ERR(gmsh_err_to_res_T(ierr));
- gmsh_ID = gmshModelOccAddPlaneSurface(&loop, 1, -1, &ierr);
+ gmsh_ID = gmshModelOccAddPlaneSurface(&loop, 1, -1, &ierr);
ERR(gmsh_err_to_res_T(ierr));
ERR(scad_geometry_create(name, &geom));
geom->gmsh_dimTags_n = 2;
- geom->gmsh_dimTags = malloc(geom->gmsh_dimTags_n * sizeof(int));
- if(! geom->gmsh_dimTags_n) {
+ geom->gmsh_dimTags
+ = malloc(geom->gmsh_dimTags_n * sizeof(*geom->gmsh_dimTags));
+ if(!geom->gmsh_dimTags) {
res = RES_MEM_ERR;
goto error;
}
geom->gmsh_dimTags[0] = 2;
geom->gmsh_dimTags[1] = gmsh_ID;
+
ERR(device_register_tags(geom));
exit:
@@ -504,13 +509,15 @@ scad_add_box
ERR(scad_geometry_create(name, &geom));
geom->gmsh_dimTags_n = 2;
- geom->gmsh_dimTags = malloc(geom->gmsh_dimTags_n * sizeof(int));
- if(! geom->gmsh_dimTags_n) {
+ geom->gmsh_dimTags
+ = malloc(geom->gmsh_dimTags_n * sizeof(*geom->gmsh_dimTags));
+ if(!geom->gmsh_dimTags) {
res = RES_MEM_ERR;
goto error;
}
geom->gmsh_dimTags[0] = 3;
geom->gmsh_dimTags[1] = gmsh_ID;
+
ERR(device_register_tags(geom));
exit:
@@ -529,7 +536,7 @@ scad_add_cylinder
(const char* name,
const double xyz[3],
const double axis[3],
- const double rad,
+ const double radius,
const double angle,
struct scad_geometry** out_geometry)
{
@@ -537,26 +544,28 @@ scad_add_cylinder
struct scad_geometry* geom = NULL;
res_T res = RES_OK;
- if(!xyz || !axis || rad <= 0 || angle < 0 || angle > 2*PI || !out_geometry) {
+ if(!xyz || !axis || radius <= 0 || angle < 0 || angle > 2*PI || !out_geometry) {
res = RES_BAD_ARG;
goto error;
}
ERR(check_device(FUNC_NAME));
- gmsh_ID = gmshModelOccAddCylinder(SPLIT3(xyz), SPLIT3(axis), rad, -1, angle,
- &ierr);
+ gmsh_ID = gmshModelOccAddCylinder(SPLIT3(xyz), SPLIT3(axis), radius, -1,
+ angle, &ierr);
ERR(gmsh_err_to_res_T(ierr));
ERR(scad_geometry_create(name, &geom));
geom->gmsh_dimTags_n = 2;
- geom->gmsh_dimTags = malloc(geom->gmsh_dimTags_n * sizeof(int));
- if(! geom->gmsh_dimTags_n) {
+ geom->gmsh_dimTags
+ = malloc(geom->gmsh_dimTags_n * sizeof(*geom->gmsh_dimTags));
+ if(!geom->gmsh_dimTags) {
res = RES_MEM_ERR;
goto error;
}
geom->gmsh_dimTags[0] = 3;
geom->gmsh_dimTags[1] = gmsh_ID;
+
ERR(device_register_tags(geom));
exit:
@@ -574,32 +583,35 @@ int
scad_add_sphere
(const char* name,
const double xyz[3],
- const double rad,
+ const double radius,
struct scad_geometry** out_geometry)
{
int ierr, gmsh_ID;
struct scad_geometry* geom = NULL;
res_T res = RES_OK;
- if(!xyz || rad <= 0 || !out_geometry) {
+ if(!xyz || radius <= 0 || !out_geometry) {
res = RES_BAD_ARG;
goto error;
}
ERR(check_device(FUNC_NAME));
- gmsh_ID = gmshModelOccAddSphere(SPLIT3(xyz), rad, -1, -PI/2, PI/2, 2*PI, &ierr);
+ gmsh_ID =
+ gmshModelOccAddSphere(SPLIT3(xyz), radius, -1, -PI/2, PI/2, 2*PI, &ierr);
ERR(gmsh_err_to_res_T(ierr));
ERR(scad_geometry_create(name, &geom));
geom->gmsh_dimTags_n = 2;
- geom->gmsh_dimTags = malloc(geom->gmsh_dimTags_n * sizeof(int));
- if(! geom->gmsh_dimTags_n) {
+ geom->gmsh_dimTags
+ = malloc(geom->gmsh_dimTags_n * sizeof(*geom->gmsh_dimTags));
+ if(!geom->gmsh_dimTags) {
res = RES_MEM_ERR;
goto error;
}
geom->gmsh_dimTags[0] = 3;
geom->gmsh_dimTags[1] = gmsh_ID;
+
ERR(device_register_tags(geom));
exit:
@@ -915,7 +927,7 @@ error:
res_T
scad_geometry_extrude
(const struct scad_geometry* geom,
- const char* name,
+ const char* name,
const double dxdydz[3],
struct scad_geometry** out_geometry)
{
@@ -948,11 +960,11 @@ scad_geometry_extrude
ERR(scad_geometry_create(name, &extrude_geom));
/* keep only 3D entities */
- /* TODO : NOT SURE OF THE CONCEPT */
+ /* TODO : NOT SURE OF THE CONCEPT */
for (i=0; i<tagoutn/2; ++i) {
if (tagout[2*i] == 3) extrude_sz += 2;
}
- extrude_data = malloc(extrude_sz * sizeof(int));
+ extrude_data = malloc(extrude_sz * sizeof(*extrude_data));
if(!extrude_data) {
res = RES_MEM_ERR;
goto error;
@@ -963,7 +975,7 @@ scad_geometry_extrude
extrude_data[2*j] = 3;
extrude_data[2*j+1] = tagout[2*i+1];
++j;
- }
+ }
}
extrude_geom->gmsh_dimTags_n = extrude_sz;
extrude_geom->gmsh_dimTags = extrude_data;
@@ -996,7 +1008,7 @@ scad_geometry_copy
struct scad_geometry* copy = NULL;
res_T res = RES_OK;
- if(!geom){
+ if(!geom) {
res = RES_BAD_ARG;
goto error;
}
@@ -1200,7 +1212,7 @@ scad_step_import
ASSERT(tagoutn % 2 == 0);
ga_sz = tagoutn / 2;
- geom_array = malloc(ga_sz * sizeof(struct scad_geometry*));
+ geom_array = malloc(ga_sz * sizeof(*geom_array));
if(!geom_array) {
res = RES_MEM_ERR;
goto error;
@@ -1214,16 +1226,18 @@ scad_step_import
ERR(scad_geometry_create(str_cget(&strname), geom_array+i));
geom_array[i]->gmsh_dimTags_n = 2;
- geom_array[i]->gmsh_dimTags = malloc(2 * sizeof(int));
+ geom_array[i]->gmsh_dimTags = malloc(geom_array[i]->gmsh_dimTags_n *
+ sizeof(*geom_array[i]->gmsh_dimTags));
if(!geom_array[i]->gmsh_dimTags) {
res = RES_MEM_ERR;
goto error;
}
geom_array[i]->gmsh_dimTags[0] = tagout[2*i];
geom_array[i]->gmsh_dimTags[1] = tagout[2*i+1];
+
ERR(device_register_tags(geom_array[i]));
}
-
+
exit:
if(out_geometry_n) *out_geometry_n = ga_sz ;
if(out_geometry) *out_geometry = geom_array;