Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Nov 13, 2024
1 parent 23fbbe7 commit a779743
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
22 changes: 12 additions & 10 deletions PlotsBase/src/Shapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions PlotsBase/src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
44 changes: 23 additions & 21 deletions PlotsBase/test/test_components.jl
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -27,18 +29,18 @@

@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
square = Shape([(0, 0), (1, 0), (1, 1), (0, 1)])
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
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion PlotsBase/test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a779743

Please sign in to comment.