Glyph baking: comparator-free edge sort (atlas pixels unchanged)
This commit is contained in:
1 parent
3a4fc158fa
commit
48ee9270f6
5 files changed
+113
-5
No files matched your search
Generated
+37
-1
@@ -72441,6 +72441,42 @@ local function stbtt__sort_edges(p)
|
||||
STBTT_sort(p, STBTT__COMPARE)
|
||||
end
|
||||
|
||||
-- [Luau] sorts p[lo..hi] by y0 without a comparator callback (like upstream's stbtt__sort_edges_quicksort + ins_sort)
|
||||
|
||||
local function stbtt__sort_edges_range(p, lo, hi)
|
||||
while hi - lo > 12 do
|
||||
-- median of three -> p[lo]
|
||||
local m = math.floor((lo + hi) / 2)
|
||||
local a, b, c = p[lo], p[m], p[hi]
|
||||
if b.y0 < a.y0 then a, b = b, a end
|
||||
if c.y0 < b.y0 then b, c = c, b; if b.y0 < a.y0 then a, b = b, a end end
|
||||
p[lo], p[m], p[hi] = b, a, c
|
||||
local pivot = p[lo].y0
|
||||
local i, j = lo + 1, hi
|
||||
while true do
|
||||
while p[i].y0 < pivot do i = i + 1 end
|
||||
while pivot < p[j].y0 do j = j - 1 end
|
||||
if i >= j then break end
|
||||
p[i], p[j] = p[j], p[i]
|
||||
i = i + 1; j = j - 1
|
||||
end
|
||||
p[lo], p[j] = p[j], p[lo]
|
||||
-- recurse into the smaller side, loop on the larger
|
||||
if j - lo < hi - j then
|
||||
stbtt__sort_edges_range(p, lo, j - 1); lo = j + 1
|
||||
else
|
||||
stbtt__sort_edges_range(p, j + 1, hi); hi = j - 1
|
||||
end
|
||||
end
|
||||
for i = lo + 1, hi do
|
||||
local t = p[i]
|
||||
local y = t.y0
|
||||
local j = i - 1
|
||||
while j >= lo and p[j].y0 > y do p[j + 1] = p[j]; j = j - 1 end
|
||||
p[j + 1] = t
|
||||
end
|
||||
end
|
||||
|
||||
--- @param result stbtt__bitmap
|
||||
--- @param pts stbtt__point[]
|
||||
--- @param wcount int[]
|
||||
@@ -72515,7 +72551,7 @@ local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y,
|
||||
end
|
||||
|
||||
-- now sort the edges by their highest point (should snap to integer, and then by x)
|
||||
stbtt__sort_edges(e)
|
||||
stbtt__sort_edges_range(e, 1, n) -- [Luau] e[n + 1..] are y0 == nil sentinels, already last
|
||||
|
||||
-- now, traverse the scanlines and find the intersections on each scanline, use xor winding rule
|
||||
stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y)
|
||||
|
||||
Reference in new issue
Block a user