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

Fix incorrect example in the documentation for the expand method in Rect2 #91446

Merged
merged 1 commit into from
May 2, 2024

Conversation

HexagonNico
Copy link
Contributor

The documentation for the expand method in the Rect2 class currently contains this example:

var rect = Rect2(0, 0, 5, 2)

rect = rect.expand(Vector2(10, 0)) # rect is Rect2(0, 0, 10, 2)
rect = rect.expand(Vector2(-5, 5)) # rect is Rect2(-5, 0, 10, 5)

However, running the following code

var rect = Rect2(0, 0, 5, 2)

rect = rect.expand(Vector2(10, 0))
print(rect)
rect = rect.expand(Vector2(-5, 5))
print(rect)

produces this output:

[P: (0, 0), S: (10, 2)]
[P: (-5, 0), S: (15, 5)]

After the second call the rectangle becomes (-5, 0, 15, 5) instead of (-5, 0, 10, 5) because the first call modifies the rect variable, while the example assumes that the expand function is still called on the original rectangle.

Changing the example to

var rect = Rect2(0, 0, 5, 2)

var rect1 = rect.expand(Vector2(10, 0)) # rect1 is Rect2(0, 0, 10, 2)
var rect2 = rect.expand(Vector2(-5, 5)) # rect2 is Rect2(-5, 0, 10, 5)

should make it clear that the initial rectangle is still the same.

@AThousandShips
Copy link
Member

I'd suggest just fixing the incorrect results instead of changing the example

@AThousandShips AThousandShips added bug cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release and removed enhancement labels May 2, 2024
@AThousandShips AThousandShips modified the milestones: 4.x, 4.3 May 2, 2024
@HexagonNico HexagonNico changed the title Clear ambiguity in the example in the documentation for Rect2.expand. Fix incorrect example in the documentation for the expand method in Rect2 May 2, 2024
@HexagonNico
Copy link
Contributor Author

I've changed the example to

var rect = Rect2(0, 0, 5, 2)

rect = rect.expand(Vector2(10, 0)) # rect is Rect2(0, 0, 10, 2)
rect = rect.expand(Vector2(-5, 5)) # rect is Rect2(-5, 0, 15, 5)

@akien-mga akien-mga merged commit a0b0b19 into godotengine:master May 2, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants