Avoid -Wdouble-promotion warnings

This commit is contained in:
Paul Cornett
2020-10-14 11:07:55 -07:00
parent 97655e5b21
commit b5a554b9a6
44 changed files with 208 additions and 201 deletions

View File

@@ -1205,7 +1205,7 @@ void MyCanvas::DrawGraphics(wxGraphicsContext* gc)
{
gc->PushState(); // save this new current state so we can
// pop back to it at the end of the loop
wxImage::RGBValue val = wxImage::HSVtoRGB(wxImage::HSVValue(float(angle)/360, 1, 1));
wxImage::RGBValue val = wxImage::HSVtoRGB(wxImage::HSVValue(angle / 360.0, 1, 1));
gc->SetBrush(wxBrush(wxColour(val.red, val.green, val.blue, 64)));
gc->SetPen(wxPen(wxColour(val.red, val.green, val.blue, 128)));

View File

@@ -150,7 +150,7 @@ TestGLContext::TestGLContext(wxGLCanvas *canvas)
// set viewing projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.5f, 0.5f, -0.5f, 0.5f, 1.0f, 3.0f);
glFrustum(-0.5, 0.5, -0.5, 0.5, 1, 3);
// create the textures to use for cube sides: they will be reused by all
// canvases (which is probably not critical in the case of simple textures
@@ -362,13 +362,13 @@ void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
glDrawBuffer( GL_BACK_LEFT );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.47f, 0.53f, -0.5f, 0.5f, 1.0f, 3.0f);
glFrustum(-0.47, 0.53, -0.5, 0.5, 1, 3);
canvas.DrawRotatedCube(m_xangle, m_yangle);
CheckGLError();
glDrawBuffer( GL_BACK_RIGHT );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.53f, 0.47f, -0.5f, 0.5f, 1.0f, 3.0f);
glFrustum(-0.53, 0.47, -0.5, 0.5, 1, 3);
canvas.DrawRotatedCube(m_xangle, m_yangle);
CheckGLError();
}

View File

@@ -293,19 +293,19 @@ void TestGLCanvas::OnChar(wxKeyEvent& event)
return;
case WXK_LEFT:
m_yrot -= 15.0;
m_yrot -= 15;
break;
case WXK_RIGHT:
m_yrot += 15.0;
m_yrot += 15;
break;
case WXK_UP:
m_xrot += 15.0;
m_xrot += 15;
break;
case WXK_DOWN:
m_xrot -= 15.0;
m_xrot -= 15;
break;
case 's': case 'S':
@@ -349,8 +349,8 @@ void TestGLCanvas::OnMouseEvent(wxMouseEvent& event)
}
else
{
m_yrot += (event.GetX() - last_x)*1.0;
m_xrot += (event.GetY() - last_y)*1.0;
m_yrot += event.GetX() - last_x;
m_xrot += event.GetY() - last_y;
Refresh(false);
}
last_x = event.GetX();

View File

