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

Simplify and fix Table.set_span #53

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tomprogrammer
Copy link

In Table.set_span there are a bunch of redundant checks for borders and number of bordered edges that this commit simplifies. Additionally the vertical and horizontal spans are independent of each other, therefore these checks can be untangled.

I think that this actually uncovered a bug in the old implementation. For the cases where both horizontally and vertically only one of both edges are bordered there are differences with this commit.

left right top bottom vspan/hspan before vspan/hspan after
true false true false false true
true false false true false true
false true true false false true
false true false true false true

This change in behaviour of the Table.set_span method is a bug fix. I guess in the original code it was missed that a cell could both horizontally and vertically span to other cells if the two bordered edges are not on the same direction.

In `Table.set_span` there are a bunch of redundant checks for borders and
number of bordered edges that this commit simplifies. Additionally the
vertical and horizontal spans are independent of each other, therefore these
checks can be untangled.

I think that this actually uncovered a bug in the old implementation.
For the cases where both horizontally and vertically only one of both edges
are bordered there are differences with this commit.

| left  | right | top   | bottom | vspan/hspan before | vspan/hspan after |
| ----- | ----- | ---   | ------ | ------------------ | ----------------- |
| true  | false | true  | false  | false              | true              |
| true  | false | false | true   | false              | true              |
| false | true  | true  | false  | false              | true              |
| false | true  | false | true   | false              | true              |

This change in behaviour of the `Table.set_span` method is a bug fix.
I guess in the original code it was missed that a cell could both
horizontally and vertically span to other cells if the two bordered
edges are not on the same direction.
@tomprogrammer tomprogrammer marked this pull request as ready for review August 16, 2024 21:52
@tomprogrammer tomprogrammer marked this pull request as draft August 16, 2024 21:57
@tomprogrammer
Copy link
Author

This is now locally tested and does pass. But I didn't check whether the tests would catch the different hspan/vspan results. I probably should add tests for that..

The attributes `vspan` and `hspan` depend only on other attributes
inside `Cell`, therefore there is no need to use a mutating method
`set_span` to recover the invariants of `Cell`.
@tomprogrammer
Copy link
Author

After the change to use properties for Cell.hspan and Cell.vspan the method Cell.bound isn't used anymore. Since it is part of the public interface I didn't remove it.

@tomprogrammer tomprogrammer marked this pull request as ready for review August 17, 2024 17:05
The condition `hspan and not left` expands to `(not left or not right)
and not left` which simplifies to `not left`.

After this change `Cell.hspan` and `Cell.vspan` aren't used anymore in
this codebase. They stay because they are part of the API.
@bosd bosd added bug Something isn't working enhancement New feature or request labels Aug 26, 2024
@bosd bosd mentioned this pull request Aug 28, 2024
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants