Added Shape rotation tests
This commit is contained in:
parent
10c94c739d
commit
bc144b64c8
@ -1,18 +1,19 @@
|
|||||||
using Plots, Test
|
using Plots, Test
|
||||||
|
|
||||||
@testset "Shape Copy" begin
|
@testset "Shapes" begin
|
||||||
|
@testset "Copy" begin
|
||||||
square = Shape([(0,0),(1,0),(1,1),(0,1)])
|
square = Shape([(0,0),(1,0),(1,1),(0,1)])
|
||||||
square2 = Shape(square)
|
square2 = Shape(square)
|
||||||
@test square2.x == square.x
|
@test square2.x == square.x
|
||||||
@test square2.y == square.y
|
@test square2.y == square.y
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "Shape Center" begin
|
@testset "Center" begin
|
||||||
square = Shape([(0,0),(1,0),(1,1),(0,1)])
|
square = Shape([(0,0),(1,0),(1,1),(0,1)])
|
||||||
@test Plots.center(square) == (0.5,0.5)
|
@test Plots.center(square) == (0.5,0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "Shape Translate" begin
|
@testset "Translate" begin
|
||||||
square = Shape([(0,0),(1,0),(1,1),(0,1)])
|
square = Shape([(0,0),(1,0),(1,1),(0,1)])
|
||||||
squareUp = Shape([(0,1),(1,1),(1,2),(0,2)])
|
squareUp = Shape([(0,1),(1,1),(1,2),(0,2)])
|
||||||
squareUpRight = Shape([(1,1),(2,1),(2,2),(1,2)])
|
squareUpRight = Shape([(1,1),(2,1),(2,2),(1,2)])
|
||||||
@ -23,6 +24,26 @@ end
|
|||||||
@test Plots.center(translate!(square,1)) == (1.5,1.5)
|
@test Plots.center(translate!(square,1)) == (1.5,1.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@testset "Rotate" begin
|
||||||
|
# 2 radians rotation matrix
|
||||||
|
R2 = [cos(2) sin(2); -sin(2) cos(2)]
|
||||||
|
coords = [0 0; 1 0; 1 1; 0 1]'
|
||||||
|
coordsRotated2 = R2*(coords.-0.5).+0.5
|
||||||
|
|
||||||
|
square = Shape([(0,0),(1,0),(1,1),(0,1)])
|
||||||
|
|
||||||
|
# make a new, rotated square
|
||||||
|
square2 = rotate(square, -2)
|
||||||
|
@test square2.x ≈ coordsRotated2[1,:]
|
||||||
|
@test square2.y ≈ coordsRotated2[2,:]
|
||||||
|
|
||||||
|
# unrotate the new square in place
|
||||||
|
rotate!(square2, 2)
|
||||||
|
@test square2.x ≈ coords[1,:]
|
||||||
|
@test square2.y ≈ coords[2,:]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@testset "Brush" begin
|
@testset "Brush" begin
|
||||||
@testset "Colors" begin
|
@testset "Colors" begin
|
||||||
baseline = brush(1, RGB(0,0,0))
|
baseline = brush(1, RGB(0,0,0))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user