Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #600 from JuliaPlots/sd/geo
Browse files Browse the repository at this point in the history
add Point transform type
  • Loading branch information
SimonDanisch authored Jan 16, 2021
2 parents c23c40a + ea14314 commit 8012f14
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/layouting/boundingbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function raw_boundingbox(plots::Vector)
plot_idx = iterate(plots, idx)
# isvisible(plot) || continue
bb2 = boundingbox(plot)
isfinite(bb) || (bb = bb2)
isfinite(bb2) || continue
isfinite_rect(bb) || (bb = bb2)
isfinite_rect(bb2) || continue
bb = union(bb, bb2)
end
return bb
Expand Down Expand Up @@ -192,7 +192,7 @@ function boundingbox(
# bb = rectdiv(bb, 1.5)
shifted_bb = FRect3D(rotated_bb) + position[i]
bboxc = bbox[]
if !isfinite(bboxc)
if !isfinite_rect(bboxc)
bbox[] = shifted_bb
else
bbox[] = union(bboxc, shifted_bb)
Expand Down
8 changes: 4 additions & 4 deletions src/layouting/data_limits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function extrema_nan(itr)
end

function xyz_boundingbox(transform_func, mesh::GeometryBasics.Mesh)
xyz_boundingbox(transform_func, coordinates(mesh))
xyz_boundingbox(transform_func, decompose(Point, mesh))
end

function xyz_boundingbox(transform_func, xyz)
Expand Down Expand Up @@ -121,7 +121,7 @@ function data_limits(x::Annotations)
return inv(modelmatrix(x)) * bb
end

Base.isfinite(x::Rect) = all(isfinite.(minimum(x))) && all(isfinite.(maximum(x)))
isfinite_rect(x::Rect) = all(isfinite.(minimum(x))) && all(isfinite.(maximum(x)))

function data_limits(plots::Vector)
isempty(plots) && return
Expand All @@ -133,8 +133,8 @@ function data_limits(plots::Vector)
# axis shouldn't be part of the data limit
isaxis(plot) && continue
bb2 = data_limits(plot)::FRect3D
isfinite(bb) || (bb = bb2)
isfinite(bb2) || continue
isfinite_rect(bb) || (bb = bb2)
isfinite_rect(bb2) || continue
bb = union(bb, bb2)
end
bb
Expand Down
24 changes: 24 additions & 0 deletions src/layouting/transformation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,30 @@ apply_transform(f::typeof(identity), positions::AbstractArray) = positions
apply_transform(f::typeof(identity), positions::AbstractVector) = positions
apply_transform(f::typeof(identity), position::VecTypes) = position

struct PointTrans{N, F}
f::F
end

PointTrans{N}(func::F) where {N, F} = PointTrans{N, F}(func)
Base.broadcastable(x::PointTrans) = (x,)

function apply_transform(f::PointTrans{N}, point::Point{N}) where N
return f.f(point)
end

function apply_transform(f::PointTrans{N1}, point::Point{N2}) where {N1, N2}
p_dim = to_ndim(Point{N1, Float32}, point, 0.0)
p_trans = f.f(p_dim)
if N1 < N2
p_large = ntuple(i-> i <= N1 ? p_trans[i] : point[i], N2)
return Point{N2, Float32}(p_large)
else
return to_ndim(Point{N2, Float32}, p_trans, 0.0)
end
end



function apply_transform(f, data::AbstractArray)
return map(point-> apply_transform(f, point), data)
end
Expand Down
4 changes: 2 additions & 2 deletions src/makielayout/layoutables/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function Axis(fig_or_scene; bbox = nothing, kwargs...)
ticksvisible = yticksvisible, spinevisible = yspinevisible, spinecolor = yspinecolor, spinewidth = spinewidth,
trimspine = ytrimspine, ticklabelsize = yticklabelsize, ticksize = yticksize, flip_vertical_label = flip_ylabel, reversed = yreversed, tickwidth = ytickwidth,
tickcolor = ytickcolor)

decorations[:yaxis] = yaxis

xoppositelinepoints = lift(scene.px_area, spinewidth, xaxisposition) do r, sw, xaxpos
Expand Down Expand Up @@ -436,7 +436,7 @@ function getlimits(la::Axis, dim)
plots_with_autolimits)

bboxes = [FRect2D(AbstractPlotting.data_limits(p)) for p in visible_plots]
finite_bboxes = filter(isfinite, bboxes)
finite_bboxes = filter(AbstractPlotting.isfinite_rect, bboxes)

isempty(finite_bboxes) && return nothing

Expand Down
1 change: 1 addition & 0 deletions test/unit_tests/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
include("liftmacro.jl")
include("makielayout.jl")
include("figures.jl")
include("transformations.jl")
end
24 changes: 24 additions & 0 deletions test/unit_tests/transformations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using AbstractPlotting: PointTrans, xyz_boundingbox

@testset "Basic transforms" begin
function point2(x::Point2)
return Point2f0(x[1] + 10, x[2] - 77)
end

function point3(x::Point3)
return Point3f0(x[1] + 10, x[2] - 77, x[3] / 4)
end
trans2 = PointTrans{2}(point2)
trans3 = PointTrans{3}(point3)
points = [Point2f0(0, 0), Point2f0(0, 1)]
bb = xyz_boundingbox(trans2, points)
@test bb == Rect(Vec3f0(10, -77, 0), Vec3f0(0, 1, 0))
bb = xyz_boundingbox(trans3, points)
@test bb == Rect(Vec3f0(10, -77, 0), Vec3f0(0, 1, 0))

points = [Point3f0(0, 0, 4), Point3f0(0, 1, -8)]
bb = xyz_boundingbox(trans2, points)
@test bb == Rect(Vec3f0(10, -77, -8), Vec3f0(0, 1, 12))
bb = xyz_boundingbox(trans3, points)
@test bb == Rect(Vec3f0(10, -77, -2.0), Vec3f0(0, 1, 3.0))
end

0 comments on commit 8012f14

Please sign in to comment.