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 cfb4c9a916f..93e4bdc174e 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/primitives.jl b/CairoMakie/src/primitives.jl index c21578d4769..e37c91cca8f 100644 --- a/CairoMakie/src/primitives.jl +++ b/CairoMakie/src/primitives.jl @@ -309,7 +309,7 @@ end function p3_to_p2(p::Point3{T}) where T if p[3] == 0 || isnan(p[3]) - Point2{T}(p[1:2]...) + Point2{T}(p[Vec(1,2)]...) else error("Can't reduce Point3 to Point2 with nonzero third component $(p[3]).") end @@ -333,7 +333,7 @@ end function draw_glyph_collection( scene, ctx, positions, glyph_collections::AbstractArray, rotation, - model::SMatrix, space, markerspace, offset + model::Mat, space, markerspace, offset ) # TODO: why is the Ref around model necessary? doesn't broadcast_foreach handle staticarrays matrices? @@ -377,7 +377,7 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation, # offsets and scale apply in markerspace glyph_pos = s2ms * to_ndim(Point4f, to_ndim(Point3f, position, 0), 1) - gp3 = glyph_pos[SOneTo(3)] ./ glyph_pos[4] .+ glyphoffset .+ p3_offset + gp3 = glyph_pos[Vec(1, 2, 3)] ./ glyph_pos[4] .+ glyphoffset .+ p3_offset scale3 = scale isa Number ? Point3f(scale, scale, 0) : to_ndim(Point3f, scale, 0) @@ -663,16 +663,16 @@ function draw_mesh3D( @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 + colormap = to_colormap(to_value(get(primitive, :colormap, nothing))) + colorrange = to_value(get(primitive, :colorrange, nothing)) + matcap = to_value(get(primitive, :matcap, nothing)) # Priorize colors of the mesh if present color = hasproperty(mesh, :color) ? mesh.color : color ctx = screen.context model = primitive.model[] - space = to_value(get(primitive, :space, :data)) + space = to_value(get(primitive, :space, :data))::Symbol view = ifelse(is_data_space(space), scene.camera.view[], Mat4f(I)) projection = Makie.space_to_clip(scene.camera, space, false) i = Vec(1, 2, 3) @@ -694,9 +694,9 @@ function draw_mesh3D( 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 + color_or_nothing(to_value(get(primitive, :lowclip, nothing))) , + color_or_nothing(to_value(get(primitive, :highclip, nothing))) , + color_or_nothing(to_value(get(primitive, :nan_color, nothing))) ) # Liight math happens in view/camera space @@ -723,7 +723,7 @@ 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]) @@ -745,7 +745,7 @@ function draw_mesh3D( map(ns[f], vs[f], cols[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) .+ diff --git a/CairoMakie/src/utils.jl b/CairoMakie/src/utils.jl index 466b4a9b670..a3c5fe887f8 100644 --- a/CairoMakie/src/utils.jl +++ b/CairoMakie/src/utils.jl @@ -16,7 +16,7 @@ function project_position(scene, space, 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 @@ -199,7 +199,7 @@ 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, diff --git a/GLMakie/src/GLAbstraction/GLAbstraction.jl b/GLMakie/src/GLAbstraction/GLAbstraction.jl index 2e3813fbeec..45222400366 100644 --- a/GLMakie/src/GLAbstraction/GLAbstraction.jl +++ b/GLMakie/src/GLAbstraction/GLAbstraction.jl @@ -1,6 +1,5 @@ module GLAbstraction -using StaticArrays using GeometryBasics using ModernGL using Makie @@ -12,6 +11,7 @@ using LinearAlgebra using Observables using ShaderAbstractions using ShaderAbstractions: current_context, is_context_active, context_alive +using GeometryBasics: StaticVector import FixedPointNumbers: N0f8, N0f16, N0f8, Normed @@ -100,9 +100,4 @@ export getUniformsInfo export getProgramInfo export getAttributesInfo -if Base.VERSION >= v"1.4.2" - include("precompile.jl") - _precompile_() -end - end # module diff --git a/GLMakie/src/GLAbstraction/GLUniforms.jl b/GLMakie/src/GLAbstraction/GLUniforms.jl index a8214a5aece..487d2f268b6 100644 --- a/GLMakie/src/GLAbstraction/GLUniforms.jl +++ b/GLMakie/src/GLAbstraction/GLUniforms.jl @@ -5,7 +5,7 @@ const GLSL_COMPATIBLE_NUMBER_TYPES = (GLfloat, GLint, GLuint, GLdouble) const NATIVE_TYPES = Union{ - StaticArray, GLSL_COMPATIBLE_NUMBER_TYPES..., + StaticVector, Mat, GLSL_COMPATIBLE_NUMBER_TYPES..., ZeroIndex{GLint}, ZeroIndex{GLuint}, GLBuffer, GPUArray, Shader, GLProgram } @@ -33,7 +33,7 @@ function uniformfunc(typ::DataType, dims::Tuple{Int, Int}) Symbol(string("glUniformMatrix", M == N ? "$M" : "$(M)x$(N)", opengl_postfix(typ))) end -function gluniform(location::Integer, x::FSA) where FSA <: Union{StaticArray, Colorant} +function gluniform(location::Integer, x::Union{StaticVector, Mat, Colorant}) xref = [x] gluniform(location, xref) end @@ -44,7 +44,7 @@ _size(p::Type{T}) where {T <: Colorant} = (length(p),) _ndims(p) = ndims(p) _ndims(p::Type{T}) where {T <: Colorant} = 1 -@generated function gluniform(location::Integer, x::Vector{FSA}) where FSA <: Union{StaticArray, Colorant} +@generated function gluniform(location::Integer, x::Vector{FSA}) where FSA <: Union{Mat, Colorant, StaticVector} func = uniformfunc(eltype(FSA), _size(FSA)) callexpr = if _ndims(FSA) == 2 :($func(location, length(x), GL_FALSE, x)) @@ -101,12 +101,12 @@ function glsl_typename(t::Texture{T, D}) where {T, D} str end -function glsl_typename(t::Type{T}) where T <: SMatrix +function glsl_typename(t::Type{T}) where T <: Mat M, N = size(t) string(opengl_prefix(eltype(t)), "mat", M==N ? M : string(M, "x", N)) end toglsltype_string(t::Observable) = toglsltype_string(to_value(t)) -toglsltype_string(x::T) where {T<:Union{Real, StaticArray, Texture, Colorant, TextureBuffer, Nothing}} = "uniform $(glsl_typename(x))" +toglsltype_string(x::T) where {T<:Union{Real, Mat, StaticVector, Texture, Colorant, TextureBuffer, Nothing}} = "uniform $(glsl_typename(x))" #Handle GLSL structs, which need to be addressed via single fields function toglsltype_string(x::T) where T if isa_gl_struct(x) @@ -124,7 +124,7 @@ function glsl_variable_access(keystring, t::Texture{T, D}) where {T,D} end return string("getindex(", keystring, "index).", fields, ";") end -function glsl_variable_access(keystring, ::Union{Real, GLBuffer, GPUVector, StaticArray, Colorant}) +function glsl_variable_access(keystring, ::Union{Real, GLBuffer, GPUVector, Mat, Colorant}) string(keystring, ";") end function glsl_variable_access(keystring, s::Observable) @@ -183,8 +183,8 @@ gl_promote(x::Type{T}) where {T <: Color4} = RGBA{gl_promote(eltype(T))} gl_promote(x::Type{T}) where {T <: BGRA} = BGRA{gl_promote(eltype(T))} gl_promote(x::Type{T}) where {T <: BGR} = BGR{gl_promote(eltype(T))} - -gl_promote(x::Type{T}) where {T <: StaticVector} = similar_type(T, gl_promote(eltype(T))) +gl_promote(x::Type{Vec{N, T}}) where {N, T} = Vec{N, gl_promote(T)} +gl_promote(x::Type{Point{N, T}}) where {N, T} = Point{N, gl_promote(T)} gl_convert(x::AbstractVector{Vec3f}) = x @@ -225,7 +225,7 @@ gl_convert(a::T) where {T <: NATIVE_TYPES} = a gl_convert(s::Observable{T}) where {T <: NATIVE_TYPES} = s gl_convert(s::Observable{T}) where T = const_lift(gl_convert, s) gl_convert(x::StaticVector{N, T}) where {N, T} = map(gl_promote(T), x) -gl_convert(x::SMatrix{N, M, T}) where {N, M, T} = map(gl_promote(T), x) +gl_convert(x::Mat{N, M, T}) where {N, M, T} = map(gl_promote(T), x) gl_convert(a::AbstractVector{<: AbstractFace}) = indexbuffer(s) gl_convert(t::Type{T}, a::T; kw_args...) where T <: NATIVE_TYPES = a gl_convert(::Type{<: GPUArray}, a::StaticVector) = gl_convert(a) diff --git a/GLMakie/src/GLAbstraction/precompile.jl b/GLMakie/src/GLAbstraction/precompile.jl deleted file mode 100644 index da3c7c61eb9..00000000000 --- a/GLMakie/src/GLAbstraction/precompile.jl +++ /dev/null @@ -1,107 +0,0 @@ -const __bodyfunction__ = Dict{Method,Any}() - -# Find keyword "body functions" (the function that contains the body -# as written by the developer, called after all missing keyword-arguments -# have been assigned values), in a manner that doesn't depend on -# gensymmed names. -# `mnokw` is the method that gets called when you invoke it without -# supplying any keywords. -function __lookup_kwbody__(mnokw::Method) - function getsym(arg) - isa(arg, Symbol) && return arg - @assert isa(arg, GlobalRef) - return arg.name - end - - f = get(__bodyfunction__, mnokw, nothing) - if f === nothing - fmod = mnokw.module - # The lowered code for `mnokw` should look like - # %1 = mkw(kwvalues..., #self#, args...) - # return %1 - # where `mkw` is the name of the "active" keyword body-function. - ast = Base.uncompressed_ast(mnokw) - if isa(ast, Core.CodeInfo) && length(ast.code) >= 2 - callexpr = ast.code[end-1] - if isa(callexpr, Expr) && callexpr.head == :call - fsym = callexpr.args[1] - if isa(fsym, Symbol) - f = getfield(fmod, fsym) - elseif isa(fsym, GlobalRef) - if fsym.mod === Core && fsym.name === :_apply - f = getfield(mnokw.module, getsym(callexpr.args[2])) - elseif fsym.mod === Core && fsym.name === :_apply_iterate - f = getfield(mnokw.module, getsym(callexpr.args[3])) - else - f = getfield(fsym.mod, fsym.name) - end - else - f = missing - end - else - f = missing - end - else - f = missing - end - __bodyfunction__[mnokw] = f - end - return f -end - -function _precompile_() - ccall(:jl_generating_output, Cint, ()) == 1 || return nothing - Base.precompile(Tuple{typeof(get_template!),String,Dict{String, String},Dict{Symbol, Any}}) # time: 0.21933882 - isdefined(GLAbstraction, Symbol("#63#68")) && Base.precompile(Tuple{getfield(GLAbstraction, Symbol("#63#68"))}) # time: 0.086304404 - Base.precompile(Tuple{typeof(gluniform),Int32,Observable{Vec{2, Float32}}}) # time: 0.06477806 - Base.precompile(Tuple{Core.kwftype(typeof(Type)),NamedTuple{(:x_repeat,), Tuple{Symbol}},Type{Texture},Vector{Float16}}) # time: 0.03858548 - Base.precompile(Tuple{typeof(signal_convert),Type,Observable{Vec2{Int32}}}) # time: 0.038141333 - Base.precompile(Tuple{typeof(gl_convert),Type{GLBuffer},Observable{Vec{2, Float32}}}) # time: 0.031721786 - Base.precompile(Tuple{typeof(toglsltype_string),GLBuffer{Point{3, Float32}}}) # time: 0.03062245 - Base.precompile(Tuple{typeof(signal_convert),Type,Observable{Float32}}) # time: 0.022515636 - Base.precompile(Tuple{typeof(compile_program),Vector{Shader},Vector{Tuple{Int64, String}}}) # time: 0.021999607 - let fbody = try __lookup_kwbody__(which(TextureParameters, (Type,Int64,))) catch missing end - if !ismissing(fbody) - precompile(fbody, (Symbol,Symbol,Symbol,Symbol,Symbol,Float32,Type{TextureParameters},Type,Int64,)) - end - end # time: 0.019532876 - Base.precompile(Tuple{typeof(gl_convert),Observable{Any}}) # time: 0.01664884 - Base.precompile(Tuple{typeof(gl_convert),Observable{Bool}}) # time: 0.0149467 - Base.precompile(Tuple{typeof(gl_convert),Observable{RGBA{Float32}}}) # time: 0.014625993 - Base.precompile(Tuple{typeof(const_lift),typeof(length),Observable{Vector{Point{2, Float32}}}}) # time: 0.014371832 - Base.precompile(Tuple{typeof(gl_convert),Type{GLBuffer},Observable{Vector{Point{3, Float32}}}}) # time: 0.01388594 - Base.precompile(Tuple{typeof(gl_convert),Observable{Int64}}) # time: 0.01345424 - Base.precompile(Tuple{typeof(const_lift),typeof(length),Observable{Vector{Point{3, Float32}}}}) # time: 0.011757969 - Base.precompile(Tuple{typeof(gl_convert),Type{GLBuffer},Observable{Vector{Vec{2, Float32}}}}) # time: 0.011719398 - isdefined(GLAbstraction, Symbol("#LazyShader#49#50")) && Base.precompile(Tuple{getfield(GLAbstraction, Symbol("#LazyShader#49#50")),Base.Iterators.Pairs{Symbol, Dict{String, String}, Tuple{Symbol}, NamedTuple{(:view,), Tuple{Dict{String, String}}}},Type{LazyShader},String,Vararg{String, N} where N}) # time: 0.010064982 - Base.precompile(Tuple{typeof(gl_convert),Type{GLBuffer},Observable{Vector{Vec{4, Float32}}}}) # time: 0.008807838 - isdefined(GLAbstraction, Symbol("#63#68")) && Base.precompile(Tuple{getfield(GLAbstraction, Symbol("#63#68"))}) # time: 0.008238689 - Base.precompile(Tuple{typeof(gl_convert),Type{GLBuffer},Observable{Vector{Point{2, Float32}}}}) # time: 0.008220657 - Base.precompile(Tuple{typeof(gl_convert),Type{GLBuffer},Observable{Vector{RGBA{Float32}}}}) # time: 0.007779626 - Base.precompile(Tuple{typeof(toglsltype_string),GLBuffer{Vec{4, Float32}}}) # time: 0.007245759 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{Int64}}) # time: 0.00689424 - Base.precompile(Tuple{typeof(toglsltype_string),Texture{Float16, 2}}) # time: 0.006558549 - Base.precompile(Tuple{typeof(gl_convert),Type{GLBuffer},Observable{Vector{Float32}}}) # time: 0.006534443 - Base.precompile(Tuple{typeof(gl_convert),SMatrix{4, 4, Float32, 16}}) # time: 0.0058618 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{Float32}}) # time: 0.005198346 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{Any}}) # time: 0.004741108 - Base.precompile(Tuple{typeof(toglsltype_string),Texture{Float16, 1}}) # time: 0.004597425 - Base.precompile(Tuple{typeof(toglsltype_string),GLBuffer{RGBA{Float32}}}) # time: 0.00437181 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{Vec2{Int32}}}) # time: 0.004354946 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{Int32}}) # time: 0.004301191 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{SMatrix{4, 4, Float32, 16}}}) # time: 0.004184706 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{Vec{3, Float32}}}) # time: 0.004105391 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{Vec{2, Float32}}}) # time: 0.004101697 - Base.precompile(Tuple{typeof(toglsltype_string),GLBuffer{Point{2, Float32}}}) # time: 0.003962705 - Base.precompile(Tuple{typeof(toglsltype_string),GLBuffer{Vec{2, Float32}}}) # time: 0.003796558 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{RGBA{Float32}}}) # time: 0.003778398 - Base.precompile(Tuple{typeof(isa_gl_struct),Observable{Bool}}) # time: 0.00368915 - Base.precompile(Tuple{typeof(isa_gl_struct),Dict{Symbol, Any}}) # time: 0.003686279 - Base.precompile(Tuple{typeof(isa_gl_struct),Nothing}) # time: 0.003181062 - Base.precompile(Tuple{typeof(isa_gl_struct),Symbol}) # time: 0.003076398 - Base.precompile(Tuple{typeof(isa_gl_struct),Bool}) # time: 0.003013663 - Base.precompile(Tuple{typeof(gl_convert),Vec{2, Float32}}) # time: 0.002978386 - Base.precompile(Tuple{typeof(mustache2replacement),String,Dict{String, String},Dict{Symbol, Any}}) # time: 0.002830558 - Base.precompile(Tuple{typeof(gluniform),Int32,Int64,Texture{RGBA{N0f8}, 2}}) # time: 0.002434047 - Base.precompile(Tuple{typeof(map_texture_paramers),Tuple{Symbol, Symbol}}) # time: 0.00121505 -end diff --git a/GLMakie/src/GLMakie.jl b/GLMakie/src/GLMakie.jl index d5f978e8290..a183b376703 100644 --- a/GLMakie/src/GLMakie.jl +++ b/GLMakie/src/GLMakie.jl @@ -1,6 +1,6 @@ module GLMakie -using ModernGL, FixedPointNumbers, Colors, GeometryBasics, StaticArrays +using ModernGL, FixedPointNumbers, Colors, GeometryBasics using Makie, FileIO using Makie: @key_str, Key, broadcast_foreach, to_ndim, NativeFont @@ -12,6 +12,7 @@ using Makie: inline! using Makie: spaces, is_data_space, is_pixel_space, is_relative_space, is_clip_space using ShaderAbstractions using FreeTypeAbstraction +using GeometryBasics: StaticVector using Base: RefValue import Base: push!, isopen, show diff --git a/GLMakie/src/GLVisualize/GLVisualize.jl b/GLMakie/src/GLVisualize/GLVisualize.jl index e27fb3937ba..5361162d69b 100644 --- a/GLMakie/src/GLVisualize/GLVisualize.jl +++ b/GLMakie/src/GLVisualize/GLVisualize.jl @@ -5,7 +5,6 @@ using Makie: RaymarchAlgorithm, IsoValue, Absorption, MaximumIntensityProjection using ..GLMakie.GLFW using ModernGL -using StaticArrays using GeometryBasics using Colors using Makie @@ -13,6 +12,7 @@ using FixedPointNumbers using FileIO using Markdown using Observables +using GeometryBasics: StaticVector import Base: merge, convert, show using Base.Iterators: Repeated, repeated diff --git a/GLMakie/src/GLVisualize/visualize/particles.jl b/GLMakie/src/GLVisualize/visualize/particles.jl index b17b3c207b0..b3003107c77 100644 --- a/GLMakie/src/GLVisualize/visualize/particles.jl +++ b/GLMakie/src/GLVisualize/visualize/particles.jl @@ -78,7 +78,7 @@ function char_scale_factor(char, font) ta = Makie.get_texture_atlas() lbrt = glyph_uv_width!(ta, char, font) width = Vec(lbrt[3] - lbrt[1], lbrt[4] - lbrt[2]) - width * Vec2f(size(ta.data)) / Makie.PIXELSIZE_IN_ATLAS[] + return width .* Vec2f(size(ta.data)) ./ Makie.PIXELSIZE_IN_ATLAS[] end # This works the same for x being widths and offsets diff --git a/GLMakie/src/drawing_primitives.jl b/GLMakie/src/drawing_primitives.jl index c537c92827a..a8d239c95a4 100644 --- a/GLMakie/src/drawing_primitives.jl +++ b/GLMakie/src/drawing_primitives.jl @@ -217,7 +217,7 @@ function draw_atomic(screen::GLScreen, scene::Scene, @nospecialize(x::Union{Scat mspace = get(gl_attributes, :markerspace, :pixel) cam = scene.camera gl_attributes[:preprojection] = map(space, mspace, cam.projectionview) do space, mspace, pv - Makie.clip_to_space(cam, mspace) * Makie.space_to_clip(cam, space) + return Makie.clip_to_space(cam, mspace) * Makie.space_to_clip(cam, space) end if !(marker[] isa FastPixel) # fast pixel does its own camera setup diff --git a/GLMakie/src/glwindow.jl b/GLMakie/src/glwindow.jl index 487d790ce06..d643f609c5b 100644 --- a/GLMakie/src/glwindow.jl +++ b/GLMakie/src/glwindow.jl @@ -3,11 +3,12 @@ Selection of random objects on the screen is realized by rendering an object id + plus an arbitrary index into the framebuffer. The index can be used for e.g. instanced geometries. """ -struct SelectionID{T <: Integer} <: FieldVector{2, T} +struct SelectionID{T <: Integer} id::T index::T end - +Base.convert(::Type{SelectionID{T}}, s::SelectionID) where T = SelectionID{T}(T(s.id), T(s.index)) +Base.zero(::Type{GLMakie.SelectionID{T}}) where T = SelectionID{T}(T(0), T(0)) mutable struct GLFramebuffer resolution::Observable{NTuple{2, Int}} @@ -96,7 +97,7 @@ function GLFramebuffer(fb_size::NTuple{2, Int}) fb_size_node = Observable(fb_size) - # To allow adding postprocessors in various combinations we need to keep + # To allow adding postprocessors in various combinations we need to keep # track of the buffer ids that are already in use. We may also want to reuse # buffers so we give them names for easy fetching. buffer_ids = Dict( diff --git a/GLMakie/src/screen.jl b/GLMakie/src/screen.jl index 380b63590e5..ddc2e208e69 100644 --- a/GLMakie/src/screen.jl +++ b/GLMakie/src/screen.jl @@ -520,11 +520,11 @@ function Makie.pick_sorted(scene::Scene, screen::Screen, xy, range) picks = pick_native(screen, Rect2i(x0, y0, dx, dy)) - selected = filter(x -> x[1] > 0 && haskey(screen.cache2plot, x[1]), unique(vec(picks))) + selected = filter(x -> x.id > 0 && haskey(screen.cache2plot, x.id), unique(vec(picks))) distances = Float32[range^2 for _ in selected] x, y = xy .+ 1 .- Vec2f(x0, y0) for i in 1:dx, j in 1:dy - if picks[i, j][1] > 0 + if picks[i, j].id > 0 d = (x-i)^2 + (y-j)^2 i = findfirst(isequal(picks[i, j]), selected) if i === nothing @@ -537,7 +537,7 @@ function Makie.pick_sorted(scene::Scene, screen::Screen, xy, range) idxs = sortperm(distances) permute!(selected, idxs) - return map(id -> (screen.cache2plot[id[1]], id[2]), selected) + return map(id -> (screen.cache2plot[id.id], id.index), selected) end diff --git a/GLMakie/test/glmakie_tests.jl b/GLMakie/test/glmakie_tests.jl index f9e6aff1065..93daaeac52f 100644 --- a/GLMakie/test/glmakie_tests.jl +++ b/GLMakie/test/glmakie_tests.jl @@ -3,7 +3,6 @@ using GLMakie.GLFW using GLMakie.ModernGL using GLMakie.ShaderAbstractions using GLMakie.ShaderAbstractions: Sampler -using GLMakie.StaticArrays using GLMakie.GeometryBasics using ReferenceTests.RNG diff --git a/Project.toml b/Project.toml index 98c1fe85fb7..7dd0ef6ce23 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/ReferenceTests/src/tests/examples3d.jl b/ReferenceTests/src/tests/examples3d.jl index 52104c23f8b..5cccc4626d6 100644 --- a/ReferenceTests/src/tests/examples3d.jl +++ b/ReferenceTests/src/tests/examples3d.jl @@ -386,7 +386,7 @@ end x = loadasset("cat.obj") mesh(x, color=:black) pos = map(decompose(Point3f, x), GeometryBasics.normals(x)) do p, n - p => p .+ (normalize(n) .* 0.05f0) + p => p .+ Point(normalize(n) .* 0.05f0) end linesegments!(pos, color=:blue) current_figure() diff --git a/WGLMakie/src/WGLMakie.jl b/WGLMakie/src/WGLMakie.jl index 97f26dd6b11..6324c52e3b3 100644 --- a/WGLMakie/src/WGLMakie.jl +++ b/WGLMakie/src/WGLMakie.jl @@ -10,7 +10,6 @@ using LinearAlgebra using GeometryBasics using ImageMagick using FreeTypeAbstraction -using StaticArrays using JSServe: Session using JSServe: @js_str, onjs, Dependency, App @@ -20,6 +19,7 @@ using RelocatableFolders: @path using ShaderAbstractions: VertexArray, Buffer, Sampler, AbstractSampler using ShaderAbstractions: InstancedProgram +using GeometryBasics: StaticVector import Makie.FileIO using Makie: get_texture_atlas, glyph_uv_width!, SceneSpace, Pixel diff --git a/WGLMakie/src/imagelike.jl b/WGLMakie/src/imagelike.jl index ab1441f985b..8cca65595e7 100644 --- a/WGLMakie/src/imagelike.jl +++ b/WGLMakie/src/imagelike.jl @@ -27,7 +27,7 @@ function draw_mesh(mscene::Scene, mesh, plot; uniforms...) get!(uniforms, :ambient, Vec3f(1)) uniforms[:normalmatrix] = map(mscene.camera.view, plot.model) do v, m - i = SOneTo(3) + i = Vec(1, 2, 3) return transpose(inv(v[i, i] * m[i, i])) end diff --git a/WGLMakie/src/meshes.jl b/WGLMakie/src/meshes.jl index 32761564cab..6c9443f30e0 100644 --- a/WGLMakie/src/meshes.jl +++ b/WGLMakie/src/meshes.jl @@ -112,7 +112,7 @@ function create_shader(scene::Scene, plot::Makie.Mesh) uniforms[:depth_shift] = get(plot, :depth_shift, Observable(0f0)) uniforms[:normalmatrix] = map(scene.camera.view, plot.model) do v, m - i = SOneTo(3) + i = Vec(1, 2, 3) return transpose(inv(v[i, i] * m[i, i])) end diff --git a/WGLMakie/src/particles.jl b/WGLMakie/src/particles.jl index bb9090767f6..4498ee35556 100644 --- a/WGLMakie/src/particles.jl +++ b/WGLMakie/src/particles.jl @@ -197,7 +197,8 @@ function create_shader(scene::Scene, plot::Scatter) end value_or_first(x::AbstractArray) = first(x) -value_or_first(x::StaticArray) = x +value_or_first(x::StaticVector) = x +value_or_first(x::Mat) = x value_or_first(x) = x function create_shader(scene::Scene, plot::Makie.Text{<:Tuple{<:Union{<:Makie.GlyphCollection, <:AbstractVector{<:Makie.GlyphCollection}}}}) diff --git a/WGLMakie/src/serialization.jl b/WGLMakie/src/serialization.jl index 94165305b3e..6bfd395da25 100644 --- a/WGLMakie/src/serialization.jl +++ b/WGLMakie/src/serialization.jl @@ -140,7 +140,8 @@ end lasset(paths...) = read(joinpath(@__DIR__, "..", "assets", paths...), String) -isscalar(x::StaticArrays.StaticArray) = true +isscalar(x::StaticVector) = true +isscalar(x::Mat) = true isscalar(x::AbstractArray) = false isscalar(x::Billboard) = isscalar(x.rotation) isscalar(x::Observable) = isscalar(x[]) 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/arrows.jl b/src/basic_recipes/arrows.jl index 4b44a5b7de9..45eb6b6ed55 100644 --- a/src/basic_recipes/arrows.jl +++ b/src/basic_recipes/arrows.jl @@ -144,7 +144,7 @@ function plot!(arrowplot::Arrows{<: Tuple{AbstractVector{<: Point{N, T}}, V}}) w fxaa_bool = @lift($fxaa == automatic ? false : $fxaa) headstart = lift(points, directions, normalize, align, lengthscale) do points, dirs, n, align, s map(points, dirs) do p1, dir - dir = n ? StaticArrays.normalize(dir) : dir + dir = n ? normalize(dir) : dir if align in (:head, :lineend, :tailend, :headstart, :center) shift = s .* dir else diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index 08b31520289..daaaa38f594 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/basic_recipes/contourf.jl b/src/basic_recipes/contourf.jl index a8870b0537b..a26a7672e16 100644 --- a/src/basic_recipes/contourf.jl +++ b/src/basic_recipes/contourf.jl @@ -134,7 +134,6 @@ function Makie.plot!(c::Contourf{<:Tuple{<:AbstractVector{<:Real}, <:AbstractVec holes = polygroup[2:end] push!(polys[], GeometryBasics.Polygon(outline, holes)) # use contour level center value as color - center_scaled = (center - colorrange[][1]) / (colorrange[][2] - colorrange[][1]) push!(colors[], center) end end diff --git a/src/basic_recipes/error_and_rangebars.jl b/src/basic_recipes/error_and_rangebars.jl index 5c4991ff4f1..7881074c216 100644 --- a/src/basic_recipes/error_and_rangebars.jl +++ b/src/basic_recipes/error_and_rangebars.jl @@ -240,28 +240,28 @@ function scene_to_screen(pts, scene) p4 = to_ndim.(Vec4f, to_ndim.(Vec3f, pts, 0.0), 1.0) p1m1 = Ref(scene.camera.projectionview[]) .* p4 projected = Ref(inv(scene.camera.pixel_space[])) .* p1m1 - [Point2.(p[1:2]...) for p in projected] + [Point2.(p[Vec(1, 2)]...) for p in projected] end function screen_to_scene(pts, scene) p4 = to_ndim.(Vec4f, to_ndim.(Vec3f, pts, 0.0), 1.0) p1m1 = Ref(scene.camera.pixel_space[]) .* p4 projected = Ref(inv(scene.camera.projectionview[])) .* p1m1 - [Point2.(p[1:2]...) for p in projected] + [Point2.(p[Vec(1, 2)]...) for p in projected] end function scene_to_screen(p::T, scene) where T <: Point p4 = to_ndim(Vec4f, to_ndim(Vec3f, p, 0.0), 1.0) p1m1 = scene.camera.projectionview[] * p4 projected = inv(scene.camera.pixel_space[]) * p1m1 - T(projected[1:2]...) + T(projected[Vec(1, 2)]...) end function screen_to_scene(p::T, scene) where T <: Point p4 = to_ndim(Vec4f, to_ndim(Vec3f, p, 0.0), 1.0) p1m1 = scene.camera.pixel_space[] * p4 projected = inv(scene.camera.projectionview[]) * p1m1 - T(projected[1:2]...) + T(projected[Vec(1, 2)]...) end diff --git a/src/basic_recipes/streamplot.jl b/src/basic_recipes/streamplot.jl index 5275154bdaa..bd7ce73a290 100644 --- a/src/basic_recipes/streamplot.jl +++ b/src/basic_recipes/streamplot.jl @@ -184,7 +184,7 @@ function plot!(p::StreamPlot) rotations = lift(scene.camera.projectionview, scene.px_area, data) do pv, pxa, data angles = map(data[1], data[2]) do pos, dir pstart = project(scene, pos) - pstop = project(scene, pos + dir) + pstop = project(scene, pos .+ dir) pdir = pstop - pstart n = norm(pdir) if n == 0 diff --git a/src/basic_recipes/text.jl b/src/basic_recipes/text.jl index 65b42f57569..c7058067b4d 100644 --- a/src/basic_recipes/text.jl +++ b/src/basic_recipes/text.jl @@ -217,7 +217,7 @@ function texelems_and_glyph_collection(str::LaTeXString, fontscale_px, halign, v end xshift = if halign == :center - width(bb) / 2 + width(bb) ./ 2 elseif halign == :left minimum(bb)[1] elseif halign == :right @@ -232,7 +232,7 @@ function texelems_and_glyph_collection(str::LaTeXString, fontscale_px, halign, v minimum(bb)[2] end - positions = basepositions .- Ref(Point3f(xshift, yshift, 0)) + positions = basepositions .- Ref(Vec3f(xshift, yshift, 0)) positions .= Ref(rot) .* positions pre_align_gl = GlyphCollection( diff --git a/src/camera/camera.jl b/src/camera/camera.jl index 237780e2ffb..4a5c810ca48 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..833f8e7791b 100644 --- a/src/camera/camera3d.jl +++ b/src/camera/camera3d.jl @@ -275,10 +275,10 @@ function add_translation!(scene, cam::Camera3D) end elseif event.action == Mouse.release && dragging[] mousepos = mouseposition_px(scene) - diff = compute_diff(last_mousepos[] - mousepos) + diff = compute_diff(last_mousepos[] .- mousepos) last_mousepos[] = mousepos dragging[] = false - translate_cam!(scene, cam, translationspeed[] * Vec3f(diff[1], diff[2], 0f0)) + translate_cam!(scene, cam, translationspeed[] .* Vec3f(diff[1], diff[2], 0f0)) return Consume(true) end return Consume(false) @@ -288,7 +288,7 @@ function add_translation!(scene, cam::Camera3D) on(camera(scene), scene.events.mouseposition) do mp if dragging[] && ispressed(scene, button[]) mousepos = screen_relative(scene, mp) - diff = compute_diff(last_mousepos[] - mousepos) + diff = compute_diff(last_mousepos[] .- mousepos) last_mousepos[] = mousepos translate_cam!(scene, cam, translationspeed[] * Vec3f(diff[1], diff[2], 0f0)) return Consume(true) @@ -325,7 +325,7 @@ function add_rotation!(scene, cam::Camera3D) mousepos = mouseposition_px(scene) dragging[] = false rot_scaling = rotationspeed[] * (e.window_dpi[] * 0.005) - mp = (last_mousepos[] - mousepos) * 0.01f0 * rot_scaling + mp = (last_mousepos[] .- mousepos) .* 0.01f0 .* rot_scaling last_mousepos[] = mousepos rotate_cam!(scene, cam, Vec3f(-mp[2], mp[1], 0f0), true) return Consume(true) @@ -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/old_camera3d.jl b/src/camera/old_camera3d.jl index 352be45c02f..2d5f424cccf 100644 --- a/src/camera/old_camera3d.jl +++ b/src/camera/old_camera3d.jl @@ -264,7 +264,7 @@ function zoom!(scene, point::VecTypes, zoom_step, shift_lookat::Bool) # the offset perpendicular to `eyeposition - lookat`, based on mouse offset ~ ray_dir # the offset parallel to `eyeposition - lookat` ~ dir ray_eye = inv(scene.camera.projection[]) * Vec4f(point[1],point[2],0,0) - ray_eye = Vec4f(ray_eye[1:2]...,0,0) + ray_eye = Vec4f(ray_eye[Vec(1, 2)]...,0,0) ray_dir = Vec3f((inv(scene.camera.view[]) * ray_eye)) dir = eyeposition - lookat diff --git a/src/camera/projection_math.jl b/src/camera/projection_math.jl index 7ffcc680312..643d5f34197 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) @@ -283,7 +283,7 @@ function project(scene::Scene, point::T) where T<:StaticVector return project( cam.projectionview[] * transformationmatrix(scene)[], - Vec2f(widths(pixelarea(scene)[])), point + Vec2f(widths(pixelarea(scene)[])), Point(point) ) end @@ -296,9 +296,9 @@ end function project(proj_view::Mat4f, resolution::Vec2, point::Point) p4d = to_ndim(Vec4f, to_ndim(Vec3f, point, 0f0), 1f0) clip = proj_view * p4d - p = (clip / clip[4])[Vec(1, 2)] + p = (clip ./ clip[4])[Vec(1, 2)] p = Vec2f(p[1], p[2]) - return (((p .+ 1f0) / 2f0) .* (resolution .- 1f0)) .+ 1f0 + return (((p .+ 1f0) ./ 2f0) .* (resolution .- 1f0)) .+ 1f0 end function project_point2(mat4::Mat4, point2::Point2) diff --git a/src/interaction/inspector.jl b/src/interaction/inspector.jl index 50f15c5bc0a..3798cac74da 100644 --- a/src/interaction/inspector.jl +++ b/src/interaction/inspector.jl @@ -88,12 +88,12 @@ function view_ray(inv_view_proj, mpos, area::Rect2) far = reversed ? 0f0 : 1f0 - 1e-6 origin = inv_view_proj * Vec4f(mp[1], mp[2], near, 1f0) - origin = origin[SOneTo(3)] ./ origin[4] + origin = origin[Vec(1, 2, 3)] ./ origin[4] p = inv_view_proj * Vec4f(mp[1], mp[2], far, 1f0) - p = p[SOneTo(3)] ./ p[4] + p = p[Vec(1, 2, 3)] ./ p[4] - dir = normalize(p - origin) + dir = normalize(p .- origin) return origin, dir end diff --git a/src/jl_rasterizer/main.jl b/src/jl_rasterizer/main.jl index b4ced4bce1f..471d2a98bde 100644 --- a/src/jl_rasterizer/main.jl +++ b/src/jl_rasterizer/main.jl @@ -1,6 +1,6 @@ -using Colors, ColorVectorSpace, StaticArrays +using Colors, ColorVectorSpace 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 fa907b2ddc7..6dc931a596f 100644 --- a/src/layouting/boundingbox.jl +++ b/src/layouting/boundingbox.jl @@ -114,16 +114,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/layouting/layouting.jl b/src/layouting/layouting.jl index 557c0fefb9d..2806d72a458 100644 --- a/src/layouting/layouting.jl +++ b/src/layouting/layouting.jl @@ -72,7 +72,6 @@ function glyph_collection(str::AbstractString, font_per_char, fontscale_px, hali # collect information about every character in the string charinfos = broadcast((c for c in str), font_per_char, fontscale_px) do char, font, scale - # TODO: scale as SVector not Number unscaled_extent = get_extent(font, char) lineheight = Float32(font.height / font.units_per_EM * lineheight_factor * scale) unscaled_hi_bb = height_insensitive_boundingbox(unscaled_extent, font) @@ -274,10 +273,10 @@ function text_quads(position::VecTypes, gc::GlyphCollection, offset, transfunc) gc.glyphs[i], gc.fonts[i], gc.scales[i] ) uvs[i] = glyph_uv_width!(atlas, gc.glyphs[i], gc.fonts[i]) - scales[i] = widths(glyph_bb) .+ gc.scales[i] * 2pad - char_offsets[i] = gc.origins[i] + _offset_at(off, i) - quad_offsets[i] = minimum(glyph_bb) .- gc.scales[i] * pad - end + scales[i] = widths(glyph_bb) .+ gc.scales[i] .* 2pad + char_offsets[i] = gc.origins[i] .+ _offset_at(off, i) + quad_offsets[i] = minimum(glyph_bb) .- gc.scales[i] .* pad + end # pos is the (space) position given to text (with transfunc applied) # char_offsets are 3D offsets in marker space, including: @@ -310,10 +309,10 @@ function text_quads(position::Vector, gcs::Vector{<: GlyphCollection}, offset, t ) uvs[k] = glyph_uv_width!(atlas, gc.glyphs[i], gc.fonts[i]) scales[k] = widths(glyph_bb) .+ gc.scales[i] * 2pad - char_offsets[k] = gc.origins[i] + _offset_at(off, j) - quad_offsets[k] = minimum(glyph_bb) .- gc.scales[i] * pad + char_offsets[k] = gc.origins[i] .+ _offset_at(off, j) + quad_offsets[k] = minimum(glyph_bb) .- gc.scales[i] .* pad k += 1 - end + end return pos, char_offsets, quad_offsets, uvs, scales end diff --git a/src/makielayout/interactions.jl b/src/makielayout/interactions.jl index 5285fd9ce17..e9f6970ce2b 100644 --- a/src/makielayout/interactions.jl +++ b/src/makielayout/interactions.jl @@ -187,11 +187,10 @@ function process_interaction(r::RectangleZoom, event::MouseEvent, ax::Axis) return Consume(false) end -function rectclamp(p::Point, r::Rect) - p = map(p, minimum(r), maximum(r)) do pp, mi, ma - clamp(pp, mi, ma) - end - return Point(p) +function rectclamp(p::Point{N, T}, r::Rect) where {N, T} + mi, ma = extrema(r) + p = clamp.(p, mi, ma) + return Point{N, T}(p) end function process_interaction(r::RectangleZoom, event::KeysEvent, ax::Axis) @@ -248,7 +247,7 @@ function process_interaction(s::ScrollZoom, event::ScrollEvent, ax::Axis) mp_axscene = Vec4f((e.mouseposition[] .- pa.origin)..., 0, 1) # first to normal -1..1 space - mp_axfraction = (cam.pixel_space[] * mp_axscene)[1:2] .* + mp_axfraction = (cam.pixel_space[] * mp_axscene)[Vec(1, 2)] .* # now to 1..-1 if an axis is reversed to correct zoom point (-2 .* ((ax.xreversed[], ax.yreversed[])) .+ 1) .* # now to 0..1 @@ -312,7 +311,7 @@ function process_interaction(dp::DragPan, event::MouseEvent, ax) mp_axfraction, mp_axfraction_prev = map((mp_axscene, mp_axscene_prev)) do mp # first to normal -1..1 space - (cam.pixel_space[] * mp)[1:2] .* + (cam.pixel_space[] * mp)[Vec(1, 2)] .* # now to 1..-1 if an axis is reversed to correct zoom point (-2 .* ((ax.xreversed[], ax.yreversed[])) .+ 1) .* # now to 0..1 diff --git a/src/makielayout/layoutables/axis.jl b/src/makielayout/layoutables/axis.jl index 9a3efc18008..38c700f2301 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/makielayout/layoutables/axis3d.jl b/src/makielayout/layoutables/axis3d.jl index 484fbc57b33..3f9b8dd5486 100644 --- a/src/makielayout/layoutables/axis3d.jl +++ b/src/makielayout/layoutables/axis3d.jl @@ -587,7 +587,7 @@ function add_ticks_and_ticklabels!(topscene, scene, dim::Int, limits, ticknode, pp2 = Point2f(o + Makie.project(scene, p2)) # find the midpoint - midpoint = (pp1 + pp2) / 2 + midpoint = (pp1 + pp2) ./ 2 # and the difference vector diff = pp2 - pp1 diff --git a/src/utilities/quaternions.jl b/src/utilities/quaternions.jl index c4f7d701d50..bcae57f50de 100644 --- a/src/utilities/quaternions.jl +++ b/src/utilities/quaternions.jl @@ -52,13 +52,13 @@ LinearAlgebra.normalize(q::Quaternion) = q / abs(q) Base.:(/)(q::Quaternion, x::Real) = Quaternion(q[1] / x, q[2] / x, q[3] / x, q[4] / x) -function Base.:(*)(quat::Quaternion, vec::StaticVector{2, T}) where T +function Base.:(*)(quat::Quaternion, vec::P) where {P <: StaticVector{2}} + T = eltype(vec) x3 = quat * Vec(vec[1], vec[2], T(0)) - VT = similar_type(vec, StaticArrays.Size(2,)) - VT(x3[1], x3[2]) + return P(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] diff --git a/test/conversions.jl b/test/conversions.jl index c21cbe0b671..0811f0239c3 100644 --- a/test/conversions.jl +++ b/test/conversions.jl @@ -28,10 +28,6 @@ end V2 = to_vertices(X2) @test Float32(X2[7][1]) == V2[7][1] - X3 = [SVector(rand(3)...) for i = 1:10] - V3 = to_vertices(X3) - @test Float32(X3[7][1]) == V3[7][1] - X4 = rand(2,10) V4 = to_vertices(X4) @test Float32(X4[1,7]) == V4[7][1] diff --git a/test/events.jl b/test/events.jl index dcacf246d46..1501ceb613a 100644 --- a/test/events.jl +++ b/test/events.jl @@ -10,22 +10,22 @@ Base.:(==)(l::Or, r::Or) = l.left == r.left && l.right == r.right @testset "PriorityObservable" begin po = PriorityObservable(0) - first = Observable(0.0) - second = Observable(0.0) - third = Observable(0.0) + first = Observable(UInt64(0)) + second = Observable(UInt64(0)) + third = Observable(UInt64(0)) on(po, priority=1) do x sleep(0) - first[] = time() + first[] = time_ns() end on(po, priority=0) do x sleep(0) - second[] = time() + second[] = time_ns() return Consume(isodd(x)) end on(po, priority=-1) do x sleep(0) - third[] = time() + third[] = time_ns() return Consume(false) end diff --git a/test/quaternions.jl b/test/quaternions.jl index ea0361b22bc..ac723242c51 100644 --- a/test/quaternions.jl +++ b/test/quaternions.jl @@ -1,21 +1,21 @@ @testset "Quaternions" begin qx = qrotation(Vec(1, 0, 0), pi / 4) - @test qx * qx ≈ qrotation(SVector(1.0, 0.0, 0.0), pi / 2) - @test Base.power_by_squaring(qx, 2) ≈ qrotation(SVector(1.0, 0.0, 0.0), pi / 2) + @test qx * qx ≈ qrotation(Vec(1.0, 0.0, 0.0), pi / 2) + @test Base.power_by_squaring(qx, 2) ≈ qrotation(Vec(1.0, 0.0, 0.0), pi / 2) theta = pi / 8 - qx = qrotation(SVector(1.0, 0.0, 0.0), theta) + qx = qrotation(Vec(1.0, 0.0, 0.0), theta) c = cos(theta); s = sin(theta) Rx = [1 0 0; 0 c -s; 0 s c] @test Mat3f(qx) ≈ Rx theta = pi / 6 - qy = qrotation(SVector(0.0, 1.0, 0.0), theta) + qy = qrotation(Vec(0.0, 1.0, 0.0), theta) c = cos(theta); s = sin(theta) Ry = [c 0 s; 0 1 0; -s 0 c] @test Mat3f(qy) ≈ Ry theta = 4pi / 3 - qz = qrotation(SVector(0.0, 0.0, 1.0), theta) + qz = qrotation(Vec(0.0, 0.0, 1.0), theta) c = cos(theta); s = sin(theta) Rz = [c -s 0; s c 0; 0 0 1] @test Mat3f(qz) ≈ Rz @@ -24,12 +24,12 @@ @test Mat3f(qy * qx * qz) ≈ Ry * Rx * Rz @test Mat3f(qz * qx * qy) ≈ Rz * Rx * Ry - a, b = qrotation(SVector(0.0, 0.0, 1.0), deg2rad(0)), qrotation(SVector(0.0, 0.0, 1.0), deg2rad(180)) + a, b = qrotation(Vec(0.0, 0.0, 1.0), deg2rad(0)), qrotation(Vec(0.0, 0.0, 1.0), deg2rad(180)) # @test slerp(a, b, 0.0) ≈ a # @test slerp(a, b, 1.0) ≈ b # @test slerp(a, b, 0.5) ≈ qrotation([0, 0, 1], deg2rad(90)) # - # @test angle(qrotation(SVector(1.0, 0.0, 0.0), 0)) ≈ 0 + # @test angle(qrotation(Vec(1.0, 0.0, 0.0), 0)) ≈ 0 # @test angle(qrotation([0, 1, 0], pi / 4)) ≈ pi / 4 # @test angle(qrotation([0, 0, 1], pi / 2)) ≈ pi / 2 # diff --git a/test/runtests.jl b/test/runtests.jl index aac28929a01..9c89ac747be 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,4 @@ using Test -using StaticArrays using Makie using Makie.Observables using Makie.GeometryBasics