1
0
Fork 0

Codechange: Add CentreTo Rect method.

pull/14300/head
Peter Nelson 2025-05-24 21:54:40 +01:00 committed by Peter Nelson
parent c213218b66
commit 6e90b828c6
1 changed files with 13 additions and 0 deletions

View File

@ -236,6 +236,19 @@ struct Rect {
/* This is a local version of IsInsideMM, to avoid including math_func everywhere. */
return (uint)(pt.x - this->left) <= (uint)(this->right - this->left) && (uint)(pt.y - this->top) <= (uint)(this->bottom - this->top);
}
/**
* Centre a dimension within this Rect.
* @param width The horizontal dimension.
* @param height The vertical dimension.
* @return the new resized Rect.
*/
[[nodiscard]] inline Rect CentreTo(int width, int height) const
{
int new_left = CentreBounds(this->left, this->right, width);
int new_right = CentreBounds(this->top, this->bottom, height);
return {new_left, new_right, new_left + width, new_right + height};
}
};
/**