diff --git a/CairoMakie/Project.toml b/CairoMakie/Project.toml index d3c12793182..21ae3881404 100644 --- a/CairoMakie/Project.toml +++ b/CairoMakie/Project.toml @@ -14,7 +14,6 @@ GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" -StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [compat] Cairo = "1.0.4" @@ -24,7 +23,6 @@ FileIO = "1.1" FreeType = "3, 4.0" GeometryBasics = "0.4.1" Makie = "=0.16.5" -StaticArrays = "0.12, 1.0" julia = "1.3" [extras] diff --git a/CairoMakie/src/CairoMakie.jl b/CairoMakie/src/CairoMakie.jl index b97f62c5396..f2ba353cad4 100644 --- a/CairoMakie/src/CairoMakie.jl +++ b/CairoMakie/src/CairoMakie.jl @@ -1,7 +1,7 @@ module CairoMakie using Makie, LinearAlgebra -using Colors, GeometryBasics, FileIO, StaticArrays +using Colors, GeometryBasics, FileIO import SHA import Base64 import Cairo diff --git a/CairoMakie/src/precompiles.jl b/CairoMakie/src/precompiles.jl index 6d38f7bf1e4..cb1739eac48 100644 --- a/CairoMakie/src/precompiles.jl +++ b/CairoMakie/src/precompiles.jl @@ -6,5 +6,49 @@ function _precompile_() f, ax2, pl = lines(1:4) Makie.colorbuffer(ax1.scene) Makie.colorbuffer(ax2.scene) + scene = Scene() + + screen = CairoMakie.CairoScreen(scene) + + attributes = Attributes( + colormap=nothing, + colorrange=nothing, + model=Mat4f(I), + color=:red, + + ) + r = Rect2f(0, 0, 1, 1) + mesh = GeometryBasics.mesh(r) + CairoMakie.draw_mesh2D(scene, screen, attributes, mesh) + mesh = GeometryBasics.uv_mesh(r) + CairoMakie.draw_mesh2D(scene, screen, attributes, mesh) + mesh = GeometryBasics.normal_mesh(r) + CairoMakie.draw_mesh2D(scene, screen, attributes, mesh) + mesh = GeometryBasics.uv_normal_mesh(r) + CairoMakie.draw_mesh2D(scene, screen, attributes, mesh) + + color = to_color(:red) + vs = decompose(Point2f, mesh)::Vector{Point2f} + fs = decompose(GLTriangleFace, mesh)::Vector{GLTriangleFace} + uv = decompose_uv(mesh)::Union{Nothing, Vector{Vec2f}} + model = Mat4f(I) + cols = per_face_colors(color, nothing, nothing, nothing, vs, fs, nothing, uv) + CairoMakie.draw_mesh2D(scene, screen, cols, vs, fs, model) + + mesh2 = GeometryBasics.normal_mesh(Sphere(Point3f(0), 1f0)) + + attributes = Attributes( + colormap=nothing, + colorrange=nothing, + model=Mat4f(I), + color=:red, + shading=true, + diffuse=Vec3f(1), + specular=Vec3f(0), + shininess=2f0, + faceculling=true + ) + + CairoMakie.draw_mesh3D(scene, screen, attributes, mesh2) return end diff --git a/CairoMakie/src/primitives.jl b/CairoMakie/src/primitives.jl index c226eaa4943..30e72b33e83 100644 --- a/CairoMakie/src/primitives.jl +++ b/CairoMakie/src/primitives.jl @@ -320,14 +320,12 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Text{<:Tuple{ position = primitive.position[] # use cached glyph info glyph_collection = to_value(primitive[1]) - draw_glyph_collection(scene, ctx, position, glyph_collection, remove_billboard(rotation), model, space, offset) nothing end - -function draw_glyph_collection(scene, ctx, positions, glyph_collections::AbstractArray, rotation, model::SMatrix, space, offset) +function draw_glyph_collection(scene, ctx, positions, glyph_collections::AbstractArray, rotation, model::Mat, space, offset) # TODO: why is the Ref around model necessary? doesn't broadcast_foreach handle staticarrays matrices? broadcast_foreach(positions, glyph_collections, rotation, @@ -404,7 +402,7 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation, glyphpos = let # project without yflip - we need to apply model before that p = project_position(scene, position, Mat4f(I), false) - + # flip for Cairo p += (p3_to_p2(glyphoffset .+ p3_offset)) p = (_deref(model) * Vec4f(p[1], p[2], 0, 1))[Vec(1, 2)] @@ -412,7 +410,7 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation, p end # and the scale is just taken as is - scale = length(scale) == 2 ? scale : SVector(scale, scale) + scale = length(scale) == 2 ? scale : Vec(scale, scale) mat = let scale_mat = if length(scale) == 2 @@ -597,11 +595,11 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Union{Heatmap # Rectangles and polygons that are directly adjacent usually show # white lines between them due to anti aliasing. To avoid this we - # increase their size slightly. + # increase their size slightly. if alpha(colors[i, j]) == 1 - # sign.(p - center) gives the direction in which we need to - # extend the polygon. (Which may change due to rotations in the + # sign.(p - center) gives the direction in which we need to + # extend the polygon. (Which may change due to rotations in the # model matrix.) (i!=1) etc is used to avoid increasing the # outer extent of the heatmap. center = 0.25 * (p1 + p2 + p3 + p4) @@ -629,35 +627,42 @@ end ################################################################################ -function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Makie.Mesh) +function draw_atomic(scene::Scene, screen::CairoScreen, @nospecialize(primitive::Makie.Mesh)) + mesh = primitive[1][] if Makie.cameracontrols(scene) isa Union{Camera2D, Makie.PixelCamera, Makie.EmptyCamera} - draw_mesh2D(scene, screen, primitive) + draw_mesh2D(scene, screen, primitive, mesh) else if !haskey(primitive, :faceculling) primitive[:faceculling] = Observable(-10) end - draw_mesh3D(scene, screen, primitive) + draw_mesh3D(scene, screen, primitive, mesh) end return nothing end -function draw_mesh2D(scene, screen, primitive) - @get_attribute(primitive, (color,)) +function draw_mesh2D(scene, screen, @nospecialize(plot), @nospecialize(mesh)) + @get_attribute(plot, (color,)) + color = to_color(hasproperty(mesh, :color) ? mesh.color : color) + vs = decompose(Point2f, mesh)::Vector{Point2f} + fs = decompose(GLTriangleFace, mesh)::Vector{GLTriangleFace} + uv = decompose_uv(mesh)::Union{Nothing, Vector{Vec2f}} + model = plot.model[]::Mat4f + colormap = to_colormap(to_value(get(plot, :colormap, nothing)))::Union{Nothing, Vector{RGBAf}} + colorrange = to_value(get(plot, :colorrange, nothing))::Union{Nothing, Vec2f} + cols = per_face_colors(color, colormap, colorrange, nothing, vs, fs, nothing, uv) + return draw_mesh2D(scene, screen, cols, vs, fs, model) +end + +function draw_mesh2D(scene, screen, per_face_cols, + vs::Vector{Point2f}, fs::Vector{GLTriangleFace}, model::Mat4f) - colormap = get(primitive, :colormap, nothing) |> to_value |> to_colormap - colorrange = get(primitive, :colorrange, nothing) |> to_value ctx = screen.context - model = primitive.model[] - mesh = GeometryBasics.mesh(primitive[1][]) # Priorize colors of the mesh if present # This is a hack, which needs cleaning up in the Mesh plot type! - color = hasproperty(mesh, :color) ? mesh.color : color - vs = decompose(Point, mesh); fs = decompose(TriangleFace, mesh) - uv = hasproperty(mesh, :uv) ? mesh.uv : nothing + pattern = Cairo.CairoPatternMesh() - cols = per_face_colors(color, colormap, colorrange, nothing, vs, fs, nothing, uv) - for (f, (c1, c2, c3)) in zip(fs, cols) + for (f, (c1, c2, c3)) in zip(fs, per_face_cols) t1, t2, t3 = project_position.(scene, vs[f], (model,)) #triangle points Cairo.mesh_pattern_begin_patch(pattern) @@ -684,25 +689,54 @@ end nan2zero(x) = !isnan(x) * x -function draw_mesh3D( - scene, screen, primitive; - mesh = primitive[1][], pos = Vec4f(0), scale = 1f0 - ) - @get_attribute(primitive, (color, shading, diffuse, - specular, shininess, faceculling)) - colormap = get(primitive, :colormap, nothing) |> to_value |> to_colormap - colorrange = get(primitive, :colorrange, nothing) |> to_value - matcap = get(primitive, :matcap, nothing) |> to_value +function draw_mesh3D(scene, screen, attributes, mesh; pos = Vec4f(0), scale = 1f0) # Priorize colors of the mesh if present + @get_attribute(attributes, (color,)) + + colormap = to_colormap(to_value(get(attributes, :colormap, nothing))) + colorrange = to_value(get(attributes, :colorrange, nothing)) + matcap = to_value(get(attributes, :matcap, nothing)) + color = hasproperty(mesh, :color) ? mesh.color : color + meshpoints = decompose(Point3f, mesh)::Vector{Point3f} + meshfaces = decompose(GLTriangleFace, mesh)::Vector{GLTriangleFace} + meshnormals = decompose_normals(mesh)::Vector{Vec3f} + meshuvs = texturecoordinates(mesh)::Union{Nothing, Vector{Vec2f}} + + lowclip = color_or_nothing(to_value(get(attributes, :lowclip, nothing)))::Union{Nothing, RGBAf} + highclip = color_or_nothing(to_value(get(attributes, :highclip, nothing)))::Union{Nothing, RGBAf} + nan_color = color_or_nothing(to_value(get(attributes, :nan_color, nothing)))::Union{Nothing, RGBAf} + + per_face_col = per_face_colors( + color, colormap, colorrange, matcap, meshfaces, meshnormals, meshuvs, + lowclip, highclip, nan_color + ) + + @get_attribute(attributes, (shading, diffuse, + specular, shininess, faceculling)) + + model = attributes.model[]::Mat4f + + draw_mesh3D( + scene, screen, meshpoints, meshfaces, meshnormals, per_face_col, pos, scale, + model, shading::Bool, diffuse::Vec3f, + specular::Vec3f, shininess::Float32, faceculling::Bool + ) +end + +function draw_mesh3D( + scene, screen, meshpoints, meshfaces, meshnormals, per_face_col, pos, scale, + model, shading, diffuse, + specular, shininess, faceculling + ) + - ctx = screen.context - model = primitive.model[] + ctx = screen.context view = scene.camera.view[] projection = scene.camera.projection[] - i = SOneTo(3) + i = Vec(1, 2, 3) normalmatrix = transpose(inv(view[i, i] * model[i, i])) # Mesh data @@ -710,21 +744,14 @@ function draw_mesh3D( func = Makie.transform_func_obs(scene)[] # pass func as argument to function, so that we get a function barrier # and have `func` be fully typed inside closure - vs = broadcast(decompose(Point, mesh), (func,)) do v, f + vs = broadcast(meshpoints, (func,)) do v, f # Should v get a nan2zero? v = Makie.apply_transform(f, v) p4d = to_ndim(Vec4f, scale .* to_ndim(Vec3f, v, 0f0), 1f0) view * (model * p4d .+ to_ndim(Vec4f, pos, 0f0)) end - fs = decompose(GLTriangleFace, mesh) - uv = texturecoordinates(mesh) - ns = map(n -> normalize(normalmatrix * n), decompose_normals(mesh)) - cols = per_face_colors( - color, colormap, colorrange, matcap, vs, fs, ns, uv, - get(primitive, :lowclip, nothing) |> to_value |> color_or_nothing, - get(primitive, :highclip, nothing) |> to_value |> color_or_nothing, - get(primitive, :nan_color, nothing) |> to_value |> color_or_nothing - ) + + ns = map(n -> normalize(normalmatrix * n), meshnormals) # Liight math happens in view/camera space pointlight = Makie.get_point_light(scene) @@ -750,29 +777,29 @@ function draw_mesh3D( @inbounds begin p = (clip ./ clip[4])[Vec(1, 2)] p_yflip = Vec2f(p[1], -p[2]) - p_0_to_1 = (p_yflip .+ 1f0) / 2f0 + p_0_to_1 = (p_yflip .+ 1f0) ./ 2f0 end p = p_0_to_1 .* scene.camera.resolution[] return Vec3f(p[1], p[2], clip[3]) end # Approximate zorder - zorder = sortperm(fs, by = f -> average_z(ts, f)) + zorder = sortperm(meshfaces, by = f -> average_z(ts, f)) # Face culling - zorder = filter(i -> any(last.(ns[fs[i]]) .> faceculling), zorder) + zorder = filter(i -> any(last.(ns[meshfaces[i]]) .> faceculling), zorder) pattern = Cairo.CairoPatternMesh() for k in reverse(zorder) - f = fs[k] + f = meshfaces[k] t1, t2, t3 = ts[f] # light calculation c1, c2, c3 = if shading - map(ns[f], vs[f], cols[k]) do N, v, c + map(ns[f], vs[f], per_face_col[k]) do N, v, c L = normalize(lightpos .- v[Vec(1,2,3)]) diff_coeff = max(dot(L, N), 0.0) - H = normalize(L + normalize(-v[SOneTo(3)])) + H = normalize(L + normalize(-v[Vec(1, 2, 3)])) spec_coeff = max(dot(H, N), 0.0)^shininess c = RGBA(c) new_c = (ambient .+ diff_coeff .* diffuse) .* Vec3f(c.r, c.g, c.b) .+ @@ -780,7 +807,7 @@ function draw_mesh3D( RGBA(new_c..., c.alpha) end else - cols[k] + per_face_col[k] end # debug normal coloring # n1, n2, n3 = Vec3f(0.5) .+ 0.5ns[f] @@ -822,7 +849,7 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Makie.Surface if !haskey(primitive, :faceculling) primitive[:faceculling] = Observable(-10) end - draw_mesh3D(scene, screen, primitive, mesh=mesh) + draw_mesh3D(scene, screen, primitive, mesh) primitive[:color] = old return nothing end @@ -912,7 +939,7 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Makie.MeshSca scale = markersize isa Vector ? markersize[i] : markersize draw_mesh3D( - scene, screen, submesh, mesh = m, pos = p, + scene, screen, submesh, m, pos = p, scale = scale isa Real ? Vec3f(scale) : to_ndim(Vec3f, scale, 1f0) ) end diff --git a/CairoMakie/src/utils.jl b/CairoMakie/src/utils.jl index 20141addff2..3ab3f428955 100644 --- a/CairoMakie/src/utils.jl +++ b/CairoMakie/src/utils.jl @@ -16,7 +16,7 @@ function project_position(scene, point, model, yflip = true) # flip y to match cairo p_yflip = Vec2f(p[1], (1f0 - 2f0 * yflip) * p[2]) # normalize to between 0 and 1 - p_0_to_1 = (p_yflip .+ 1f0) / 2f0 + p_0_to_1 = (p_yflip .+ 1f0) ./ 2f0 end # multiply with scene resolution for final position return p_0_to_1 .* res @@ -189,10 +189,10 @@ Base.getindex(fi::FaceIterator{:PerFace}, i::Integer) = fi.data[i] Base.getindex(fi::FaceIterator{:PerVert}, i::Integer) = fi.data[fi.faces[i]] Base.getindex(fi::FaceIterator{:Const}, i::Integer) = ntuple(i-> fi.data, 3) -color_or_nothing(c) = c === nothing ? nothing : to_color(c) +color_or_nothing(c) = isnothing(c) ? nothing : to_color(c) function per_face_colors( - color, colormap, colorrange, matcap, vertices, faces, normals, uv, + color, colormap, colorrange, matcap, faces, normals, uv, lowclip=nothing, highclip=nothing, nan_color=nothing ) if matcap !== nothing diff --git a/Project.toml b/Project.toml index 2ee2d8f8f4e..5e8901d7db0 100644 --- a/Project.toml +++ b/Project.toml @@ -43,7 +43,6 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" SignedDistanceFields = "73760f76-fbc4-59ce-8f25-708e95d2df96" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" @@ -83,7 +82,6 @@ PolygonOps = "0.1.1" RelocatableFolders = "0.1, 0.2" Showoff = "0.3, 1.0.2" SignedDistanceFields = "0.4" -StaticArrays = "0.12, 1.0" StatsBase = "0.31, 0.32, 0.33" StatsFuns = "0.9" StructArrays = "0.3, 0.4, 0.5, 0.6" diff --git a/metrics/ttfp/custom-benchmarks.jl b/metrics/ttfp/custom-benchmarks.jl new file mode 100644 index 00000000000..5cd8fc68f64 --- /dev/null +++ b/metrics/ttfp/custom-benchmarks.jl @@ -0,0 +1,33 @@ +cd(@__DIR__) +using Pkg +Pkg.activate(".") +Pkg.instantiate() +using JSON, Statistics, GitHub, Base64, SHA, Downloads, Dates, CairoMakie + +include("benchmark-library.jl") + +ctx = github_context() + +project = "current-pr-project/" +# It seems, that between julia versions, the manifest must be deleted to not get problems +isdir(project) && rm(project; force=true, recursive=true) +mkdir(project) + +Pkg.activate(project) +Pkg.develop([(;path="../../MakieCore"), (;path="../../"), (;path="../../CairoMakie"), (;path="../../../GeometryBasics")]) +this_pr = BenchInfo( + project=project, + branch="current-pr", + commit=string(current_commit()) +) + +Pkg.activate(".") + +get_benchmark_data(ctx, this_pr; n=10, force=true) + +plot_url = run_benchmarks(ctx, [GitHub.branch(ctx.repo, "master"), this_pr]) + + +i1 = BenchInfo(commit="444eae5ce174d23d53c181144b357382bd57afa8") +i2 = BenchInfo(commit="7ccf35e789fccdda2429b39b6b10f4e91adcc5fd") +plot_url = run_benchmarks(ctx, [i2, i1]) diff --git a/src/Makie.jl b/src/Makie.jl index f02668671c9..8e11b20b953 100644 --- a/src/Makie.jl +++ b/src/Makie.jl @@ -27,7 +27,6 @@ using Markdown using DocStringExtensions # documentation using Serialization # serialize events using StructArrays -using StaticArrays # Text related packages using FreeType using FreeTypeAbstraction @@ -48,7 +47,7 @@ import SparseArrays using MakieCore using OffsetArrays -using GeometryBasics: widths, positive_widths, VecTypes, AbstractPolygon, value +using GeometryBasics: widths, positive_widths, VecTypes, AbstractPolygon, value, StaticVector using Distributions: Distribution, VariateForm, Discrete, QQPair, pdf, quantile, qqbuild import FileIO: save diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index f57704e2479..19de43f99e9 100644 --- a/src/basic_recipes/axis.jl +++ b/src/basic_recipes/axis.jl @@ -245,7 +245,7 @@ function draw_axis3d(textbuffer, linebuffer, scale, limits, ranges_labels, args. axisnames_size = (%) .* axisnames_size # index of the direction in which ticks and labels are drawn - offset_indices = [ifelse(i != 2, mod1(i + 1, N), 1) for i in 1:N] + offset_indices = Vec(ntuple(i-> ifelse(i != 2, mod1(i + 1, N), 1), N)) # These need the real limits, not (%), to be scale-aware titlegap = 0.01limit_widths[offset_indices] .* titlegap tgap = 0.01limit_widths[offset_indices] .* tgap diff --git a/src/camera/camera.jl b/src/camera/camera.jl index 8203db11084..e10d465b31a 100644 --- a/src/camera/camera.jl +++ b/src/camera/camera.jl @@ -81,7 +81,7 @@ function Camera(px_area) view = Observable(Mat4f(I)) proj = Observable(Mat4f(I)) proj_view = map(*, proj, view) - Camera( + return Camera( pixel_space, view, proj, diff --git a/src/camera/camera2d.jl b/src/camera/camera2d.jl index f9502da5608..3a9a07c9024 100644 --- a/src/camera/camera2d.jl +++ b/src/camera/camera2d.jl @@ -267,8 +267,6 @@ function reset!(cam, boundingbox, preserveratio = true) return end - - function add_restriction!(cam, window, rarea::Rect2, minwidths::Vec) area_ref = Base.RefValue(cam[Area]) restrict_action = paused_action(1.0) do t diff --git a/src/camera/camera3d.jl b/src/camera/camera3d.jl index 505a23c9ed1..60daf5cb6f2 100644 --- a/src/camera/camera3d.jl +++ b/src/camera/camera3d.jl @@ -604,7 +604,7 @@ function update_cam!(scene::Scene, camera::Camera3D, area3d::Rect) @extractvalue camera (lookat, eyeposition, upvector) bb = Rect3f(area3d) width = widths(bb) - half_width = width/2f0 + half_width = width ./ 2f0 middle = maximum(bb) - half_width old_dir = normalize(eyeposition .- lookat) camera.lookat[] = middle diff --git a/src/camera/projection_math.jl b/src/camera/projection_math.jl index bd4f718020e..2b61acc18ce 100644 --- a/src/camera/projection_math.jl +++ b/src/camera/projection_math.jl @@ -158,9 +158,9 @@ function orthographicprojection( end function orthographicprojection( - left ::T, right::T, - bottom::T, top ::T, - znear ::T, zfar ::T + left::T, right::T, + bottom::T, top::T, + znear::T, zfar::T ) where T (right==left || bottom==top || znear==zfar) && return Mat{4,4,T}(I) T0, T1, T2 = zero(T), one(T), T(2) diff --git a/src/conversions.jl b/src/conversions.jl index 9b694f5ba95..c3f8b8d1d5f 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -740,15 +740,16 @@ convert_attribute(p, ::key"lowclip") = to_color(p) convert_attribute(p::Nothing, ::key"lowclip") = p convert_attribute(p, ::key"nan_color") = to_color(p) -struct Palette{N} - colors::SArray{Tuple{N},RGBA{Float32},1,N} - i::Ref{UInt8} - Palette(colors) = new{length(colors)}(SVector{length(colors)}(to_color.(colors)), zero(UInt8)) +struct Palette + colors::Vector{RGBA{Float32}} + i::Ref{Int} + Palette(colors) = new(to_color.(colors), zero(Int)) end Palette(name::Union{String, Symbol}, n = 8) = Palette(to_colormap(name, n)) -function convert_attribute(p::Palette{N}, ::key"color") where {N} - p.i[] = p.i[] == N ? one(UInt8) : p.i[] + one(UInt8) +function convert_attribute(p::Palette, ::key"color") + N = length(p.colors) + p.i[] = p.i[] == N ? 1 : p.i[] + 1 p.colors[p.i[]] end diff --git a/src/jl_rasterizer/main.jl b/src/jl_rasterizer/main.jl index b4ced4bce1f..da02e076081 100644 --- a/src/jl_rasterizer/main.jl +++ b/src/jl_rasterizer/main.jl @@ -1,6 +1,6 @@ using Colors, ColorVectorSpace, StaticArrays using GeometryBasics, Interpolations -using ImageView +using ImageShow using Makie: orthographicprojection @inline function edge_function(a, b, c) diff --git a/src/layouting/boundingbox.jl b/src/layouting/boundingbox.jl index 350d900c4fb..09b18e85a15 100644 --- a/src/layouting/boundingbox.jl +++ b/src/layouting/boundingbox.jl @@ -106,16 +106,16 @@ This is not perfect but works well enough. Check an A vs X to see the difference function rotatedrect(rect::Rect{2}, angle) ox, oy = rect.origin wx, wy = rect.widths - points = @SMatrix([ - ox oy; - ox oy+wy; - ox+wx oy; - ox+wx oy+wy; - ]) - mrot = @SMatrix([ - cos(angle) -sin(angle); - sin(angle) cos(angle); - ]) + points = Mat( + ox, oy, + ox, oy+wy, + ox+wx, oy, + ox+wx, oy+wy + ) + mrot = Mat( + cos(angle), -sin(angle), + sin(angle), cos(angle) + ) rotated = mrot * points' rmins = minimum(rotated, dims = 2) diff --git a/src/makielayout/layoutables/axis.jl b/src/makielayout/layoutables/axis.jl index cf0829a8033..c27d1a5c96c 100644 --- a/src/makielayout/layoutables/axis.jl +++ b/src/makielayout/layoutables/axis.jl @@ -5,9 +5,9 @@ Creates an `Axis` object in the parent `fig_or_scene` which consists of a child with orthographic projection for 2D plots and axis decorations that live in the parent. """ -function layoutable(::Type{<:Axis}, fig_or_scene::Union{Figure, Scene}; bbox = nothing, kwargs...) +function layoutable(::Type{Axis}, fig_or_scene::Union{Figure, Scene}; bbox = nothing, kwargs...) - topscene = get_topscene(fig_or_scene) + topscene = get_topscene(fig_or_scene)::Scene default_attrs = default_attributes(Axis, topscene).attributes theme_attrs = subtheme(topscene, :Axis) @@ -137,7 +137,6 @@ function layoutable(::Type{<:Axis}, fig_or_scene::Union{Figure, Scene}; bbox = n projection = Makie.orthographicprojection( leftright..., bottomtop..., nearclip, farclip) - Makie.set_proj_view!(camera(scene), projection, Makie.Mat4f(Makie.I)) end diff --git a/src/utilities/quaternions.jl b/src/utilities/quaternions.jl index c4f7d701d50..8569a9857cb 100644 --- a/src/utilities/quaternions.jl +++ b/src/utilities/quaternions.jl @@ -58,7 +58,7 @@ function Base.:(*)(quat::Quaternion, vec::StaticVector{2, T}) where T VT(x3[1], x3[2]) end -function Base.:(*)(quat::Quaternion{T}, vec::StaticVector{3}) where T +function Base.:(*)(quat::Quaternion{T}, vec::P) where {T, P <: StaticVector{3}} num = quat[1] * T(2) num2 = quat[2] * T(2) num3 = quat[3] * T(2) @@ -75,8 +75,7 @@ function Base.:(*)(quat::Quaternion{T}, vec::StaticVector{3}) where T num11 = quat[4] * num2 num12 = quat[4] * num3 - VT = similar_type(vec, StaticArrays.Size(3,)) - return VT( + return P( (1f0 - (num5 + num6)) * vec[1] + (num7 - num12) * vec[2] + (num8 + num11) * vec[3], (num7 + num12) * vec[1] + (1f0 - (num4 + num6)) * vec[2] + (num9 - num10) * vec[3], (num8 - num11) * vec[1] + (num9 + num10) * vec[2] + (1f0 - (num4 + num5)) * vec[3]