Skip to content

Commit b399e8f

Browse files
committed
fix double to float conversion warning
(and avoid a bunch of divisions)
1 parent ab99da0 commit b399e8f

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

Polyhedron/demo/Polyhedron/create_sphere.h

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void create_flat_sphere(double R,
1414
// Must be a multiple of 360 and 180.
1515
const int rings=18;
1616
const int sectors=38;
17+
const float to_rad = static_cast<float>(CGAL_PI / 180.0);
1718

1819
float T, P;
1920
float x[4],y[4],z[4];
@@ -30,8 +31,8 @@ void create_flat_sphere(double R,
3031
normals_spheres.push_back(0);
3132
normals_spheres.push_back(1);
3233

33-
P = rings*CGAL_PI/180.0;
34-
T = t*CGAL_PI/180.0;
34+
P = rings*to_rad;
35+
T = t*to_rad;
3536
x[1] = sin(P) * cos(T) ;
3637
y[1] = sin(P) * sin(T) ;
3738
z[1] = cos(P);
@@ -44,8 +45,8 @@ void create_flat_sphere(double R,
4445
normals_spheres.push_back(z[1]);
4546

4647
//
47-
P = rings*CGAL_PI/180.0;
48-
T = (t+sectors)*CGAL_PI/180.0;
48+
P = rings*to_rad;
49+
T = (t+sectors)*to_rad;
4950
x[2] = sin(P) * cos(T) ;
5051
y[2] = sin(P) * sin(T) ;
5152
z[2] = cos(P);
@@ -63,8 +64,8 @@ void create_flat_sphere(double R,
6364
for(int t=0; t<360; t+=sectors)
6465
{
6566
//A
66-
P = p*CGAL_PI/180.0;
67-
T = t*CGAL_PI/180.0;
67+
P = p*to_rad;
68+
T = t*to_rad;
6869
x[0] = sin(P) * cos(T) ;
6970
y[0] = sin(P) * sin(T) ;
7071
z[0] = cos(P);
@@ -78,8 +79,8 @@ void create_flat_sphere(double R,
7879
normals_spheres.push_back(z[0]);
7980

8081
//B
81-
P = (p+rings)*CGAL_PI/180.0;
82-
T = t*CGAL_PI/180.0;
82+
P = (p+rings)*to_rad;
83+
T = t*to_rad;
8384
x[1] = sin(P) * cos(T) ;
8485
y[1] = sin(P) * sin(T) ;
8586
z[1] = cos(P);
@@ -92,8 +93,8 @@ void create_flat_sphere(double R,
9293
normals_spheres.push_back(z[1]);
9394

9495
//C
95-
P = p*CGAL_PI/180.0;
96-
T = (t+sectors)*CGAL_PI/180.0;
96+
P = p*to_rad;
97+
T = (t+sectors)*to_rad;
9798
x[2] = sin(P) * cos(T) ;
9899
y[2] = sin(P) * sin(T) ;
99100
z[2] = cos(P);
@@ -106,8 +107,8 @@ void create_flat_sphere(double R,
106107
normals_spheres.push_back(y[2]);
107108
normals_spheres.push_back(z[2]);
108109
//D
109-
P = (p+rings)*CGAL_PI/180.0;
110-
T = (t+sectors)*CGAL_PI/180.0;
110+
P = (p+rings)*to_rad;
111+
T = (t+sectors)*to_rad;
111112
x[3] = sin(P) * cos(T) ;
112113
y[3] = sin(P) * sin(T) ;
113114
z[3] = cos(P);
@@ -149,8 +150,8 @@ void create_flat_sphere(double R,
149150
normals_spheres.push_back(-1);
150151

151152

152-
P = (180-rings)*CGAL_PI/180.0;
153-
T = t*CGAL_PI/180.0;
153+
P = (180-rings)*to_rad;
154+
T = t*to_rad;
154155
x[1] = sin(P) * cos(T) ;
155156
y[1] = sin(P) * sin(T) ;
156157
z[1] = cos(P);
@@ -163,8 +164,8 @@ void create_flat_sphere(double R,
163164
normals_spheres.push_back(z[1]);
164165

165166

166-
P = (180-rings)*CGAL_PI/180.0;
167-
T = (t+sectors)*CGAL_PI/180.0;
167+
P = (180-rings)*to_rad;
168+
T = (t+sectors)*to_rad;
168169
x[2] = sin(P) * cos(T) ;
169170
y[2] = sin(P) * sin(T) ;
170171
z[2] = cos(P);
@@ -189,6 +190,7 @@ void create_flat_and_wire_sphere(double R,
189190
// Must be a multiple of 360 and 180.
190191
const int rings=18;
191192
const int sectors=38;
193+
const float to_rad = static_cast<float>(CGAL_PI / 180.0);
192194

193195
create_flat_sphere(R, positions_spheres, normals_spheres);
194196

@@ -202,8 +204,8 @@ void create_flat_and_wire_sphere(double R,
202204
positions_wire_spheres.push_back(0);
203205
positions_wire_spheres.push_back(R);
204206

205-
P = rings*CGAL_PI/180.0;
206-
T = t*CGAL_PI/180.0;
207+
P = rings*to_rad;
208+
T = t*to_rad;
207209
x[1] = sin(P) * cos(T) ;
208210
y[1] = sin(P) * sin(T) ;
209211
z[1] = cos(P);
@@ -217,8 +219,8 @@ void create_flat_and_wire_sphere(double R,
217219
positions_wire_spheres.push_back(R * z[1]);
218220

219221
//
220-
P = rings*CGAL_PI/180.0;
221-
T = (t+sectors)*CGAL_PI/180.0;
222+
P = rings*to_rad;
223+
T = (t+sectors)*to_rad;
222224
x[2] = sin(P) * cos(T) ;
223225
y[2] = sin(P) * sin(T) ;
224226
z[2] = cos(P);
@@ -240,29 +242,29 @@ void create_flat_and_wire_sphere(double R,
240242
for(int t=0; t<360; t+=sectors)
241243
{
242244
//A
243-
P = p*CGAL_PI/180.0;
244-
T = t*CGAL_PI/180.0;
245+
P = p*to_rad;
246+
T = t*to_rad;
245247
x[0] = sin(P) * cos(T) ;
246248
y[0] = sin(P) * sin(T) ;
247249
z[0] = cos(P);
248250

249251
//B
250-
P = (p+rings)*CGAL_PI/180.0;
251-
T = t*CGAL_PI/180.0;
252+
P = (p+rings)*to_rad;
253+
T = t*to_rad;
252254
x[1] = sin(P) * cos(T) ;
253255
y[1] = sin(P) * sin(T) ;
254256
z[1] = cos(P);
255257

256258
//C
257-
P = p*CGAL_PI/180.0;
258-
T = (t+sectors)*CGAL_PI/180.0;
259+
P = p*to_rad;
260+
T = (t+sectors)*to_rad;
259261
x[2] = sin(P) * cos(T) ;
260262
y[2] = sin(P) * sin(T) ;
261263
z[2] = cos(P);
262264

263265
//D
264-
P = (p+rings)*CGAL_PI/180.0;
265-
T = (t+sectors)*CGAL_PI/180.0;
266+
P = (p+rings)*to_rad;
267+
T = (t+sectors)*to_rad;
266268
x[3] = sin(P) * cos(T) ;
267269
y[3] = sin(P) * sin(T) ;
268270
z[3] = cos(P);
@@ -313,14 +315,14 @@ void create_flat_and_wire_sphere(double R,
313315
//Bottom of the sphere
314316
for(int t=0; t<360; t+=sectors)
315317
{
316-
P = (180-rings)*CGAL_PI/180.0;
317-
T = t*CGAL_PI/180.0;
318+
P = (180-rings)*to_rad;
319+
T = t*to_rad;
318320
x[1] = sin(P) * cos(T) ;
319321
y[1] = sin(P) * sin(T) ;
320322
z[1] = cos(P);
321323

322-
P = (180-rings)*CGAL_PI/180.0;
323-
T = (t+sectors)*CGAL_PI/180.0;
324+
P = (180-rings)*to_rad;
325+
T = (t+sectors)*to_rad;
324326
x[2] = sin(P) * cos(T) ;
325327
y[2] = sin(P) * sin(T) ;
326328
z[2] = cos(P);

0 commit comments

Comments
 (0)