Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactoring] change qt math function to cmath analog #89

Merged
merged 2 commits into from
Feb 28, 2018

Conversation

pperehozhih
Copy link
Contributor

Issue #36
change

  • qMax -> std::max
  • qMin -> std::min
  • qCeil -> std::ceil
  • qFloor -> std::floor

@crackedmind
Copy link
Member

@berkus berkus added the pr:WIP DO NOT MERGE This PR is in progress, do not merge yet label Jan 19, 2018
Copy link
Member

@berkus berkus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement missing conversions to std::clamp

@@ -370,7 +370,7 @@ void ShareBox::Inner::repaintChatAtIndex(int index) {

auto row = index / _columnCount;
auto column = index % _columnCount;
update(rtlrect(_rowsLeft + qFloor(column * _rowWidthReal), row * _rowHeight, _rowWidth, _rowHeight, width()));
update(rtlrect(_rowsLeft + std::floor(column * _rowWidthReal), row * _rowHeight, _rowWidth, _rowHeight, width()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tab - replace with spaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean the opposite? Replace spaces with tab? Currently, Kepka codebase mainly uses tabs.

}
qint32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
qint32 descAtY = qMin(_historyPaddingTop - descH, qMax(0, (_scroll->height() - descH) / 2)) + st::msgMargin.top();
qint32 descAtY = std::min(_historyPaddingTop - descH, std::max(0, (_scroll->height() - descH) / 2)) + st::msgMargin.top();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use clamp here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clamp cant be used here. There may be situations it will lead to undefined behavior, this constuction doesnt guarantee that second argument of std:max greater 0 and first argument of std::min greater 0, or one of these greater than other

From specs of std::clamp
"The behavior is undefined if the value of lo is greater than hi"

}
qint32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
qint32 descAtY = qMin(newHistoryPaddingTop - descH, qMax(0, (_scroll->height() - descH) / 2)) + st::msgMargin.top();
qint32 descAtY = std::min(newHistoryPaddingTop - descH, std::max(0, (_scroll->height() - descH) / 2)) + st::msgMargin.top();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clamp cant be used here. There may be situations it will lead to undefined behavior, this constuction doesnt guarantee that second argument of std:max greater 0 and first argument of std::min greater 0, or one of these greater than other

From specs of std::clamp
"The behavior is undefined if the value of lo is greater than hi"

@@ -463,7 +463,7 @@ void HistoryMessageReply::updateName() const {
w += st::msgServiceFont->spacew + _replyToVia->_maxWidth;
}

_maxReplyWidth = previewSkip + qMax(w, qMin(replyToText.maxWidth(), qint32(st::maxSignatureSize)));
_maxReplyWidth = previewSkip + std::max(w, std::min(replyToText.maxWidth(), qint32(st::maxSignatureSize)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clamp cant be used here. There may be situations it will lead to undefined behavior, this constuction doesnt guarantee that second argument of std:max greater 0 and first argument of std::min greater 0, or one of these greater than other

From specs of std::clamp
"The behavior is undefined if the value of lo is greater than hi"

if (_media && _media->currentWidth() < maxwidth) {
maxwidth = qMax(_media->currentWidth(), qMin(maxwidth, plainMaxWidth()));
maxwidth = std::max(_media->currentWidth(), std::min(maxwidth, plainMaxWidth()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clamp cant be used here. There may be situations it will lead to undefined behavior, this constuction doesnt guarantee that second argument of std:max greater 0 and first argument of std::min greater 0, or one of these greater than other

From specs of std::clamp
"The behavior is undefined if the value of lo is greater than hi"

double coef = 1. / fadeSamples, fadedFrom = d->fullSamples - skipSamples;
short *ptr = srcSamplesDataChannel, *zeroEnd = ptr + qMin(samplesCnt, qMax(0, skipSamples - d->fullSamples)), *end = ptr + fadedCnt;
short *ptr = srcSamplesDataChannel, *zeroEnd = ptr + std::min(samplesCnt, std::max(0, skipSamples - d->fullSamples)), *end = ptr + fadedCnt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clamp cant be used here. There may be situations it will lead to undefined behavior, this constuction doesnt guarantee that second argument of std:max greater 0 and first argument of std::min greater 0, or one of these greater than other

From specs of std::clamp
"The behavior is undefined if the value of lo is greater than hi"

qint32 maxw = qMin(qMax(width() - 2 * skipw - st::mediaviewCaptionPadding.left() - st::mediaviewCaptionPadding.right() - 2 * st::mediaviewCaptionMargin.width(), int(st::msgMinWidth)), _caption.maxWidth());
qint32 maxh = qMin(_caption.countHeight(maxw), int(height() / 4 - st::mediaviewCaptionPadding.top() - st::mediaviewCaptionPadding.bottom() - 2 * st::mediaviewCaptionMargin.height()));
qint32 skipw = std::max(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width());
qint32 maxw = std::min(std::max(width() - 2 * skipw - st::mediaviewCaptionPadding.left() - st::mediaviewCaptionPadding.right() - 2 * st::mediaviewCaptionMargin.width(), int(st::msgMinWidth)), _caption.maxWidth());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clamp cant be used here. There may be situations it will lead to undefined behavior, this constuction doesnt guarantee that second argument of std:max greater 0 and first argument of std::min greater 0, or one of these greater than other

From specs of std::clamp
"The behavior is undefined if the value of lo is greater than hi"

auto skipw = qMax(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width());
auto maxw = qMin(qMax(width() - 2 * skipw - st::mediaviewCaptionPadding.left() - st::mediaviewCaptionPadding.right() - 2 * st::mediaviewCaptionMargin.width(), int(st::msgMinWidth)), _caption.maxWidth());
auto skipw = std::max(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width());
auto maxw = std::min(std::max(width() - 2 * skipw - st::mediaviewCaptionPadding.left() - st::mediaviewCaptionPadding.right() - 2 * st::mediaviewCaptionMargin.width(), int(st::msgMinWidth)), _caption.maxWidth());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clamp cant be used here. There may be situations it will lead to undefined behavior, this constuction doesnt guarantee that second argument of std:max greater 0 and first argument of std::min greater 0, or one of these greater than other

From specs of std::clamp
"The behavior is undefined if the value of lo is greater than hi"

@crackedmind
Copy link
Member

@crackedmind
Copy link
Member

@leha-bot leha-bot added this to the Refactoring milestone Feb 13, 2018
@leha-bot
Copy link
Member

I consider to merge it w/o clamp changes. We will make it in next PR.

@berkus berkus merged commit 1cb6dce into procxx:dev Feb 28, 2018
@berkus berkus removed the pr:WIP DO NOT MERGE This PR is in progress, do not merge yet label Feb 28, 2018
@leha-bot leha-bot added category:Enhancement This is a proposed improvement category:Infrastructure Related to build tools, automation category:Refactoring Related to code refactoring labels Feb 28, 2018
@leha-bot leha-bot mentioned this pull request Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:Enhancement This is a proposed improvement category:Infrastructure Related to build tools, automation category:Refactoring Related to code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants