Skip to content
Merged
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
8 changes: 4 additions & 4 deletions src/beziercurves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function Path(P::Vararg{PT, N}; tangents=nothing, tfactor=.5) where {PT<:Abstrac
# first command, recalculate WP if tangent is given
first_wp = WP[1]
if tangents !== nothing
p1, p2, t = P[1], P[2], normalize(Pointf(tangents[1]))
p1, p2, t = P[1], P[2], normalize(to_pointf32(tangents[1]))
dir = p2 - p1
d = tfactor * norm(dir ⋅ t)
first_wp = PT(p1+d*t)
Expand All @@ -289,7 +289,7 @@ function Path(P::Vararg{PT, N}; tangents=nothing, tfactor=.5) where {PT<:Abstrac
# last command, recalculate last WP if tangent is given
last_wp = (P[N] + WP[N-1])/2
if tangents !== nothing
p1, p2, t = P[N-1], P[N], normalize(Pointf(tangents[2]))
p1, p2, t = P[N-1], P[N], normalize(to_pointf32(tangents[2]))
dir = p2 - p1
d = tfactor * norm(dir ⋅ t)
last_wp = PT(p2-d*t)
Expand All @@ -313,8 +313,8 @@ function Path(P::Vararg{PT, 2}; tangents=nothing, tfactor=.5) where {PT<:Abstrac
if tangents === nothing
return Line(p1, p2)
else
t1 = normalize(Pointf(tangents[1]))
t2 = normalize(Pointf(tangents[2]))
t1 = normalize(to_pointf32(tangents[1]))
t2 = normalize(to_pointf32(tangents[2]))
len = norm(p2 - p1)
return BezierPath([MoveTo(p1),
CurveTo(PT(p1+len*tf1*t1),
Expand Down
6 changes: 3 additions & 3 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ function Makie.plot!(gp::GraphPlot)
if length(layout) != nv(graph)
throw(ArgumentError("The length of the layout vector does not match the number of nodes in the graph!"))
else
Pointf.(layout)
to_pointf32.(layout)
end
else
[Pointf(p) for p in layout(graph)]
[to_pointf32(p) for p in layout(graph)]
end
end

Expand Down Expand Up @@ -783,7 +783,7 @@ end

function _expand_args(args::Union{AbstractVector, AbstractDict}, ranges)
N_paths = length(ranges)
N_points = ranges[end][end]
N_points = N_paths > 0 ? ranges[end][end] : 0
allstraight = N_paths*3 == N_points
if args isa AbstractVector && length(args) != N_paths
throw(ArgumentError("The length of the args vector $args does not match the number of edges!"))
Expand Down
10 changes: 5 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ Return `true` if `x` represents a single attribute value
issingleattribute(x) = isa(x, Point) || (!isa(x, AbstractVector) && !isa(x, AbstractDict))

"""
Pointf(p::Point{N, T})
to_pointf32(p::Point{N, T})

Convert Point{N, T} or NTuple{N, T} to Point{N, Float32}.
"""
Pointf(p::Union{Point{N,T}, NTuple{N,T}}) where {N,T} = Point{N, Float32}(p)
Pointf(p::StaticVector{N, T}) where {N,T} = Point{N, Float32}(p)
Pointf(p::Vararg{T,N}) where {N,T} = Point{N, Float32}(p)
Pointf(p::Vector{T}) where {T} = Point{length(p), Float32}(p)
to_pointf32(p::Union{Point{N,T}, NTuple{N,T}}) where {N,T} = Point{N, Float32}(p)
to_pointf32(p::StaticVector{N, T}) where {N,T} = Point{N, Float32}(p)
to_pointf32(p::Vararg{T,N}) where {N,T} = Point{N, Float32}(p)
to_pointf32(p::Vector{T}) where {T} = Point{length(p), Float32}(p)

"""
align_to_dir(align::Tuple{Symbol, Symbol})
Expand Down
43 changes: 23 additions & 20 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,32 +189,32 @@ end
@test get_elabel_plot(p)[:text][] == elabels
end

@testset "test Pointf" begin
using GraphMakie: Pointf
@testset "test to_pointf32" begin
using GraphMakie: to_pointf32

p = Point(0.0, 0.0)
@test typeof(Pointf(p)) == Point2f
@test Pointf(p) == Point2f(p)
@test typeof(to_pointf32(p)) == Point2f
@test to_pointf32(p) == Point2f(p)

p = Point(1, 0)
@test typeof(Pointf(p)) == Point2f
@test Pointf(p) == Point2f(p)
@test typeof(to_pointf32(p)) == Point2f
@test to_pointf32(p) == Point2f(p)

p = Point(0.0, 1.0, 2.0)
@test typeof(Pointf(p)) == Point3f
@test Pointf(p) == Point3f(p)
@test typeof(to_pointf32(p)) == Point3f
@test to_pointf32(p) == Point3f(p)

@test Pointf(0.0, 0.0, 0.0) isa Point3f
@test Pointf(1.0, 1.0) isa Point2f
@test to_pointf32(0.0, 0.0, 0.0) isa Point3f
@test to_pointf32(1.0, 1.0) isa Point2f

@test Pointf((0.0, 0.0, 0.0 )) isa Point3f
@test Pointf((1.0, 1.0)) isa Point2f
@test to_pointf32((0.0, 0.0, 0.0 )) isa Point3f
@test to_pointf32((1.0, 1.0)) isa Point2f

@test Pointf([0.0, 0.0, 0.0]) isa Point3f
@test Pointf([1.0, 1.0]) isa Point2f
@test to_pointf32([0.0, 0.0, 0.0]) isa Point3f
@test to_pointf32([1.0, 1.0]) isa Point2f

@test Pointf(SA[0.0, 0.0, 0.0]) isa Point3f
@test Pointf(SA[1.0, 1.0]) isa Point2f
@test to_pointf32(SA[0.0, 0.0, 0.0]) isa Point3f
@test to_pointf32(SA[1.0, 1.0]) isa Point2f

g = complete_graph(3)
pos1 = [(0,0),
Expand All @@ -226,9 +226,9 @@ end
pos3 = [SA[0,0],
SA[1,1],
SA[0,1]]
@test isconcretetype(typeof(Pointf.(pos1)))
@test isconcretetype(typeof(Pointf.(pos2)))
@test isconcretetype(typeof(Pointf.(pos3)))
@test isconcretetype(typeof(to_pointf32.(pos1)))
@test isconcretetype(typeof(to_pointf32.(pos2)))
@test isconcretetype(typeof(to_pointf32.(pos3)))
graphplot(g; layout=(x)->pos1)
graphplot(g; layout=(x)->pos2)
graphplot(g; layout=(x)->pos3)
Expand Down Expand Up @@ -278,9 +278,12 @@ end
@test ax isa LScene
end

@testset "test empty endge Blot" begin
@testset "test empty edge plot" begin
GraphMakie.edgeplot(GraphMakie.Line{Point{2, Float32}}[])
GraphMakie.edgeplot(GraphMakie.AbstractPath{Point{2, Float32}}[])

# test empty edge color
graphplot(SimpleGraph(2); edge_color=Symbol[])
end

include("referencetests.jl")
Expand Down
Loading