Skip to content

Commit

Permalink
Remove redundant conditions on Cell.vspan/hspan
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomprogrammer authored and bosd committed Oct 19, 2024
1 parent 898ec39 commit 6118c3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions camelot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,20 +647,21 @@ def copy_spanning_text(self, copy_text=None):
Returns
-------
t : camelot.core.Table
table : camelot.core.Table
"""
for f in copy_text:
if f == "h":
for i in range(len(self.cells)):
for j in range(len(self.cells[i])):
if self.cells[i][j].text.strip() == "":
if self.cells[i][j].hspan and not self.cells[i][j].left:
if not self.cells[i][j].left:
self.cells[i][j].text = self.cells[i][j - 1].text
elif f == "v":
for i in range(len(self.cells)):
for j in range(len(self.cells[i])):
if self.cells[i][j].text.strip() == "":
if self.cells[i][j].vspan and not self.cells[i][j].top:
if not self.cells[i][j].top:
self.cells[i][j].text = self.cells[i - 1][j].text
return self

Expand Down
8 changes: 4 additions & 4 deletions camelot/parsers/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ def _reduce_index(table, idx, shift_text):
indices = []
for r_idx, c_idx, text in idx:
for d in shift_text:
if d == "l" and table.cells[r_idx][c_idx].hspan:
if d == "l":
while not table.cells[r_idx][c_idx].left:
c_idx -= 1
if d == "r" and table.cells[r_idx][c_idx].hspan:
elif d == "r":
while not table.cells[r_idx][c_idx].right:
c_idx += 1
if d == "t" and table.cells[r_idx][c_idx].vspan:
elif d == "t":
while not table.cells[r_idx][c_idx].top:
r_idx -= 1
if d == "b" and table.cells[r_idx][c_idx].vspan:
elif d == "b":
while not table.cells[r_idx][c_idx].bottom:
r_idx += 1
indices.append((r_idx, c_idx, text))
Expand Down

0 comments on commit 6118c3c

Please sign in to comment.