Skip to content

Commit

Permalink
refactor: Apply Lua "min" profile without math.log10 and math.pow
Browse files Browse the repository at this point in the history
Not a fix as those exist in Lua 5.1 to 5.4 at the time of writing,
but were marked deprecated in 5.2 and 5.3...
  • Loading branch information
Omikhleia authored and Didier Willis committed Dec 8, 2023
1 parent 7e00578 commit 0dfbb40
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lua-libraries/README.tinyyaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ RESILIENT was to avoid a C binding dependency, since style files are
reasonably small theoretically (so performance do not really matter) and
only need a subset of YAML (so a pure-Lua implementation, even possibly
incomplete, ought to be sufficient.)

Modications are marked with comments MODIFIED RESILIENT
2 changes: 1 addition & 1 deletion lua-libraries/resilient-tinyyaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function types.timestamp:__init(y, m, d, h, i, s, f, z)
self.minute = tonumber(i or 0)
self.second = tonumber(s or 0)
if type(f) == 'string' and sfind(f, '^%d+$') then
self.fraction = tonumber(f) * math.pow(10, 3 - #f)
self.fraction = tonumber(f) * 10^(3 - #f) -- MODIFIED RESILIENT Lua min compat
elseif f then
self.fraction = f
else
Expand Down
7 changes: 5 additions & 2 deletions packages/resilient/bookmatters/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ end

-- Source: https://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
local function weightedColorDistanceIn3D (color)
return math.sqrt(math.pow(color.r * 255, 2) * 0.241 + math.pow(color.g * 255, 2) * 0.691 + math.pow(color.b * 255, 2) * 0.068)
return math.sqrt(
(color.r * 255)^2 * 0.241
+ (color.g * 255)^2 * 0.691
+ (color.b * 255)^2 * 0.068
)
end
local function contrastColor(color)
if not color.r then
Expand Down Expand Up @@ -160,7 +164,6 @@ function package:registerCommands ()
end

if metadata["meta:isbn"] then
-- local H = SILE.measurement("100%fh"):tonumber() - SILE.measurement("40mm"):tonumber()
SILE.call("skip", { height = offset })
SILE.call("kern", { width = SILE.nodefactory.hfillglue() })
SILE.call("framebox", { fillcolor = "white", padding = pad1, borderwidth = 0 }, {
Expand Down
4 changes: 3 additions & 1 deletion packages/resilient/poetry/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
--
local ast = require("silex.ast")
local createStructuredCommand = ast.createStructuredCommand
local LOG10 = math.log(10)

local base = require("packages.resilient.base")

Expand Down Expand Up @@ -178,7 +179,8 @@ function package:registerCommands ()
digitSize = SILE.shaper:measureChar("0").width
end)
local setback = SILE.length("1.75em"):absolute()
indent = SILE.length((math.floor(math.log10(nVerse + iVerse)) + 1) * digitSize):absolute()
local logv = math.floor(math.log(nVerse + iVerse) / LOG10) -- Reminder: math.log10 is not in Lua "min" profiile
indent = SILE.length((logv + 1) * digitSize):absolute()
+ setback
+ SILE.length(SILE.settings:get("document.parindent")):absolute()
end
Expand Down

0 comments on commit 0dfbb40

Please sign in to comment.