Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/cairomakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
- ubuntu-latest
arch:
- x64
env:
JULIA_PKG_SERVER: ""
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -49,7 +51,7 @@ jobs:
run: |
using Pkg;
# dev mono repo versions
pkg"dev . MakieCore CairoMakie ReferenceTests"
pkg"dev . ./MakieCore ./CairoMakie ./ReferenceTests"
- name: Run the tests
continue-on-error: true
run: >
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
- ubuntu-latest
arch:
- x64
env:
JULIA_PKG_SERVER: ""
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -49,7 +51,7 @@ jobs:
run: |
using Pkg;
# dev mono repo versions
pkg"dev . MakieCore"
pkg"dev . ./MakieCore"
Pkg.test("Makie"; coverage=true)

- uses: julia-actions/julia-processcoverage@v1
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- ubuntu-18.04
arch:
- x64
env:
JULIA_PKG_SERVER: ""
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -48,7 +50,7 @@ jobs:
pkg"registry add https://github.com/JuliaRegistries/General";
pkg"registry up General";
# dev mono repo versions
pkg"dev . MakieCore CairoMakie WGLMakie GLMakie; add Documenter#master; instantiate"'
pkg"dev . ./MakieCore ./CairoMakie ./WGLMakie ./GLMakie; add Documenter#master; instantiate"'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/glmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
- ubuntu-18.04
arch:
- x64
env:
JULIA_PKG_SERVER: ""
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -50,7 +52,7 @@ jobs:
run: |
using Pkg;
# dev mono repo versions
pkg"dev . MakieCore GLMakie ReferenceTests"
pkg"dev . ./MakieCore ./GLMakie ./ReferenceTests"
- name: Run the tests
continue-on-error: true
run: >
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/wglmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
- ubuntu-latest
arch:
- x64
env:
JULIA_PKG_SERVER: ""
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -40,7 +42,7 @@ jobs:
run: |
using Pkg;
# dev mono repo versions
pkg"dev . MakieCore WGLMakie ReferenceTests"
pkg"dev . ./MakieCore ./WGLMakie ./ReferenceTests"
- name: Run the tests
continue-on-error: true
run: >
Expand Down
4 changes: 2 additions & 2 deletions CairoMakie/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Colors = "0.10, 0.11, 0.12"
FFTW = "1"
FileIO = "1.1"
FreeType = "3, 4.0"
GeometryBasics = "0.2, 0.3"
GeometryBasics = "0.4.1"
Makie = "=0.15.0"
StaticArrays = "0.12, 1.0"
julia = "1.3"

[extras]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
ReferenceTests = "d37af2e0-5618-4e00-9939-d430db56ee94"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Pkg", "ReferenceTests"]
10 changes: 6 additions & 4 deletions CairoMakie/src/CairoMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const OneOrVec{T} = Union{
NTuple{N2, T} where N2,
}

# re-export Makie
for name in names(Makie)
@eval using Makie: $(name)
@eval export $(name)
# re-export Makie, including deprecated names
for name in names(Makie, all=true)
if Base.isexported(Makie, name)
@eval using Makie: $(name)
@eval export $(name)
end
end
export inline!

