mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add math.lua, move all math related helpers in to it
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
require "../math"
|
||||
|
||||
--[[
|
||||
This is a registry for document providers
|
||||
]]--
|
||||
@@ -126,17 +128,9 @@ function Document:getPageDimensions(pageno, zoom, rotation)
|
||||
return native_dimen
|
||||
end
|
||||
|
||||
function Document:oddEven(number)
|
||||
if number % 2 == 1 then
|
||||
return "odd"
|
||||
else
|
||||
return "even"
|
||||
end
|
||||
end
|
||||
|
||||
function Document:getPageBBox(pageno)
|
||||
local bbox = self.bbox[pageno] -- exact
|
||||
local oddEven = self:oddEven(pageno)
|
||||
local oddEven = math.oddEven(pageno)
|
||||
if bbox ~= nil then
|
||||
DEBUG("bbox from", pageno)
|
||||
else
|
||||
|
||||
25
frontend/math.lua
Normal file
25
frontend/math.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
--[[
|
||||
Simple math helper function
|
||||
]]--
|
||||
|
||||
function math.roundAwayFromZero(num)
|
||||
if num > 0 then
|
||||
return math.ceil(num)
|
||||
else
|
||||
return math.floor(num)
|
||||
end
|
||||
end
|
||||
|
||||
function math.round(num)
|
||||
return math.floor(num + 0.5)
|
||||
end
|
||||
|
||||
function math.oddEven(number)
|
||||
if number % 2 == 1 then
|
||||
return "odd"
|
||||
else
|
||||
return "even"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require "math"
|
||||
|
||||
--[[
|
||||
BBoxWidget shows a bbox for page cropping
|
||||
]]
|
||||
@@ -89,14 +91,6 @@ function BBoxWidget:screen_to_page()
|
||||
return bbox
|
||||
end
|
||||
|
||||
function BBoxWidget:oddEven(number)
|
||||
if number % 2 == 1 then
|
||||
return "odd"
|
||||
else
|
||||
return "even"
|
||||
end
|
||||
end
|
||||
|
||||
function BBoxWidget:onAdjustCrop(arg, ges)
|
||||
DEBUG("adjusting crop bbox with pos", ges.pos)
|
||||
local bbox = self.screen_bbox
|
||||
@@ -136,7 +130,7 @@ function BBoxWidget:onConfirmCrop()
|
||||
UIManager:close(self)
|
||||
self.ui:handleEvent(Event:new("BBoxUpdate"), self.page_bbox)
|
||||
self.document.bbox[self.pageno] = self.page_bbox
|
||||
self.document.bbox[self:oddEven(self.pageno)] = self.page_bbox
|
||||
self.document.bbox[math.oddEven(self.pageno)] = self.page_bbox
|
||||
self.ui:handleEvent(Event:new("ExitPageCrop"))
|
||||
end
|
||||
|
||||
|
||||
@@ -265,21 +265,3 @@ return the Euclidean distance between two geoms
|
||||
function Geom:distance(geom)
|
||||
return math.sqrt(math.pow(self.x - geom.x, 2) + math.pow(self.y - geom.y, 2))
|
||||
end
|
||||
|
||||
--[[
|
||||
Simple math helper function
|
||||
]]--
|
||||
|
||||
function math.roundAwayFromZero(num)
|
||||
if num > 0 then
|
||||
return math.ceil(num)
|
||||
else
|
||||
return math.floor(num)
|
||||
end
|
||||
end
|
||||
|
||||
function math.round(num)
|
||||
return math.floor(num + 0.5)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require "math"
|
||||
|
||||
ReaderPaging = InputContainer:new{
|
||||
current_page = 0,
|
||||
number_of_pages = 0,
|
||||
|
||||
Reference in New Issue
Block a user