forked from MakieOrg/Makie.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boundingboxes.jl
105 lines (85 loc) · 3.5 KB
/
boundingboxes.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function Base.isapprox(r1::Rect{D}, r2::Rect{D}; kwargs...) where D
return isapprox(minimum(r1), minimum(r2); kwargs...) &&
isapprox(widths(r1), widths(r2); kwargs...)
end
@testset "data_limits(plot)" begin
ps = Point2f[(0, 0), (1, 1)]
fig, ax, p = hexbin(ps)
ms = to_ndim(Vec3f, Vec2f(p.plots[1].markersize[]), 0)
@test data_limits(p) ≈ Rect3f(-ms, Vec3f(1, 1, 0) .+ 2ms)
fig, ax, p = errorbars(ps, [0.5, 0.5])
@test data_limits(p) ≈ Rect3f(-Point3f(0, 0.5, 0), Vec3f(1, 2, 0))
fig, ax, p = bracket(ps...)
@test data_limits(p) ≈ Rect3f(Point3f(0), Vec3f(1, 1, 0))
fig = Figure()
ax = Axis(fig[1, 1], yscale=log, xscale=log)
scatter!(ax, [0.5, 1, 2], [0.5, 1, 2])
p1 = vlines!(ax, [0.5])
p2 = hlines!(ax, [0.5])
p3 = vspan!(ax, [0.25], [0.75])
p4 = hspan!(ax, [0.25], [0.75])
Makie.reset_limits!(ax)
lims = ax.finallimits[]
x, y = minimum(lims); w, h = widths(lims)
@test data_limits(p1) ≈ Rect3f(Point3f(0.5, y, 0), Vec3f(0, h, 0))
@test data_limits(p2) ≈ Rect3f(Point3f(x, 0.5, 0), Vec3f(w, 0, 0))
@test data_limits(p3) ≈ Rect3f(Point3f(0.25, y, 0), Vec3f(0.5, h, 0))
@test data_limits(p4) ≈ Rect3f(Point3f(x, 0.25, 0), Vec3f(w, 0.5, 0))
end
@testset "boundingbox(plot)" begin
cat = FileIO.load(Makie.assetpath("cat.obj"))
# Testing atomic plots here. Everything else should be derived from them
fig, ax, p = mesh(cat)
bb = boundingbox(p)
@test bb.origin ≈ Point3f(-0.1678, -0.002068, -0.358661)
@test bb.widths ≈ Vec3f(0.339423, 0.92186, 1.3318559)
fig, ax, p = surface([x*y for x in 1:10, y in 1:10])
bb = boundingbox(p)
@test bb.origin ≈ Point3f(1.0, 1.0, 1.0)
@test bb.widths ≈ Vec3f(9.0, 9.0, 99.0)
fig, ax, p = meshscatter([Point3f(x, y, z) for x in 1:5 for y in 1:5 for z in 1:5])
bb = boundingbox(p)
# Note: awkwards numbers come from using mesh over Sphere
@test bb.origin ≈ Point3f(0.9011624, 0.9004657, 0.9)
@test bb.widths ≈ Vec3f(4.1986046, 4.199068, 4.2)
fig, ax, p = meshscatter(
[Point3f(0) for _ in 1:3],
marker = Rect3f(Point3f(-0.1, -0.1, -0.1), Vec3f(0.2, 0.2, 1.2)),
markersize = Vec3f(1, 1, 2),
rotations = Makie.rotation_between.((Vec3f(0,0,1),), Vec3f[(1,0,0), (0,1,0), (0,0,1)])
)
bb = boundingbox(p)
@test bb.origin ≈ Point3f(-0.2)
@test bb.widths ≈ Vec3f(2.4)
fig, ax, p = volume(rand(5, 5, 5))
bb = boundingbox(p)
@test bb.origin ≈ Point3f(0)
@test bb.widths ≈ Vec3f(5)
fig, ax, p = scatter(1:10)
bb = boundingbox(p)
@test bb.origin ≈ Point3f(1, 1, 0)
@test bb.widths ≈ Vec3f(9, 9, 0)
fig, ax, p = lines(1:10)
bb = boundingbox(p)
@test bb.origin ≈ Point3f(1, 1, 0)
@test bb.widths ≈ Vec3f(9, 9, 0)
fig, ax, p = linesegments(1:10)
bb = boundingbox(p)
@test bb.origin ≈ Point3f(1, 1, 0)
@test bb.widths ≈ Vec3f(9, 9, 0)
fig, ax, p = heatmap(rand(10, 10))
bb = boundingbox(p)
@test bb.origin ≈ Point3f(0.5, 0.5, 0)
@test bb.widths ≈ Vec3f(10.0, 10.0, 0)
fig, ax, p = image(rand(10, 10))
bb = boundingbox(p)
@test bb.origin ≈ Point3f(0)
@test bb.widths ≈ Vec3f(10.0, 10.0, 0)
# text transforms to pixel space atm (TODO)
fig = Figure(size = (400, 400))
ax = Axis(fig[1, 1])
p = text!(ax, Point2f(10), text = "test", fontsize = 20)
bb = boundingbox(p)
@test bb.origin ≈ Point3f(343.0, 345.0, 0)
@test bb.widths ≈ Vec3f(32.24, 23.3, 0)
end