@@ -247,10 +247,10 @@ void TestGLCanvas::OnMouse(wxMouseEvent& event)
/* drag in progress, simulate trackball */
float spin_quat[4];
trackball(spin_quat,
(2.0*m_gldata.beginx - sz.x) / sz.x,
(sz.y - 2.0*m_gldata.beginy) / sz.y,
(2.0*event.GetX() - sz.x) / sz.x,
(sz.y - 2.0*event.GetY()) / sz.y);
(2 * m_gldata.beginx - sz.x) / sz.x,
(sz.y - 2 * m_gldata.beginy) / sz.y,
(2 * event.GetX() - sz.x) / sz.x,
(sz.y - 2 * event.GetY()) / sz.y);
add_quats(spin_quat, m_gldata.quat, m_gldata.quat);
@@ -315,7 +315,7 @@ void TestGLCanvas::ResetProjectionMode()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)ClientSize.x/ClientSize.y, 1.0, 100.0);
gluPerspective(45, double(ClientSize.x) / ClientSize.y, 1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

View File

@@ -113,7 +113,7 @@ vcross(const float *v1, const float *v2, float *cross)
float
vlength(const float *v)
{
return (float) sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
return (float) sqrt((double)(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]));
}
void
@@ -192,9 +192,9 @@ trackball(float q[4], float p1x, float p1y, float p2x, float p2y)
/*
* Avoid problems with out-of-control values...
*/
if (t > 1.0) t = 1.0;
if (t < -1.0) t = -1.0;
phi = 2.0f * (float) asin(t);
if (t > 1) t = 1;
if (t < -1) t = -1;
phi = 2 * (float) asin((double)t);
axis_to_quat(a,phi,q);
}
@@ -207,8 +207,8 @@ axis_to_quat(float a[3], float phi, float q[4])
{
vnormal(a);
vcopy(a, q);
vscale(q, (float) sin(phi/2.0));
q[3] = (float) cos(phi/2.0);
vscale(q, (float) sin((double)phi / 2));
q[3] = (float) cos((double)phi / 2);
}
/*
@@ -220,9 +220,9 @@ tb_project_to_sphere(float r, float x, float y)
{
float d, t, z;
d = (float) sqrt(x*x + y*y);
if (d < r * 0.70710678118654752440) { /* Inside sphere */
z = (float) sqrt(r*r - d*d);
d = (float) sqrt((double)(x*x + y*y));
if (d < r * 0.70710678118654752440f) { /* Inside sphere */
z = (float) sqrt((double)(r*r - d*d));
} else { /* On hyperbola */
t = r / 1.41421356237309504880f;
z = t*t / d;

View File

@@ -21,6 +21,7 @@ class myVec3
public:
myVec3() { x = y = z = 0.0 ;}
myVec3(double xd, double yd, double zd) : x(xd), y(yd), z(zd) {}
myVec3(float xd, float yd, float zd) : x(double(xd)), y(double(yd)), z(double(zd)) {}
~myVec3() {}
double x, y, z;

View File

@@ -1187,16 +1187,16 @@ void myOGLManager::SetStringOnPyr(const unsigned char* strImage, int iWidth, int
double edgeLen = MyDistance(myVec3(gVerts[0], gVerts[1], gVerts[2]),
myVec3(gVerts[6], gVerts[7], gVerts[8]));
GLfloat prop = ((GLfloat) iHeigh) / ((GLfloat) iWidth);
GLfloat rw = (GLfloat) (edgeLen / (1 + 4.0 * prop / sqrt(3.0)));
GLfloat rw = float(edgeLen) / (1 + 4 * prop / std::sqrt(3.0f));
GLfloat h = prop * rw;
GLfloat de = (GLfloat)(2.0 * h / sqrt(3.0));
GLfloat de = 2 * h / std::sqrt(3.0f);
// A bit of separation of the face so as to avoid z-fighting
GLfloat rY = gVerts[1] - (GLfloat)0.01; // Towards outside
GLfloat rY = gVerts[1] - 0.01f; // Towards outside
GLfloat sVerts[12];
// The image was created top to bottom, but OpenGL axis are bottom to top.
// The image would display upside down. We avoid it choosing the right
// order of vertices and texture coords. See myOGLString::SetStringWithVerts()
sVerts[0] = gVerts[6] + de; sVerts[1] = rY; sVerts[2] = gVerts[8] + h / (GLfloat)2.0;
sVerts[0] = gVerts[6] + de; sVerts[1] = rY; sVerts[2] = gVerts[8] + h / 2;
sVerts[3] = sVerts[0] ; sVerts[4] = rY; sVerts[5] = sVerts[2] + h;
sVerts[6] = sVerts[0] + rw; sVerts[7] = rY; sVerts[8] = sVerts[2];
sVerts[9] = sVerts[6] ; sVerts[10] = rY; sVerts[11] = sVerts[5];

View File

@@ -651,7 +651,7 @@ void MyPrintout::DrawPageTwo()
// scaling. The text point size _should_ be the right size but in fact is
// too small for some reason. This is a detail that will need to be
// addressed at some point but can be fudged for the moment.
float scale = (float)((float)ppiPrinterX/(float)ppiScreenX);
double scale = double(ppiPrinterX) / ppiScreenX;
// Now we have to check in case our real page size is reduced (e.g. because
// we're drawing to a print preview memory DC)
@@ -662,7 +662,7 @@ void MyPrintout::DrawPageTwo()
// If printer pageWidth == current DC width, then this doesn't change. But w
// might be the preview bitmap width, so scale down.
float overallScale = scale * (float)(w/(float)pageWidth);
double overallScale = scale * w / pageWidth;
dc->SetUserScale(overallScale, overallScale);
// Calculate conversion factor for converting millimetres into logical
@@ -672,11 +672,11 @@ void MyPrintout::DrawPageTwo()
// unscale to pass logical units to DrawLine.
// Draw 50 mm by 50 mm L shape
float logUnitsFactor = (float)(ppiPrinterX/(scale*25.4));
float logUnits = (float)(50*logUnitsFactor);
double logUnitsFactor = ppiPrinterX / (scale * 25.4);
int logUnits = int(50 * logUnitsFactor);
dc->SetPen(* wxBLACK_PEN);
dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250);
dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits));
dc->DrawLine(50, 250, 50 + logUnits, 250);
dc->DrawLine(50, 250, 50, 250 + logUnits);
dc->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
dc->SetBrush(*wxTRANSPARENT_BRUSH);
@@ -716,22 +716,22 @@ void MyPrintout::DrawPageTwo()
int pageWidthMM, pageHeightMM;
GetPageSizeMM(&pageWidthMM, &pageHeightMM);
float leftMarginLogical = (float)(logUnitsFactor*leftMargin);
float topMarginLogical = (float)(logUnitsFactor*topMargin);
float bottomMarginLogical = (float)(logUnitsFactor*(pageHeightMM - bottomMargin));
float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin));
int leftMarginLogical = int(logUnitsFactor * leftMargin);
int topMarginLogical = int(logUnitsFactor * topMargin);
int bottomMarginLogical = int(logUnitsFactor * (pageHeightMM - bottomMargin));
int rightMarginLogical = int(logUnitsFactor * (pageWidthMM - rightMargin));
dc->SetPen(* wxRED_PEN);
dc->DrawLine( (long)leftMarginLogical, (long)topMarginLogical,
(long)rightMarginLogical, (long)topMarginLogical);
dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical,
(long)rightMarginLogical, (long)bottomMarginLogical);
dc->DrawLine(leftMarginLogical, topMarginLogical,
rightMarginLogical, topMarginLogical);
dc->DrawLine(leftMarginLogical, bottomMarginLogical,
rightMarginLogical, bottomMarginLogical);
WritePageHeader(this, dc, "A header", logUnitsFactor);
}
// Writes a header on a page. Margin units are in millimetres.
bool MyPrintout::WritePageHeader(wxPrintout *printout, wxDC *dc, const wxString&text, float mmToLogical)
bool MyPrintout::WritePageHeader(wxPrintout *printout, wxDC *dc, const wxString&text, double mmToLogical)
{
int pageWidthMM, pageHeightMM;
@@ -742,19 +742,19 @@ bool MyPrintout::WritePageHeader(wxPrintout *printout, wxDC *dc, const wxString&
int topMargin = 10;
int rightMargin = 10;
float leftMarginLogical = (float)(mmToLogical*leftMargin);
float topMarginLogical = (float)(mmToLogical*topMargin);
float rightMarginLogical = (float)(mmToLogical*(pageWidthMM - rightMargin));
int leftMarginLogical = int(mmToLogical * leftMargin);
int topMarginLogical = int(mmToLogical * topMargin);
int rightMarginLogical = int(mmToLogical * (pageWidthMM - rightMargin));
wxCoord xExtent, yExtent;
dc->GetTextExtent(text, &xExtent, &yExtent);
float xPos = (float)(((((pageWidthMM - leftMargin - rightMargin)/2.0)+leftMargin)*mmToLogical) - (xExtent/2.0));
dc->DrawText(text, (long)xPos, (long)topMarginLogical);
int xPos = int(((((pageWidthMM - leftMargin - rightMargin) / 2.0) + leftMargin) * mmToLogical) - (xExtent / 2.0));
dc->DrawText(text, xPos, topMarginLogical);
dc->SetPen(* wxBLACK_PEN);
dc->DrawLine( (long)leftMarginLogical, (long)(topMarginLogical+yExtent),
(long)rightMarginLogical, (long)topMarginLogical+yExtent );
dc->DrawLine(leftMarginLogical, topMarginLogical + yExtent,
rightMarginLogical, topMarginLogical + yExtent);
return true;
}

View File

@@ -98,7 +98,7 @@ public:
void DrawPageTwo();
// Writes a header on a page. Margin units are in millimetres.
bool WritePageHeader(wxPrintout *printout, wxDC *dc, const wxString& text, float mmToLogical);
bool WritePageHeader(wxPrintout *printout, wxDC *dc, const wxString& text, double mmToLogical);
private:
MyFrame *m_frame;

View File

@@ -499,15 +499,15 @@ void SeeThroughFrame::OnPaint(wxPaintEvent& WXUNUSED(evt))
int xcount = 8;
int ycount = 8;
float xstep = 1. / xcount;
float ystep = 1. / ycount;
double xstep = 1.0 / xcount;
double ystep = 1.0 / ycount;
int width = GetClientSize().GetWidth();
int height = GetClientSize().GetHeight();
for ( float x = 0.; x < 1.; x += xstep )
for ( double x = 0; x < 1; x += xstep )
{
for ( float y = 0.; y < 1.; y += ystep )
for ( double y = 0; y < 1; y += ystep )
{
wxImage::RGBValue v = wxImage::HSVtoRGB(wxImage::HSVValue(x, 1., 1.));
dc.SetBrush(wxBrush(wxColour(v.red, v.green, v.blue,