mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
geom: supplement :combine with more generic .boundingBox
It is a bit cleaner to do all of the necessary looping over lists of Geoms within a straight-forward Geom.boundingBox function rather than looping over :combine every time (or reimplementing :combine in some cases). Geom:combine can be trivially reimplemented in terms of Geom.boundingBox as well. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
committed by
Frans de Jonge
parent
6f1b70e5eb
commit
a29d24f86d
@@ -561,25 +561,14 @@ function CreDocument:getWordFromPosition(pos)
|
||||
if text_range.pos0 and text_range.pos1 then
|
||||
-- get segments from these pos, to build the overall box
|
||||
local word_boxes = self._document:getWordBoxesFromPositions(text_range.pos0, text_range.pos1, true)
|
||||
if #word_boxes > 0 then
|
||||
local overall_box
|
||||
for i = 1, #word_boxes do
|
||||
local line_box = word_boxes[i]
|
||||
if not overall_box then
|
||||
overall_box = line_box
|
||||
else
|
||||
if line_box.x0 < overall_box.x0 then overall_box.x0 = line_box.x0 end
|
||||
if line_box.y0 < overall_box.y0 then overall_box.y0 = line_box.y0 end
|
||||
if line_box.x1 > overall_box.x1 then overall_box.x1 = line_box.x1 end
|
||||
if line_box.y1 > overall_box.y1 then overall_box.y1 = line_box.y1 end
|
||||
end
|
||||
end
|
||||
wordbox.sbox = Geom:new{
|
||||
x = overall_box.x0,
|
||||
y = overall_box.y0,
|
||||
w = overall_box.x1 - overall_box.x0,
|
||||
h = overall_box.y1 - overall_box.y0,
|
||||
}
|
||||
-- convert to Geom so we can use Geom.boundingBox
|
||||
for i=1, #word_boxes do
|
||||
local v = word_boxes[i]
|
||||
word_boxes[i] = { x = v.x0, y = v.y0,
|
||||
w = v.x1 - v.x0, h = v.y1 - v.y0 }
|
||||
end
|
||||
wordbox.sbox = Geom.boundingBox(word_boxes)
|
||||
if wordbox.sbox then
|
||||
box_found = true
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user