diff --git a/PlotsBase/src/Shapes.jl b/PlotsBase/src/Shapes.jl index 8d921b1e9..9a68df152 100644 --- a/PlotsBase/src/Shapes.jl +++ b/PlotsBase/src/Shapes.jl @@ -210,20 +210,15 @@ rotate_x(x::Real, y::Real, θ::Real, centerx::Real, centery::Real) = rotate_y(x::Real, y::Real, θ::Real, centerx::Real, centery::Real) = ((y - centery) * cos(θ) + (x - centerx) * sin(θ) + centery) -end # module - -# ----------------------------------------------------------------------------- - -using .Shapes rotate(x::Real, y::Real, θ::Real, c) = - (Shapes.rotate_x(x, y, θ, c...), Shapes.rotate_y(x, y, θ, c...)) + (rotate_x(x, y, θ, c...), rotate_y(x, y, θ, c...)) function rotate!(shape::Shape, θ::Real, c = center(shape)) x, y = coords(shape) for i ∈ eachindex(x) - xi = Shapes.rotate_x(x[i], y[i], θ, c...) - yi = Shapes.rotate_y(x[i], y[i], θ, c...) + xi = rotate_x(x[i], y[i], θ, c...) + yi = rotate_y(x[i], y[i], θ, c...) x[i], y[i] = xi, yi end shape @@ -232,7 +227,14 @@ end "rotate an object in space" function rotate(shape::Shape, θ::Real, c = center(shape)) x, y = coords(shape) - x_new = Shapes.rotate_x.(x, y, θ, c...) - y_new = Shapes.rotate_y.(x, y, θ, c...) + x_new = rotate_x.(x, y, θ, c...) + y_new = rotate_y.(x, y, θ, c...) Shape(x_new, y_new) end + + +end # module + +# ----------------------------------------------------------------------------- + +using .Shapes diff --git a/PlotsBase/src/recipes.jl b/PlotsBase/src/recipes.jl index 296590887..6ab4e240f 100644 --- a/PlotsBase/src/recipes.jl +++ b/PlotsBase/src/recipes.jl @@ -1506,10 +1506,10 @@ end @specialize -findnz(A::SparseArrays.AbstractSparseMatrix) = SparseArrays.findnz(A) +find_nnz(A::SparseArrays.AbstractSparseMatrix) = SparseArrays.findnz(A) # fallback function for finding non-zero elements of non-sparse matrices -function findnz(A::AbstractMatrix) +function find_nnz(A::AbstractMatrix) keysnz = findall(!iszero, A) rs = map(k -> k[1], keysnz) cs = map(k -> k[2], keysnz) @@ -1520,7 +1520,7 @@ end @recipe function f(::Type{Val{:spy}}, x, y, z) # COV_EXCL_LINE yflip := true aspect_ratio := 1 - rs, cs, zs = findnz(z.surf) + rs, cs, zs = PlotsBase.find_nnz(z.surf) xlims := ignorenan_extrema(cs) ylims := ignorenan_extrema(rs) widen --> true diff --git a/PlotsBase/test/test_components.jl b/PlotsBase/test/test_components.jl index de53ade64..740ea053e 100644 --- a/PlotsBase/test/test_components.jl +++ b/PlotsBase/test/test_components.jl @@ -1,7 +1,9 @@ +const Shapes = PlotsBase.Shapes + @testset "Shapes" begin - get_xs = PlotsBase.Shapes.get_xs - get_ys = PlotsBase.Shapes.get_ys - vertices = PlotsBase.Shapes.vertices + get_xs = Shapes.get_xs + get_ys = Shapes.get_ys + vertices = Shapes.vertices @testset "Type" begin square = Shape([(0, 0.0), (1, 0.0), (1, 1.0), (0, 1.0)]) @test get_xs(square) == [0, 1, 1, 0] @@ -27,7 +29,7 @@ @testset "Center" begin square = Shape([(0, 0), (1, 0), (1, 1), (0, 1)]) - @test PlotsBase.center(square) == (0.5, 0.5) + @test Shapes.center(square) == (0.5, 0.5) end @testset "Translate" begin @@ -35,10 +37,10 @@ squareUp = Shape([(0, 1), (1, 1), (1, 2), (0, 2)]) squareUpRight = Shape([(1, 1), (2, 1), (2, 2), (1, 2)]) - @test PlotsBase.translate(square, 0, 1).x == squareUp.x - @test PlotsBase.translate(square, 0, 1).y == squareUp.y + @test Shapes.translate(square, 0, 1).x == squareUp.x + @test Shapes.translate(square, 0, 1).y == squareUp.y - @test PlotsBase.center(PlotsBase.translate!(square, 1)) == (1.5, 1.5) + @test Shapes.center(Shapes.translate!(square, 1)) == (1.5, 1.5) end @testset "Rotate" begin @@ -50,12 +52,12 @@ square = Shape([(0, 0), (1, 0), (1, 1), (0, 1)]) # make a new, rotated square - square2 = PlotsBase.rotate(square, -2) + square2 = Shapes.rotate(square, -2) @test square2.x ≈ coordsRotated2[1, :] @test square2.y ≈ coordsRotated2[2, :] # unrotate the new square in place - PlotsBase.rotate!(square2, 2) + Shapes.rotate!(square2, 2) @test square2.x ≈ coords[1, :] @test square2.y ≈ coords[2, :] end @@ -71,18 +73,18 @@ end @testset "Misc" begin - @test PlotsBase.weave([1, 3], [2, 4]) == collect(1:4) - @test PlotsBase.makeshape(3) isa PlotsBase.Shape - @test PlotsBase.makestar(3) isa PlotsBase.Shape - @test PlotsBase.makecross() isa PlotsBase.Shape - @test PlotsBase.makearrowhead(10.0) isa PlotsBase.Shape + @test Shapes.weave([1, 3], [2, 4]) == collect(1:4) + @test Shapes.makeshape(3) isa Shape + @test Shapes.makestar(3) isa Shape + @test Shapes.makecross() isa Shape + @test Shapes.makearrowhead(10.0) isa Shape - @test PlotsBase.rotate(1.0, 2.0, 5.0, (0, 0)) isa Tuple + @test Shapes.rotate(1.0, 2.0, 5.0, (0, 0)) isa Tuple - star = PlotsBase.makestar(3) - star_scaled = PlotsBase.scale(star, 0.5) + star = Shapes.makestar(3) + star_scaled = Shapes.scale(star, 0.5) - PlotsBase.scale!(star, 0.5) + Shapes.scale!(star, 0.5) @test get_xs(star) == get_xs(star_scaled) @test get_ys(star) == get_ys(star_scaled) @@ -221,9 +223,9 @@ end end @testset "Series Annotations" begin - get_xs = PlotsBase.Shapes.get_xs - get_ys = PlotsBase.Shapes.get_ys - vertices = PlotsBase.Shapes.vertices + get_xs = Shapes.get_xs + get_ys = Shapes.get_ys + vertices = Shapes.vertices square = Shape([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]) @test_logs (:warn, "Unused SeriesAnnotations arg: triangle (Symbol)") begin pl = plot( diff --git a/PlotsBase/test/test_misc.jl b/PlotsBase/test/test_misc.jl index fd9fe7323..334eb7263 100644 --- a/PlotsBase/test/test_misc.jl +++ b/PlotsBase/test/test_misc.jl @@ -262,7 +262,7 @@ with(:gr) do @test ylims(pl) == (-1, +1) end - @test PlotsBase.findnz([0 1; 2 0]) == ([2, 1], [1, 2], [2, 1]) + @test PlotsBase.find_nnz([0 1; 2 0]) == ([2, 1], [1, 2], [2, 1]) end @testset "mesh3d" begin