Skip to content

Commit

Permalink
Dfl/update stable hash (#3216)
Browse files Browse the repository at this point in the history
* update stable_hash usage

* update news

* Update texture_atlas.jl

---------

Co-authored-by: David Little <david.frank.little@gmail.com>
  • Loading branch information
SimonDanisch and haberdashPI authored Sep 7, 2023
1 parent 2836626 commit 882c827
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Improved Barplot Label Alignment [#3160](https://github.com/MakieOrg/Makie.jl/issues/3160).
- Fixed regression in determining axis limits [#3179](https://github.com/MakieOrg/Makie.jl/pull/3179)
- Added a theme `theme_latexfonts` that uses the latex font family as default fonts [#3147](https://github.com/MakieOrg/Makie.jl/pull/3147).
- Upgrades `StableHashTraits` from 0.3 to 1.0

## v0.19.8

Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.19.8"
[deps]
Animations = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
ColorBrewer = "a2cac450-b92f-5266-8821-25eda20663c8"
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down Expand Up @@ -95,7 +96,7 @@ Setfield = "1"
ShaderAbstractions = "0.3"
Showoff = "0.3, 1.0.2"
SignedDistanceFields = "0.4"
StableHashTraits = "0.3"
StableHashTraits = "1"
StatsBase = "0.31, 0.32, 0.33, 0.34"
StatsFuns = "0.9, 1.0"
StructArrays = "0.3, 0.4, 0.5, 0.6"
Expand Down
1 change: 1 addition & 0 deletions src/Makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ using ColorBrewer
using ColorTypes
using Colors
using ColorSchemes
using CRC32c
using Packing
using SignedDistanceFields
using Markdown
Expand Down
7 changes: 0 additions & 7 deletions src/bezier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ struct BezierPath
commands::Vector{PathCommand}
end

StableHashTraits.transform(path::BezierPath) = path.commands
StableHashTraits.transform(c::EllipticalArc) = [c.c[1], c.c[2], c.r1, c.r2, c.angle, c.a1, c.a2]
StableHashTraits.transform(c::CurveTo) = [c.c1[1], c.c1[2], c.c2[1], c.c2[2], c.p[1], c.p[2]]
StableHashTraits.transform(c::LineTo) = [c.p[1], c.p[2]]
StableHashTraits.transform(c::MoveTo) = [c.p[1], c.p[2]]
StableHashTraits.transform(c::ClosePath) = 0

# so that the same bezierpath with a different instance of a vector hashes the same
# and we don't create the same texture atlas entry twice
Base.:(==)(b1::BezierPath, b2::BezierPath) = b1.commands == b2.commands
Expand Down
9 changes: 5 additions & 4 deletions src/utilities/texture_atlas.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const SERIALIZATION_FORMAT_VERSION = "v4"

struct TextureAtlas
rectangle_packer::RectanglePacker{Int32}
Expand Down Expand Up @@ -70,8 +71,6 @@ function Base.show(io::IO, atlas::TextureAtlas)
println(io, " font_render_callback: ", length(atlas.font_render_callback))
end

const SERIALIZATION_FORMAT_VERSION = "v3"

# basically a singleton for the textureatlas
function get_cache_path(resolution::Int, pix_per_glyph::Int)
path = abspath(
Expand Down Expand Up @@ -292,14 +291,16 @@ function glyph_uv_width!(atlas::TextureAtlas, b::BezierPath)
return atlas.uv_rectangles[glyph_index!(atlas, b)]
end

crc(x, seed=UInt32(0)) = crc32c(collect(x), seed)
function insert_glyph!(atlas::TextureAtlas, glyph, font::NativeFont)
glyphindex = FreeTypeAbstraction.glyph_index(font, glyph)
hash = StableHashTraits.stable_hash((glyphindex, FreeTypeAbstraction.fontname(font)))
hash = StableHashTraits.stable_hash((glyphindex, FreeTypeAbstraction.fontname(font));
alg=crc)
return insert_glyph!(atlas, hash, (glyphindex, font))
end

function insert_glyph!(atlas::TextureAtlas, path::BezierPath)
return insert_glyph!(atlas, StableHashTraits.stable_hash(path), path)
return insert_glyph!(atlas, StableHashTraits.stable_hash(path; alg=crc), path)
end


Expand Down

0 comments on commit 882c827

Please sign in to comment.