View Single Post
Old 04-13-2023, 06:31 AM   #541
kaznelson
Old Kaz
kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.kaznelson ought to be getting tired of karma fortunes by now.
 
kaznelson's Avatar
 
Posts: 208
Karma: 1064151
Join Date: May 2010
Device: PocketBook Era
Quote:
Originally Posted by NiLuJe View Post
Are we talking the angle at which point horizontal becomes a diagonal? I would assume 45°
In any case, hope you like trig: https://github.com/koreader/koreader....lua#L307-L337
I made these sectors: 15°*2 for vertical swipe, 15° for diagonal swipe, and 60°*2 for horizontal swipe.
Please tell me, is it possible to do this with user patch?

Spoiler:
Code:
--[[--
Compares `current_tev` with `initial_tev`.

The first boolean argument `simple` results in only four directions if true.

@return (direction, distance) pan direction and distance
--]]
function Contact:getPath(simple, diagonal, initial_tev)
    initial_tev = initial_tev or self.initial_tev

    local x_diff = self.current_tev.x - initial_tev.x
    local y_diff = self.current_tev.y - initial_tev.y
    local direction = nil
    local distance = math.sqrt(x_diff*x_diff + y_diff*y_diff)
    if x_diff ~= 0 or y_diff ~= 0 then
        local v_direction = y_diff < 0 and "north" or "south"
        local h_direction = x_diff < 0 and "west" or "east"
        if (not simple
            and math.abs(y_diff) > 1.732*math.abs(x_diff)
            and math.abs(y_diff) < 3.732*math.abs(x_diff))
           or (simple and diagonal)
        then
            direction = v_direction .. h_direction
        elseif (math.abs(x_diff) > 0.577*math.abs(y_diff)) then
            direction = h_direction
        else
            direction = v_direction
        end
    end
    return direction, distance
end

Last edited by kaznelson; 04-13-2023 at 07:02 AM.
kaznelson is offline   Reply With Quote