commit 5cf294bdd6b9783476d3b5af5ec4d4dd4fd99686
parent 97c776a31183fa31582e92581f898033ddfc99eb
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 11 Oct 2017 15:37:21 +0200
Fix GCC warnings
Diffstat:
3 files changed, 29 insertions(+), 36 deletions(-)
diff --git a/src/s3dut.h b/src/s3dut.h
@@ -46,8 +46,8 @@ struct s3dut_mesh_data {
};
enum s3dut_ends {
- S3DUT_END_BOTTOM = 1,
- S3DUT_END_TOP = 2
+ S3DUT_END_BOTTOM = BIT(0),
+ S3DUT_END_TOP = BIT(1)
};
/*******************************************************************************
@@ -166,10 +166,8 @@ s3dut_create_truncated_sphere
const double radius, /* In ]0, INF) */
const unsigned nslices, /* # subdivisions around Z axis in [3, INF) */
const unsigned nstacks, /* # subdivisions along Z axis in [2, INF) */
- const double z_range[2], /* mesh only the sphere in the z_range range;
- can be NULL => keep the whole sphere */
- const unsigned close_ends, /* Close truncated ends of the sphere?
- Meaningless if no truncation. */
+ const double z_range[2], /* Clamp the sphere to z_range. NULL <=> no clamp */
+ const unsigned close_ends, /* Combination of s3dut_ends. Ignored if no clamp */
struct s3dut_mesh** sphere);
/* Create a triangulated thick UV sphere centered in 0 discretized in `nslices'
@@ -188,10 +186,8 @@ s3dut_create_thick_truncated_sphere
const double thickness, /* In ]0, INF) */
const unsigned nslices, /* # subdivisions around Z axis in [3, INF) */
const unsigned nstacks, /* # subdivisions along Z axis in [2, INF) */
- const double z_range[2], /* Mesh only the sphere in the z_range range;
- can be NULL => keep the whole sphere */
- const unsigned close_ends, /* Close truncated ends of the sphere?
- Meaningless if no truncation. */
+ const double z_range[2], /* Clamp the sphere to z_range. NULL <=> no clamp */
+ const unsigned close_ends, /* mask of s3dut_ends. Ignored if no clamp */
struct s3dut_mesh** sphere);
#endif /* S3DUT_H */
diff --git a/src/s3dut_cylinder.c b/src/s3dut_cylinder.c
@@ -188,7 +188,7 @@ s3dut_create_thin_cylinder
size_t ntris;
const int close_bottom = close_ends & S3DUT_END_BOTTOM;
const int close_top = close_ends & S3DUT_END_TOP;
- const unsigned nb_closed_ends = (close_bottom ? 1 : 0) + (close_top ? 1 : 0);
+ const unsigned nb_closed_ends = (close_bottom ? 1u : 0) + (close_top ? 1u : 0);
res_T res = RES_OK;
if(radius <= 0 || height <= 0 || nslices < 3 || nstacks < 1 || !mesh) {
@@ -196,10 +196,8 @@ s3dut_create_thin_cylinder
goto error;
}
- nverts = nslices * (nstacks+1) /*#contour verts*/
- + nb_closed_ends; /*#polar verts*/
- ntris = 2*nslices*nstacks /*#contour tris*/
- + nb_closed_ends * nslices; /*#trg fans tris*/
+ nverts = nslices * (nstacks+1)/*#contour*/ + nb_closed_ends/*#polar*/;
+ ntris = 2*nslices*nstacks/*#contour*/ + nb_closed_ends * nslices/*#polar*/;
res = mesh_create(allocator, S3DUT_MESH_CYLINDER, nverts, ntris, &cylinder);
if(res != RES_OK) goto error;
@@ -243,7 +241,7 @@ s3dut_create_thick_cylinder
size_t id_offset;
const int close_bottom = close_ends & S3DUT_END_BOTTOM;
const int close_top = close_ends & S3DUT_END_TOP;
- const unsigned nb_closed_ends = (close_bottom ? 1 : 0) + (close_top ? 1 : 0);
+ const unsigned nb_closed_ends = (close_bottom ? 1u : 0) + (close_top ? 1u : 0);
res_T res = RES_OK;
if(radius <= thickness || height <= 0 || thickness <= 0
@@ -253,10 +251,10 @@ s3dut_create_thick_cylinder
goto error;
}
- nverts = 2 * (nslices * (nstacks+1) /*#contour verts*/
- + nb_closed_ends); /*#polar verts*/
- ntris = 2 * (2 * nslices*nstacks /*#contour tris*/
- + 2 * nslices); /*#trg fans tris, regardless of closedness*/
+ nverts = 2 * (nslices*(nstacks+1)/*#contour*/ + nb_closed_ends/*#polar*/);
+ ntris = 2 *
+ ( 2 * nslices*nstacks /*#contour*/
+ + 2 * nslices/*#trg fans tris, regardless of closedness*/);
res = mesh_create
(allocator, S3DUT_MESH_THICK_CYLINDER, nverts, ntris, &cylinder);
@@ -270,7 +268,7 @@ s3dut_create_thick_cylinder
ids_in = setup_cylinder_indices
(ids_out, 0, nslices, nstacks, close_bottom, close_top, 1);
/* Internal cylinder */
- id_offset = coords_in - coords_out;
+ id_offset = (size_t)(coords_in - coords_out);
ASSERT(id_offset % 3 == 0);
id_offset /= 3;
setup_cylinder_coords(coords_in,
diff --git a/src/s3dut_sphere.c b/src/s3dut_sphere.c
@@ -36,7 +36,7 @@ setup_sphere_coords
double step_theta;
const int top_truncated = z_range && z_range[1] < +radius;
const int bottom_truncated = z_range && z_range[0] > -radius;
- const unsigned nb_truncated = top_truncated + bottom_truncated;
+ const unsigned nb_truncated = (unsigned)(top_truncated + bottom_truncated);
const int close_top = top_truncated && (close_ends & S3DUT_END_TOP);
const int close_bottom = bottom_truncated && (close_ends & S3DUT_END_BOTTOM);
const unsigned nrings = nstacks - 1 + nb_truncated;
@@ -123,9 +123,9 @@ setup_sphere_indices
{
const int top_truncated = z_range && z_range[1] < +radius;
const int bottom_truncated = z_range && z_range[0] > -radius;
- const unsigned nb_truncated = top_truncated + bottom_truncated;
const int close_top = top_truncated && (close_ends & S3DUT_END_TOP);
const int close_bottom = bottom_truncated && (close_ends & S3DUT_END_BOTTOM);
+ const unsigned nb_truncated = (unsigned)(top_truncated + bottom_truncated);
const unsigned nrings = nstacks - 1 + nb_truncated;
size_t ibottom;
size_t itop;
@@ -219,10 +219,10 @@ sphere_accum_counts
{
const int top_truncated = z_range && z_range[1] < +radius;
const int bottom_truncated = z_range && z_range[0] > -radius;
- const unsigned nb_truncated = top_truncated + bottom_truncated;
const int close_top = top_truncated && (close_ends & S3DUT_END_TOP);
const int close_bottom = bottom_truncated && (close_ends & S3DUT_END_BOTTOM);
- const unsigned nb_closed_ends = (close_top ? 1 : 0) + (close_bottom ? 1 : 0);
+ const unsigned nb_truncated = (unsigned)(top_truncated + bottom_truncated);
+ const unsigned nb_closed_ends = (close_top ? 1u : 0) + (close_bottom ? 1u : 0);
const unsigned nb_pole_vrtx = nb_closed_ends + (2 - nb_truncated);
ASSERT(nrings && ntris && nverts);
*nrings = nstacks - 1 + nb_truncated;;
@@ -274,10 +274,10 @@ s3dut_create_truncated_sphere
struct s3dut_mesh* sphere = NULL;
const int top_truncated = z_range && z_range[1] < +radius;
const int bottom_truncated = z_range && z_range[0] > -radius;
- const unsigned nb_truncated = top_truncated + bottom_truncated;
const int close_top = top_truncated && (close_ends & S3DUT_END_TOP);
const int close_bottom = bottom_truncated && (close_ends & S3DUT_END_BOTTOM);
- const unsigned nb_closed_ends = (close_top ? 1 : 0) + (close_bottom ? 1 : 0);
+ const unsigned nb_truncated = (unsigned)(top_truncated + bottom_truncated);
+ const unsigned nb_closed_ends = (close_top ? 1u : 0) + (close_bottom ? 1u : 0);
const unsigned nb_pole_vrtx = nb_closed_ends + (2 - nb_truncated);
const unsigned nrings = nstacks - 1 + nb_truncated;
const size_t nverts = nslices*nrings/* #contour verts*/
@@ -286,7 +286,7 @@ s3dut_create_truncated_sphere
+ nb_pole_vrtx*nslices/* #polar tris*/;
double* coords;
res_T res = RES_OK;
- ASSERT(0 <= nb_truncated && nb_truncated <= 2);
+ ASSERT(nb_truncated <= 2);
if(radius <= 0 || nslices < 3 || nstacks < 2 || !mesh
|| (z_range && z_range[0] >= z_range[1])) {
@@ -345,22 +345,22 @@ s3dut_create_thick_truncated_sphere
= z_range && (z_range[0] > -internal_radius) && ! close_bottom;
unsigned external_nrings;
unsigned internal_nrings;
- const unsigned nb_seams = top_seam + bottom_seam;
+ const unsigned nb_seams = (unsigned)(top_seam + bottom_seam);
size_t nverts = 0;
size_t ntris = 0;
double z_internal_range[2];
res_T res = RES_OK;
if(radius <= thickness || thickness <= 0 || nslices < 3 || nstacks < 2
- || !mesh || (z_range && z_range[0] >= z_range[1])) {
+ || !mesh || (z_range && z_range[0] >= z_range[1])) {
return RES_BAD_ARG;
}
/* Special case when a single sphere is truncated */
- if (top_truncated && (z_range[1] >= internal_radius)) {
+ if(top_truncated && (z_range[1] >= internal_radius)) {
close_ends |= S3DUT_END_TOP; /* close the external sphere's top end */
}
- if (bottom_truncated && (z_range[0] <= -internal_radius)) {
+ if(bottom_truncated && (z_range[0] <= -internal_radius)) {
close_ends |= S3DUT_END_BOTTOM; /* close the external sphere's bottom end */
}
z_internal_range[0] = (bottom_truncated && !close_bottom)
@@ -373,7 +373,7 @@ s3dut_create_thick_truncated_sphere
close_ends, &internal_nrings, &ntris, &nverts);
ntris += 2 * nb_seams * nslices; /* # seam tris */
res = mesh_create(allocator, S3DUT_MESH_THICK_SPHERE, nverts, ntris, &sphere);
- if (res != RES_OK) goto error;
+ if(res != RES_OK) goto error;
coords = darray_double_data_get(&sphere->coords);
ids_out = darray_size_t_data_get(&sphere->ids);
@@ -384,7 +384,7 @@ s3dut_create_thick_truncated_sphere
ids_in = setup_sphere_indices(ids_out, 0, nslices, nstacks, radius, z_range,
close_ends, 1);
/* Internal sphere */
- id_offset = coords - prev_coords;
+ id_offset = (size_t)(coords - prev_coords);
ASSERT(id_offset % 3 == 0);
id_offset /= 3;
setup_sphere_coords(allocator, &coords, radius - thickness, z_internal_range,
@@ -409,4 +409,4 @@ error:
sphere = NULL;
}
goto exit;
-}
-\ No newline at end of file
+}