Skip to content

Commit

Permalink
Make some dubious type conversions explicit.
Browse files Browse the repository at this point in the history
This is to address MSVC warnings.

This commit changes a few configuration fields to use double instead
of float. There doesn't seem to be any reason these use float except
for the legacy Windows code using float for saved configuration.
Changing their type to double improves consistency.
  • Loading branch information
whitequark committed Jul 18, 2018
1 parent c1f1c7c commit 7630e0e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ bool GraphicsWindow::MouseEvent(Platform::MouseEvent event) {
break;

case MouseEvent::Type::SCROLL_VERT:
this->MouseScroll(event.x, event.y, event.scrollDelta);
this->MouseScroll(event.x, event.y, (int)event.scrollDelta);
break;

case MouseEvent::Type::LEAVE:
Expand Down
2 changes: 1 addition & 1 deletion src/platform/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void Settings::FreezeBool(const std::string &key, bool value) {
}

bool Settings::ThawBool(const std::string &key, bool defaultValue) {
return (bool)ThawInt(key, (int)defaultValue);
return ThawInt(key, (int)defaultValue) != 0;
}

void Settings::FreezeColor(const std::string &key, RgbaColor value) {
Expand Down
6 changes: 3 additions & 3 deletions src/platform/guiwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ class WindowImplWin32 : public Window {
settings->FreezeInt(key + "_Right", rc.right);
settings->FreezeInt(key + "_Top", rc.top);
settings->FreezeInt(key + "_Bottom", rc.bottom);
settings->FreezeBool(key + "_Maximized", isMaximized);
settings->FreezeBool(key + "_Maximized", isMaximized == TRUE);
}

void ThawPosition(SettingsRef settings, const std::string &key) override {
Expand Down Expand Up @@ -1555,9 +1555,9 @@ class FileDialogImplWin32 : public FileDialog {
}

if(isSaveDialog) {
return GetSaveFileNameW(&ofn);
return GetSaveFileNameW(&ofn) == TRUE;
} else {
return GetOpenFileNameW(&ofn);
return GetOpenFileNameW(&ofn) == TRUE;
}
}
};
Expand Down
50 changes: 25 additions & 25 deletions src/solvespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ void SolveSpaceUI::Init() {
modelColor[6] = settings->ThawColor("ModelColor_6", RGBi( 0, 0, 130));
modelColor[7] = settings->ThawColor("ModelColor_7", RGBi( 80, 0, 80));
// Light intensities
lightIntensity[0] = settings->ThawFloat("LightIntensity_0", 1.0f);
lightIntensity[1] = settings->ThawFloat("LightIntensity_1", 0.5f);
lightIntensity[0] = settings->ThawFloat("LightIntensity_0", 1.0);
lightIntensity[1] = settings->ThawFloat("LightIntensity_1", 0.5);
ambientIntensity = 0.3; // no setting for that yet
// Light positions
lightDir[0].x = settings->ThawFloat("LightDir_0_Right", -1.0f);
lightDir[0].y = settings->ThawFloat("LightDir_0_Up", 1.0f);
lightDir[0].z = settings->ThawFloat("LightDir_0_Forward", 0.0f);
lightDir[1].x = settings->ThawFloat("LightDir_1_Right", 1.0f);
lightDir[1].y = settings->ThawFloat("LightDir_1_Up", 0.0f);
lightDir[1].z = settings->ThawFloat("LightDir_1_Forward", 0.0f);
lightDir[0].x = settings->ThawFloat("LightDir_0_Right", -1.0);
lightDir[0].y = settings->ThawFloat("LightDir_0_Up", 1.0);
lightDir[0].z = settings->ThawFloat("LightDir_0_Forward", 0.0);
lightDir[1].x = settings->ThawFloat("LightDir_1_Right", 1.0);
lightDir[1].y = settings->ThawFloat("LightDir_1_Up", 0.0);
lightDir[1].z = settings->ThawFloat("LightDir_1_Forward", 0.0);

exportMode = false;
// Chord tolerance
chordTol = settings->ThawFloat("ChordTolerancePct", 0.5f);
chordTol = settings->ThawFloat("ChordTolerancePct", 0.5);
// Max pwl segments to generate
maxSegments = settings->ThawInt("MaxSegments", 10);
// Chord tolerance
exportChordTol = settings->ThawFloat("ExportChordTolerance", 0.1f);
exportChordTol = settings->ThawFloat("ExportChordTolerance", 0.1);
// Max pwl segments to generate
exportMaxSegments = settings->ThawInt("ExportMaxSegments", 64);
// View units
Expand All @@ -57,13 +57,13 @@ void SolveSpaceUI::Init() {
afterDecimalMm = settings->ThawInt("AfterDecimalMm", 2);
afterDecimalInch = settings->ThawInt("AfterDecimalInch", 3);
// Camera tangent (determines perspective)
cameraTangent = settings->ThawFloat("CameraTangent", 0.3f/1e3f);
cameraTangent = settings->ThawFloat("CameraTangent", 0.3f/1e3);
// Grid spacing
gridSpacing = settings->ThawFloat("GridSpacing", 5.0f);
gridSpacing = settings->ThawFloat("GridSpacing", 5.0);
// Export scale factor
exportScale = settings->ThawFloat("ExportScale", 1.0f);
exportScale = settings->ThawFloat("ExportScale", 1.0);
// Export offset (cutter radius comp)
exportOffset = settings->ThawFloat("ExportOffset", 0.0f);
exportOffset = settings->ThawFloat("ExportOffset", 0.0);
// Rewrite exported colors close to white into black (assuming white bg)
fixExportColors = settings->ThawBool("FixExportColors", true);
// Draw back faces of triangles (when mesh is leaky/self-intersecting)
Expand All @@ -81,20 +81,20 @@ void SolveSpaceUI::Init() {
// Whether export canvas size is fixed or derived from bbox
exportCanvasSizeAuto = settings->ThawBool("ExportCanvasSizeAuto", true);
// Margins for automatic canvas size
exportMargin.left = settings->ThawFloat("ExportMargin_Left", 5.0f);
exportMargin.right = settings->ThawFloat("ExportMargin_Right", 5.0f);
exportMargin.bottom = settings->ThawFloat("ExportMargin_Bottom", 5.0f);
exportMargin.top = settings->ThawFloat("ExportMargin_Top", 5.0f);
exportMargin.left = settings->ThawFloat("ExportMargin_Left", 5.0);
exportMargin.right = settings->ThawFloat("ExportMargin_Right", 5.0);
exportMargin.bottom = settings->ThawFloat("ExportMargin_Bottom", 5.0);
exportMargin.top = settings->ThawFloat("ExportMargin_Top", 5.0);
// Dimensions for fixed canvas size
exportCanvas.width = settings->ThawFloat("ExportCanvas_Width", 100.0f);
exportCanvas.height = settings->ThawFloat("ExportCanvas_Height", 100.0f);
exportCanvas.dx = settings->ThawFloat("ExportCanvas_Dx", 5.0f);
exportCanvas.dy = settings->ThawFloat("ExportCanvas_Dy", 5.0f);
exportCanvas.width = settings->ThawFloat("ExportCanvas_Width", 100.0);
exportCanvas.height = settings->ThawFloat("ExportCanvas_Height", 100.0);
exportCanvas.dx = settings->ThawFloat("ExportCanvas_Dx", 5.0);
exportCanvas.dy = settings->ThawFloat("ExportCanvas_Dy", 5.0);
// Extra parameters when exporting G code
gCode.depth = settings->ThawFloat("GCode_Depth", 10.0f);
gCode.depth = settings->ThawFloat("GCode_Depth", 10.0);
gCode.passes = settings->ThawInt("GCode_Passes", 1);
gCode.feed = settings->ThawFloat("GCode_Feed", 10.0f);
gCode.plungeFeed = settings->ThawFloat("GCode_PlungeFeed", 10.0f);
gCode.feed = settings->ThawFloat("GCode_Feed", 10.0);
gCode.plungeFeed = settings->ThawFloat("GCode_PlungeFeed", 10.0);
// Show toolbar in the graphics window
showToolbar = settings->ThawBool("ShowToolbar", true);
// Recent files menus
Expand Down
28 changes: 14 additions & 14 deletions src/solvespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ class SolveSpaceUI {
double exportChordTol;
int exportMaxSegments;
double cameraTangent;
float gridSpacing;
float exportScale;
float exportOffset;
double gridSpacing;
double exportScale;
double exportOffset;
bool fixExportColors;
bool drawBackFaces;
bool showContourAreas;
Expand All @@ -601,22 +601,22 @@ class SolveSpaceUI {
bool exportCanvasSizeAuto;
bool exportMode;
struct {
float left;
float right;
float bottom;
float top;
double left;
double right;
double bottom;
double top;
} exportMargin;
struct {
float width;
float height;
float dx;
float dy;
double width;
double height;
double dx;
double dy;
} exportCanvas;
struct {
float depth;
double depth;
int passes;
float feed;
float plungeFeed;
double feed;
double plungeFeed;
} gCode;

Unit viewUnits;
Expand Down

0 comments on commit 7630e0e

Please sign in to comment.