From 7d11dd20d4a06dfc3cdfbf1452c5e026ad4e01c9 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Fri, 18 Sep 2020 12:10:40 -0700 Subject: [PATCH] Replace some floating point expressions with equivalent integer ones --- src/common/layout.cpp | 16 ++++++++-------- src/generic/printps.cpp | 4 ++-- src/richtext/richtextctrl.cpp | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/common/layout.cpp b/src/common/layout.cpp index 1e4f0e01d2..a514c25c45 100644 --- a/src/common/layout.cpp +++ b/src/common/layout.cpp @@ -211,7 +211,7 @@ bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constr int edgePos = GetEdge(otherEdge, win, otherWin); if (edgePos != -1) { - value = (int)(edgePos*(((float)percent)*0.01) + margin); + value = (edgePos * percent) / 100 + margin; done = true; return true; } @@ -286,7 +286,7 @@ bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constr int edgePos = GetEdge(otherEdge, win, otherWin); if (edgePos != -1) { - value = (int)(edgePos*(((float)percent)*0.01) - margin); + value = (edgePos * percent) / 100 - margin; done = true; return true; } @@ -364,7 +364,7 @@ bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constr int edgePos = GetEdge(otherEdge, win, otherWin); if (edgePos != -1) { - value = (int)(edgePos*(((float)percent)*0.01) + margin); + value = (edgePos * percent) / 100 + margin; done = true; return true; } @@ -439,7 +439,7 @@ bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constr int edgePos = GetEdge(otherEdge, win, otherWin); if (edgePos != -1) { - value = (int)(edgePos*(((float)percent)*0.01) - margin); + value = (edgePos * percent) / 100 - margin; done = true; return true; } @@ -517,7 +517,7 @@ bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constr int edgePos = GetEdge(otherEdge, win, otherWin); if (edgePos != -1) { - value = (int)(edgePos*(((float)percent)*0.01) + margin); + value = (edgePos * percent) / 100 + margin; done = true; return true; } @@ -585,7 +585,7 @@ bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constr int edgePos = GetEdge(otherEdge, win, otherWin); if (edgePos != -1) { - value = (int)(edgePos*(((float)percent)*0.01) + margin); + value = (edgePos * percent) / 100 + margin; done = true; return true; } @@ -626,7 +626,7 @@ bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constr int edgePos = GetEdge(otherEdge, win, otherWin); if (edgePos != -1) { - value = (int)(edgePos*(((float)percent)*0.01)); + value = (edgePos * percent) / 100; done = true; return true; } @@ -684,7 +684,7 @@ bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constr int edgePos = GetEdge(otherEdge, win, otherWin); if (edgePos != -1) { - value = (int)(edgePos*(((float)percent)*0.01)); + value = (edgePos * percent) / 100; done = true; return true; } diff --git a/src/generic/printps.cpp b/src/generic/printps.cpp index d7284268d9..4de1bc231d 100644 --- a/src/generic/printps.cpp +++ b/src/generic/printps.cpp @@ -325,8 +325,8 @@ void wxPostScriptPrintPreview::DetermineScaling() m_previewPrintout->SetPPIPrinter( logPPIPrinterX, logPPIPrinterY ); wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); - sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * resolution / 72.0); - sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * resolution / 72.0); + sizeDevUnits.x = sizeDevUnits.x * resolution / 72; + sizeDevUnits.y = sizeDevUnits.y * resolution / 72; wxSize sizeTenthsMM(paper->GetSize()); wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 003dd761f3..6c066dd1d8 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -1874,7 +1874,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) if (GetWindowStyle() & wxRE_CENTRE_CARET) { int y = rect.y - GetClientSize().y/2; - int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); + int yUnits = (y + ppuY - 1) / ppuY; if (y >= 0 && (y + clientSize.y) < (int) (0.5 + GetBuffer().GetCachedSize().y * GetScale())) { if (startYUnits != yUnits) @@ -1902,7 +1902,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Make it scroll so this item is at the bottom // of the window int y = rect.y - (clientSize.y - rect.height); - int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); + int yUnits = (y + ppuY - 1) / ppuY; // If we're still off the screen, scroll another line down if ((rect.y + rect.height) > (clientSize.y + (yUnits*ppuY))) @@ -1919,7 +1919,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Make it scroll so this item is at the top // of the window int y = rect.y - (int) (0.5 + GetBuffer().GetTopMargin() * GetScale()); - int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); + int yUnits = (y + ppuY - 1) / ppuY; if (startYUnits != yUnits) { @@ -1939,7 +1939,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Make it scroll so this item is at the top // of the window int y = rect.y - (int) (0.5 + GetBuffer().GetTopMargin() * GetScale()); - int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); + int yUnits = (y + ppuY - 1) / ppuY; if (startYUnits != yUnits) { @@ -1952,7 +1952,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) // Make it scroll so this item is at the bottom // of the window int y = rect.y - (clientSize.y - rect.height); - int yUnits = (int) (0.5 + ((float) y)/(float) ppuY); + int yUnits = (y + ppuY - 1) / ppuY; // If we're still off the screen, scroll another line down if ((rect.y + rect.height) > (clientSize.y + (yUnits*ppuY))) @@ -2955,14 +2955,14 @@ void wxRichTextCtrl::SetupScrollbars(bool atTop, bool fromOnPaint) int maxHeight = (int) (0.5 + GetScale() * (GetBuffer().GetCachedSize().y + GetBuffer().GetTopMargin())); // Round up so we have at least maxHeight pixels - int unitsY = (int) (((float)maxHeight/(float)pixelsPerUnit) + 0.5); + int unitsY = (maxHeight + pixelsPerUnit - 1) / pixelsPerUnit; int startX = 0, startY = 0; if (!atTop) GetViewStart(& startX, & startY); int maxPositionX = 0; - int maxPositionY = (int) ((((float)(wxMax((unitsY*pixelsPerUnit) - clientSize.y, 0)))/((float)pixelsPerUnit)) + 0.5); + int maxPositionY = (wxMax(unitsY * pixelsPerUnit - clientSize.y, 0) + pixelsPerUnit - 1) / pixelsPerUnit; int newStartX = wxMin(maxPositionX, startX); int newStartY = wxMin(maxPositionY, startY);