KEMBAR78
COMMON: Add new Rect constructors to make construction from coordinate+size easier by elasota · Pull Request #5045 · scummvm/scummvm · GitHub
Skip to content

Conversation

@elasota
Copy link
Contributor

@elasota elasota commented May 25, 2023

This adds some new constructors to Rect for constructing a rect from a top-left coordinate and either a bottom-right coordinate or a width and height.

Currently, this requires constructing a rect as:
Rect(coord.x, coord.y, coord.x + size.x, coord.y + size.y)

Most of the subexpressions in that are duplicated, which creates opportunities for mistakes, such as when constructing multiple rects.

With this change, you construct as:
Rect(coord, coord + size) or Rect(coord, size.x, size.y)

This doesn't add the ability to do Rect(coord, size) since it would have the same signature. I opted to use top-left and bottom-right coordinates given the two options, since "Point" more intuitively makes sense as a coordinate than a size.

@bluegr
Copy link
Member

bluegr commented May 27, 2023

Thanks, these extra Rect constructors are indeed useful. The current constructors haven't been affected, so this is fine to merge

@bluegr bluegr merged commit 0e99ed1 into scummvm:master May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants