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 #165

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

Conversation

bosd
Copy link
Collaborator

@bosd bosd commented Oct 7, 2024

Superseeds #53

@bosd bosd marked this pull request as ready for review October 7, 2024 22:28
@bosd bosd added refactoring Refactoring bug Something isn't working enhancement New feature or request labels Oct 8, 2024
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.
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`.
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.
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 refactoring Refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants