refactor: use math.huge (#692)
This commit is contained in:

committed by
GitHub

parent
3c5d814307
commit
7467e182d3
@@ -15,7 +15,7 @@ function Element:init(id, props)
|
||||
-- Relative proximity from `0` - mouse outside `proximity_max` range, to `1` - mouse within `proximity_min` range.
|
||||
self.proximity = 0
|
||||
-- Raw proximity in pixels.
|
||||
self.proximity_raw = INFINITY
|
||||
self.proximity_raw = math.huge
|
||||
---@type number `0-1` factor to force min visibility. Used for toggling element's permanent visibility.
|
||||
self.min_visibility = 0
|
||||
---@type number `0-1` factor to force a visibility value. Used for flashing, fading out, and other animations
|
||||
@@ -44,7 +44,7 @@ function Element:destroy()
|
||||
Elements:remove(self)
|
||||
end
|
||||
|
||||
function Element:reset_proximity() self.proximity, self.proximity_raw = 0, INFINITY end
|
||||
function Element:reset_proximity() self.proximity, self.proximity_raw = 0, math.huge end
|
||||
|
||||
---@param ax number
|
||||
---@param ay number
|
||||
|
@@ -683,11 +683,11 @@ function Menu:on_pgdwn()
|
||||
end
|
||||
|
||||
function Menu:on_home()
|
||||
self:navigate_by_offset(-INFINITY)
|
||||
self:navigate_by_offset(-math.huge)
|
||||
end
|
||||
|
||||
function Menu:on_end()
|
||||
self:navigate_by_offset(INFINITY)
|
||||
self:navigate_by_offset(math.huge)
|
||||
end
|
||||
|
||||
---@param menu MenuStack
|
||||
|
@@ -278,7 +278,7 @@ function Timeline:render()
|
||||
|
||||
if #state.chapters > 0 then
|
||||
-- Find hovered chapter indicator
|
||||
local closest_delta = INFINITY
|
||||
local closest_delta = math.huge
|
||||
|
||||
if self.proximity_raw < diamond_radius_hovered then
|
||||
for i, chapter in ipairs(state.chapters) do
|
||||
|
@@ -93,7 +93,7 @@ function VolumeSlider:render()
|
||||
end
|
||||
|
||||
local ass = assdraw.ass_new()
|
||||
local nudge_y, nudge_size = self.draw_nudge and self.nudge_y or -INFINITY, self.nudge_size
|
||||
local nudge_y, nudge_size = self.draw_nudge and self.nudge_y or -math.huge, self.nudge_size
|
||||
local volume_y = self.ay + self.border_size +
|
||||
((height - (self.border_size * 2)) * (1 - math.min(state.volume / state.volume_max, 1)))
|
||||
|
||||
|
@@ -252,8 +252,8 @@ do
|
||||
local unicode = utf8_to_unicode(char, 1)
|
||||
for _, block in ipairs(zero_width_blocks) do
|
||||
if unicode >= block[1] and unicode <= block[2] then
|
||||
char_widths[char] = {0, INFINITY}
|
||||
return 0, INFINITY
|
||||
char_widths[char] = {0, math.huge}
|
||||
return 0, math.huge
|
||||
end
|
||||
end
|
||||
|
||||
@@ -303,7 +303,7 @@ end
|
||||
---@return number, integer
|
||||
local function character_based_width(text, bold)
|
||||
local max_width = 0
|
||||
local min_px = INFINITY
|
||||
local min_px = math.huge
|
||||
for line in tostring(text):gmatch("([^\n]*)\n?") do
|
||||
local total_width = 0
|
||||
for _, char in utf8_iter(line) do
|
||||
|
@@ -564,7 +564,7 @@ function serialize_chapter_ranges(normalized_chapters)
|
||||
if next_chapter or not meta.requires_next_chapter then
|
||||
ranges[#ranges + 1] = table_assign({
|
||||
start = chapter.time,
|
||||
['end'] = next_chapter and next_chapter.time or INFINITY,
|
||||
['end'] = next_chapter and next_chapter.time or math.huge,
|
||||
}, config.chapter_ranges[meta.name])
|
||||
end
|
||||
end
|
||||
@@ -593,7 +593,7 @@ function serialize_chapter_ranges(normalized_chapters)
|
||||
local next_chapter = chapters[i + 1]
|
||||
ranges[#ranges + 1] = table_assign({
|
||||
start = chapter.time,
|
||||
['end'] = next_chapter and next_chapter.time or INFINITY,
|
||||
['end'] = next_chapter and next_chapter.time or math.huge,
|
||||
}, config.chapter_ranges.ads)
|
||||
end
|
||||
end
|
||||
|
@@ -6,7 +6,6 @@ opt = require('mp.options')
|
||||
utils = require('mp.utils')
|
||||
msg = require('mp.msg')
|
||||
osd = mp.create_osd_overlay('ass-events')
|
||||
INFINITY = 1e309
|
||||
QUARTER_PI_SIN = math.sin(math.pi / 4)
|
||||
|
||||
require('lib/std')
|
||||
@@ -249,8 +248,8 @@ end
|
||||
|
||||
display = {width = 1280, height = 720, initialized = false}
|
||||
cursor = {
|
||||
x = INFINITY,
|
||||
y = INFINITY,
|
||||
x = math.huge,
|
||||
y = math.huge,
|
||||
hidden = true,
|
||||
hover_raw = false,
|
||||
-- Event handlers that are only fired on cursor, bound during render loop. Guidelines:
|
||||
@@ -313,15 +312,15 @@ cursor = {
|
||||
-- we receive a first real mouse move event with coordinates other than 0,0.
|
||||
if not cursor.first_real_mouse_move_received then
|
||||
if x > 0 and y > 0 then cursor.first_real_mouse_move_received = true
|
||||
else x, y = INFINITY, INFINITY end
|
||||
else x, y = math.huge, math.huge end
|
||||
end
|
||||
|
||||
-- Add 0.5 to be in the middle of the pixel
|
||||
cursor.x = x == INFINITY and x or x + 0.5
|
||||
cursor.y = y == INFINITY and y or y + 0.5
|
||||
cursor.x = x == math.huge and x or x + 0.5
|
||||
cursor.y = y == math.huge and y or y + 0.5
|
||||
|
||||
if old_x ~= cursor.x or old_y ~= cursor.y then
|
||||
if cursor.x == INFINITY or cursor.y == INFINITY then
|
||||
if cursor.x == math.huge or cursor.y == math.huge then
|
||||
cursor.hidden = true
|
||||
cursor.history:clear()
|
||||
|
||||
@@ -364,7 +363,7 @@ cursor = {
|
||||
|
||||
request_render()
|
||||
end,
|
||||
leave = function () cursor.move(INFINITY, INFINITY) end,
|
||||
leave = function () cursor.move(math.huge, math.huge) end,
|
||||
-- Cursor auto-hiding after period of inactivity
|
||||
autohide = function()
|
||||
if not cursor.on_primary_up and not Menu:is_open() then cursor.leave() end
|
||||
|
Reference in New Issue
Block a user