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:
Aleksa Sarai
2021-10-23 21:12:43 +11:00
committed by Frans de Jonge
parent 6f1b70e5eb
commit a29d24f86d
3 changed files with 42 additions and 55 deletions

View File

@@ -789,14 +789,7 @@ function KoptInterface:getClipPageContext(doc, pos0, pos1, pboxes, drawer)
assert(pos0.zoom == pos1.zoom)
local rect
if pboxes and #pboxes > 0 then
local box = pboxes[1]
rect = Geom:new{
x = box.x, y = box.y,
w = box.w, h = box.h,
}
for _, _box in ipairs(pboxes) do
rect = rect:combine(Geom:new(_box))
end
rect = Geom.boundingBox(pboxes)
else
local zoom = pos0.zoom or 1
rect = {
@@ -1241,14 +1234,9 @@ function KoptInterface:nativeToPageRectTransform(doc, pageno, rect)
y = rect.y + rect.h - 5
}
local boxes = self:getPageBoxesFromPositions(doc, pageno, pos0, pos1)
local res_rect = nil
if #boxes > 0 then
res_rect = boxes[1]
for _, box in pairs(boxes) do
res_rect = res_rect:combine(box)
end
if boxes then
return Geom.boundingBox(boxes)
end
return res_rect
else
return rect
end