-
Notifications
You must be signed in to change notification settings - Fork 1
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
Clarify and test properties of Rectangle
#27
Comments
(more notes from Discord conversation) From the invariants and properties we defined before the following assumptions should hold: // 1) rectangle from point should be valid, since min <= max
assertTrue(rect.isValid())
// 2) rectangle from point should contain the point
assertTrue(rect.contains(0, 0));
// 3) area of rectangle should be number of discrete integer points
assertEquals(1, rect.area())
// 4) area of rectanlge should be equal to width x height
assertEquals(rect.area(), rect.getSizeX() * rect.getSizeY()) From 3) and 4) it follows that the size cannot be 'max - min'. Instead, it must be 'max - min + 1'. This would need to change the current semantics max is inclusive). The last point leads to questions on how the discrete |
Half-open intervals are also an option. However, we decided on Discord that we don't want to go down this route. Adding the respective assertions here for completeness. Rectanglei rect = new Rectangle(0, 0);
// 1) rectangle from point should be valid, since min <= max
assertTrue(rect.isValid())
// 2) rectangle from point does NOT contain the point
assertFalse(rect.contains(0, 0));
// 3) area of rectangle should be number of discrete integer points
assertEquals(0, rect.area())
// 4) area of rectanlge should be equal to width x height
assertEquals(rect.area(), rect.getSizeX() * rect.getSizeY())
// 5) size is equal to 'max - min'
assertEquals(rect.maxX() - rect.minX(), rect.getSizeX()) |
The intersection of two rectangles may be empty, so one of the properties you list is incorrect. |
updated the issue - I think the property is correct, but maybe a bit confusing as it is written down:
I put this down explicitly because we have a test for intersection right now that's true even though the result of the intersection is ∅ ("touching" rectangles) |
Currently, our primitives use a closed interval semantics, i.e., both min and max are included.
To avoid confusion about floating point rounding to integer domain we do not offer floating-point variants of methods on integer primitives, e.g., we don't offer
contains(float)
and similar methods with floating points onRectanglei
.As I like the idea of testing based on properties and invariants here's what I got from the review of #23, plus a few additional things (as discussed on Discord with @pollend and @4Denthusiast):
Let A, B, C be rectangles, and let p be a point. Let ∅ denote an invalid rectangle without size.
isValid
lenght/area
contains/intersection
intersection
union
Rectangled/f
The text was updated successfully, but these errors were encountered: