ws-cleanup: MeshFlatten, Zip and the SVG style parser reuse Types.Scene.mul, Types.Date.civilFromDays, Raster.multiply

This commit is contained in:
4DBug committed 2026-10-31 12:31:32 -05:00
1 parent 44a599f00c
commit f5cf02026d
4 files changed
+6 -36

No files matched your search

+1
View File
@@ -821,6 +821,7 @@ local function civilFromDays(z: number): (number, number, number)
local m = if mp < 10 then mp + 3 else mp - 9
return (if m <= 2 then y + 1 else y), m, d
end
DateLib.civilFromDays = civilFromDays -- days since 1970-01-01 -> year, month, day (proleptic Gregorian)
local MDAYS = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
-- new(fields) -> Date (kind inferred from the fields present when not given)
function DateLib.new(f: { [string]: any }): Date
+1 -14
View File
@@ -109,20 +109,7 @@ end
-- ------------------------------------------------------------------------------------------------ transforms
local IDENTITY = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }
-- column-major 4x4 product a * b
local function mul(a: { number }, b: { number }): { number }
local m = table.create(16, 0)
for c = 0, 3 do
for r = 0, 3 do
local s = 0
for k = 0, 3 do
s += a[k * 4 + r + 1] * b[c * 4 + k + 1]
end
m[c * 4 + r + 1] = s
end
end
return m
end
local mul = Types.Scene.mul -- column-major 4x4 product a * b
local function numList(v: any, n: number): boolean
if type(v) ~= "table" then
+2 -12
View File
@@ -19,6 +19,7 @@
-- Never throws: corrupt archives and bad arguments return nil, Err. Parsing runs interpreted (it is cold); the native
-- code it reaches (Deflate, Crc32) does not throw either.
local Err = require("@formats/core/Err")
local Types = require("@formats/Types")
local Bytes = require("@formats/core/Bytes")
local Crc32 = require("@formats/core/Crc32")
local Deflate = require("@formats/codecs/compress/Deflate")
@@ -421,18 +422,7 @@ function Zip.writer(): any
end
-- days from 1970-01-01 to y-m-d (proleptic Gregorian)
local function civil(z: number): (number, number, number)
z += 719468
local era = (if z >= 0 then z else z - 146096) // 146097
local doe = z - era * 146097
local yoe = (doe - doe // 1460 + doe // 36524 - doe // 146096) // 365
local y = yoe + era * 400
local doy = doe - (365 * yoe + yoe // 4 - yoe // 100)
local mp = (5 * doy + 2) // 153
local d = doy - (153 * mp + 2) // 5 + 1
local m = if mp < 10 then mp + 3 else mp - 9
return (if m <= 2 then y + 1 else y), m, d
end
local civil = Types.Date.civilFromDays
local function daysFrom(y: number, m: number, d: number): number
y = if m <= 2 then y - 1 else y
local era = (if y >= 0 then y else y - 399) // 400
+2 -10
View File
@@ -4,6 +4,7 @@
-- lengths with units, transform lists, style="" declarations, and a CSS subset for <style> (rules of comma-separated
-- compound selectors made of a type, .classes, #id and *, with specificity; @rules and other combinators are skipped).
-- Never throws.
local Raster = require("@formats/codecs/image/Raster")
local Style = {}
local NAMED: { [string]: number } = {
@@ -242,16 +243,7 @@ function Style.numbers(s: string?): { number }
end
-- transform(s) -> { a, b, c, d, e, f } (the product of the list) | nil on a syntax error
local function mul(m: { number }, n: { number }): { number }
return {
m[1] * n[1] + m[3] * n[2],
m[2] * n[1] + m[4] * n[2],
m[1] * n[3] + m[3] * n[4],
m[2] * n[3] + m[4] * n[4],
m[1] * n[5] + m[3] * n[6] + m[5],
m[2] * n[5] + m[4] * n[6] + m[6],
}
end
local mul = Raster.multiply
Style.multiply = mul
function Style.transform(s: string): { number }?
local m = { 1, 0, 0, 1, 0, 0 }