Expand Down
8 changes: 4 additions & 4 deletions CairoMakie/src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ function draw_poly(scene::Scene, screen::CairoScreen, poly, points_list::Vector{
end


draw_poly(scene::Scene, screen::CairoScreen, poly, rect::Rect2D) = draw_poly(scene, screen, poly, [rect])
draw_poly(scene::Scene, screen::CairoScreen, poly, rect::Rect2) = draw_poly(scene, screen, poly, [rect])

function draw_poly(scene::Scene, screen::CairoScreen, poly, rects::Vector{<:Rect2D})
function draw_poly(scene::Scene, screen::CairoScreen, poly, rects::Vector{<:Rect2})
model = poly.model[]
projected_rects = project_rect.(Ref(scene), rects, Ref(model))

Expand Down Expand Up @@ -90,14 +90,14 @@ function draw_poly(scene::Scene, screen::CairoScreen, poly, rects::Vector{<:Rect
end

function polypath(ctx, polygon)
ext = decompose(Point2f0, polygon.exterior)
ext = decompose(Point2f, polygon.exterior)
Cairo.move_to(ctx, ext[1]...)
for point in ext[2:end]
Cairo.line_to(ctx, point...)
end
Cairo.close_path(ctx)

interiors = decompose.(Point2f0, polygon.interiors)
interiors = decompose.(Point2f, polygon.interiors)
for interior in interiors
Cairo.move_to(ctx, interior[1]...)
for point in interior[2:end]
Expand Down
62 changes: 31 additions & 31 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Union{Lines,
# TODO this shouldn't be necessary anymore!
if positions isa SubArray{<:Point3, 1, P, <:Tuple{Array{<:AbstractFace}}} where P
positions = let
pos = Point3f0[]
pos = Point3f[]
for tup in positions
push!(pos, tup[1])
push!(pos, tup[2])
Expand Down Expand Up @@ -174,7 +174,7 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Scatter)
model = primitive[:model][]
positions = primitive[1][]
isempty(positions) && return
size_model = transform_marker ? model : Mat4f0(I)
size_model = transform_marker ? model : Mat4f(I)

font = to_font(to_value(get(primitive, :font, Makie.defaultfont())))

Expand Down Expand Up @@ -235,12 +235,12 @@ function draw_marker(ctx, marker::Char, font, pos, scale, strokecolor, strokewid
inkbb = Makie.FreeTypeAbstraction.inkboundingbox(charextent)

# scale normalized bbox by font size
inkbb_scaled = FRect2D(origin(inkbb) .* scale, widths(inkbb) .* scale)
inkbb_scaled = Rect2f(origin(inkbb) .* scale, widths(inkbb) .* scale)

# flip y for the centering shift of the character because in Cairo y goes down
centering_offset = [1, -1] .* (-origin(inkbb_scaled) .- 0.5 .* widths(inkbb_scaled))
# this is the origin where we actually have to place the glyph so it can be centered
charorigin = pos .+ Vec2f0(marker_offset[1], -marker_offset[2])
charorigin = pos .+ Vec2f(marker_offset[1], -marker_offset[2])
old_matrix = get_font_matrix(ctx)
set_font_matrix(ctx, scale_matrix(scale...))

Expand Down Expand Up @@ -272,7 +272,7 @@ end
function draw_marker(ctx, marker::Circle, pos, scale, strokecolor, strokewidth, marker_offset, rotation)

marker_offset = marker_offset + scale ./ 2
pos += Point2f0(marker_offset[1], -marker_offset[2])
pos += Point2f(marker_offset[1], -marker_offset[2])
Cairo.arc(ctx, pos[1], pos[2], scale[1]/2, 0, 2*pi)
Cairo.fill_preserve(ctx)

Expand All @@ -285,7 +285,7 @@ end

function draw_marker(ctx, marker::Rect, pos, scale, strokecolor, strokewidth, marker_offset, rotation)
s2 = Point2((widths(marker) .* scale .* (1, -1))...)
pos = pos .+ Point2f0(marker_offset[1], -marker_offset[2])
pos = pos .+ Point2f(marker_offset[1], -marker_offset[2])
Cairo.rotate(ctx, to_2d_rotation(rotation))
Cairo.rectangle(ctx, pos[1], pos[2], s2...)
Cairo.fill_preserve(ctx)
Expand Down Expand Up @@ -350,7 +350,7 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation,
cairoface = set_ft_font(ctx, font)
old_matrix = get_font_matrix(ctx)

p3_offset = to_ndim(Point3f0, offset, 0)
p3_offset = to_ndim(Point3f, offset, 0)

glyph in ('\r', '\n') && return

Expand All @@ -362,9 +362,9 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation,
# and then projected

# glyph position in data coordinates (offset has rotation applied already)
gpos_data = to_ndim(Point3f0, position, 0) .+ glyphoffset .+ p3_offset
gpos_data = to_ndim(Point3f, position, 0) .+ glyphoffset .+ p3_offset

scale3 = scale isa Number ? Point3f0(scale, scale, 0) : to_ndim(Point3f0, scale, 0)
scale3 = scale isa Number ? Point3f(scale, scale, 0) : to_ndim(Point3f, scale, 0)

# this could be done better but it works at least

Expand All @@ -373,12 +373,12 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation,
# origin. The resulting vectors give the directions in which the character
# needs to be stretched in order to match the 3D projection

xvec = rotation * (scale3[1] * Point3f0(1, 0, 0))
yvec = rotation * (scale3[2] * Point3f0(0, -1, 0))
xvec = rotation * (scale3[1] * Point3f(1, 0, 0))
yvec = rotation * (scale3[2] * Point3f(0, -1, 0))

glyphpos = project_position(scene, gpos_data, Mat4f0(I))
xproj = project_position(scene, gpos_data + xvec, Mat4f0(I))
yproj = project_position(scene, gpos_data + yvec, Mat4f0(I))
glyphpos = project_position(scene, gpos_data, Mat4f(I))
xproj = project_position(scene, gpos_data + xvec, Mat4f(I))
yproj = project_position(scene, gpos_data + yvec, Mat4f(I))

xdiff = xproj - glyphpos
ydiff = yproj - glyphpos
Expand All @@ -395,7 +395,7 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation,
glyphpos = project_position(
scene,
position,
Mat4f0(I)) .+ (p3_to_p2(glyphoffset .+ p3_offset)) .* (1, -1) # flip for Cairo
Mat4f(I)) .+ (p3_to_p2(glyphoffset .+ p3_offset)) .* (1, -1) # flip for Cairo
# and the scale is just taken as is
scale = length(scale) == 2 ? scale : SVector(scale, scale)

Expand All @@ -413,7 +413,7 @@ function draw_glyph_collection(scene, ctx, position, glyph_collection, rotation,
Cairo.show_text(ctx, string(glyph))
Cairo.restore(ctx)

if strokewidth > 0 && strokecolor != RGBAf0(0, 0, 0, 0)
if strokewidth > 0 && strokecolor != RGBAf(0, 0, 0, 0)
Cairo.save(ctx)
Cairo.move_to(ctx, glyphpos...)
set_font_matrix(ctx, mat)
Expand Down Expand Up @@ -525,8 +525,8 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Union{Heatmap

# find projected image corners
# this already takes care of flipping the image to correct cairo orientation
xy = project_position(scene, Point2f0(first.(imsize)), model)
xymax = project_position(scene, Point2f0(last.(imsize)), model)
xy = project_position(scene, Point2f(first.(imsize)), model)
xymax = project_position(scene, Point2f(last.(imsize)), model)
w, h = xymax .- xy

s = to_cairo_image(image, primitive)
Expand Down Expand Up @@ -557,7 +557,7 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Union{Heatmap
end
# find projected image corners
# this already takes care of flipping the image to correct cairo orientation
xys = [project_position(scene, Point2f0(x, y), model) for x in xs, y in ys]
xys = [project_position(scene, Point2f(x, y), model) for x in xs, y in ys]
colors = to_rgba_image(image, primitive)

# Note: xs and ys should have size ni+1, nj+1
Expand Down Expand Up @@ -663,7 +663,7 @@ nan2zero(x) = !isnan(x) * x

function draw_mesh3D(
scene, screen, primitive;
mesh = primitive[1][], pos = Vec4f0(0), scale = 1f0
mesh = primitive[1][], pos = Vec4f(0), scale = 1f0
)
@get_attribute(primitive, (color, shading, lightposition, ambient, diffuse,
specular, shininess, faceculling))
Expand Down Expand Up @@ -694,8 +694,8 @@ function draw_mesh3D(
vs = broadcast(decompose(Point, mesh), (func,)) do v, f
# Should v get a nan2zero?
v = Makie.apply_transform(f, v)
p4d = to_ndim(Vec4f0, scale .* to_ndim(Vec3f0, v, 0f0), 1f0)
view * (model * p4d .+ to_ndim(Vec4f0, pos, 0f0))
p4d = to_ndim(Vec4f, scale .* to_ndim(Vec3f, v, 0f0), 1f0)
view * (model * p4d .+ to_ndim(Vec4f, pos, 0f0))
end
fs = decompose(GLTriangleFace, mesh)
uv = hasproperty(mesh, :uv) ? mesh.uv : nothing
Expand All @@ -711,18 +711,18 @@ function draw_mesh3D(
if lightposition == :eyeposition
lightposition = scene.camera.eyeposition[]
end
lightpos = (view * to_ndim(Vec4f0, lightposition, 1.0))[Vec(1, 2, 3)]
lightpos = (view * to_ndim(Vec4f, lightposition, 1.0))[Vec(1, 2, 3)]

# Camera to screen space
ts = map(vs) do v
clip = projection * v
@inbounds begin
p = (clip ./ clip[4])[Vec(1, 2)]
p_yflip = Vec2f0(p[1], -p[2])
p_yflip = Vec2f(p[1], -p[2])
p_0_to_1 = (p_yflip .+ 1f0) / 2f0
end
p = p_0_to_1 .* scene.camera.resolution[]
Vec3f0(p[1], p[2], clip[3])
Vec3f(p[1], p[2], clip[3])
end

# Approximate zorder
Expand All @@ -744,15 +744,15 @@ function draw_mesh3D(
H = normalize(L + normalize(-v[SOneTo(3)]))
spec_coeff = max(dot(H, N), 0.0)^shininess
c = RGBA(c)
new_c = (ambient .+ diff_coeff .* diffuse) .* Vec3f0(c.r, c.g, c.b) .+
new_c = (ambient .+ diff_coeff .* diffuse) .* Vec3f(c.r, c.g, c.b) .+
specular * spec_coeff
RGBA(new_c..., c.alpha)
end
else
cols[k]
end
# debug normal coloring
# n1, n2, n3 = Vec3f0(0.5) .+ 0.5ns[f]
# n1, n2, n3 = Vec3f(0.5) .+ 0.5ns[f]
# c1 = RGB(n1...)
# c2 = RGB(n2...)
# c3 = RGB(n3...)
Expand Down Expand Up @@ -812,7 +812,7 @@ function surface2mesh(xs::Makie.ClosedInterval, ys::Makie.ClosedInterval, zs::Ab
end

function surface2mesh(xs::AbstractVector, ys::AbstractVector, zs::AbstractMatrix)
ps = [nan2zero.(Point3f0(xs[i], ys[j], zs[i, j])) for j in eachindex(ys) for i in eachindex(xs)]
ps = [nan2zero.(Point3f(xs[i], ys[j], zs[i, j])) for j in eachindex(ys) for i in eachindex(xs)]
idxs = LinearIndices(size(zs))
faces = [
QuadFace(idxs[i, j], idxs[i+1, j], idxs[i+1, j+1], idxs[i, j+1])
Expand All @@ -822,7 +822,7 @@ function surface2mesh(xs::AbstractVector, ys::AbstractVector, zs::AbstractMatrix
end

function surface2mesh(xs::AbstractMatrix, ys::AbstractMatrix, zs::AbstractMatrix)
ps = [nan2zero.(Point3f0(xs[i, j], ys[i, j], zs[i, j])) for j in 1:size(zs, 2) for i in 1:size(zs, 1)]
ps = [nan2zero.(Point3f(xs[i, j], ys[i, j], zs[i, j])) for j in 1:size(zs, 2) for i in 1:size(zs, 1)]
idxs = LinearIndices(size(zs))
faces = [
QuadFace(idxs[i, j], idxs[i+1, j], idxs[i+1, j+1], idxs[i, j+1])
Expand Down Expand Up @@ -850,7 +850,7 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Makie.MeshSca
view = scene.camera.view[]

zorder = sortperm(pos, by = p -> begin
p4d = to_ndim(Vec4f0, to_ndim(Vec3f0, p, 0f0), 1f0)
p4d = to_ndim(Vec4f, to_ndim(Vec3f, p, 0f0), 1f0)
cam_pos = view * model * p4d
cam_pos[3] / cam_pos[4]
end, rev=false)
Expand Down Expand Up @@ -883,7 +883,7 @@ function draw_atomic(scene::Scene, screen::CairoScreen, primitive::Makie.MeshSca

draw_mesh3D(
scene, screen, submesh, mesh = m, pos = p,
scale = scale isa Real ? Vec3f0(scale) : to_ndim(Vec3f0, scale, 1f0)
scale = scale isa Real ? Vec3f(scale) : to_ndim(Vec3f, scale, 1f0)
)
end

Expand Down
Loading