Skip to content

Commit c50309f

Browse files
authored
Fixes in leepacific() and add option to do inner annotations with quoted lines. (#1786)
* Add plotgrid! test * Do not duplicate cmd when -Sqx... * Use pointer tricks in gmt_centroid_area() to avoid data copies. * Fixes in leepacific() and add option to do inner annotations with quoted lines.
1 parent d45f90d commit c50309f

4 files changed

Lines changed: 131 additions & 52 deletions

File tree

src/libgmt.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,27 +428,37 @@ function gmt_free_mem(API::Ptr{Cvoid}, mem)
428428
end
429429

430430
function gmt_centroid_area(API::Ptr{Cvoid}, D, geo::Int=0)::Matrix{Float64}
431-
if (isa(D, Vector))
431+
if (isa(D, Vector)) # 'D' is a vector of GMTdatasets but that type is not yet known here.
432432
mat = Matrix{Float64}(undef, length(D), 3)
433433
for k in eachindex(D)
434-
t = gmt_centroid_area(API::Ptr{Cvoid}, D[k].data[:,1], D[k].data[:,2], geo)
434+
ref1, ref2, nr = pointercols(D[k])
435+
t = gmt_centroid_area(API, ref1, ref2, geo, nr)
435436
mat[k, 1], mat[k, 2], mat[k, 3] = t[1], t[2], t[3]
436437
end
437438
mat
438439
else
439-
gmt_centroid_area(API::Ptr{Cvoid}, D.data[:,1], D.data[:,2], geo)
440+
ref1, ref2, nr = pointercols(D)
441+
gmt_centroid_area(API, ref1, ref2, geo, nr)
440442
end
441443
end
442444

443-
function gmt_centroid_area(API::Ptr{Cvoid}, x::Vector{Float64}, y::Vector{Float64}, geo::Int=0)::Matrix{Float64}
445+
function gmt_centroid_area(API::Ptr{Cvoid}, x, y, geo::Int=0, n::Int=0)::Matrix{Float64}
444446
# geo = 0 for Cartesian, !=0 for geographic
447+
@assert isa(x, Vector{Float64}) || isa(x, Ptr{Float64}) || isa(x, Ref{Float64}) "Bad type for x"
448+
!isa(x, Vector{Float64}) && (n == 0) && error("Must provide 'n' when x is not a Vector")
449+
(n == 0) && (n = length(x))
445450
pos = [0.0 0.0 0.0]
446451
area = ccall((:gmt_centroid_area, libgmt), Cdouble, (Cstring, Ptr{Cdouble}, Ptr{Cdouble}, UInt64, Int32, Ptr{Cdouble}),
447-
GMT_Get_Ctrl(API), x, y, length(x), geo, pos)
452+
GMT_Get_Ctrl(API), x, y, n, geo, pos)
448453
pos[3] = abs(area)
449454
return pos
450455
end
451456

457+
function pointercols(D::AbstractArray{Float64,2}, cols=(1,2))
458+
nr = size(D, 1)
459+
return Ref(D[:], (cols[1]-1)*nr + 1), Ref(D[:], (cols[2]-cols[1])*nr + 1), nr
460+
end
461+
452462
#=
453463
function get_common_R(API::Ptr{Cvoid})
454464
R = COMMON_R((false,false,false,false), false, 0, 0, 0, (0., 0., 0., 0., 0., 0.), (0., 0., 0., 0.), (0., 0.), map(UInt8, (string(repeat(" ",256))...,)))

src/psxy.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,26 +980,26 @@ end
980980
# ---------------------------------------------------------------------------------------------------
981981
function build_run_cmd(cmd, opt_B, opt_Gsymb, opt_ML, opt_S, opt_W, opt_Wmarker, opt_UVXY, opt_c)::Vector{String}
982982
# Build the executble command vector
983-
if (opt_W != "" && opt_S == "") # We have a line/polygon request
983+
if (opt_W != "" && opt_S == "") # We have a line/polygon request
984984
_cmd = [cmd * opt_W * opt_UVXY]
985985

986986
elseif (opt_W == "" && (opt_S != "" || opt_Gsymb != "")) # We have a symbol request
987987
(opt_Wmarker != "" && opt_W == "") && (opt_Gsymb *= " -W" * opt_Wmarker) # reuse var name
988988
(opt_ML != "") && (cmd *= opt_ML) # If we have a symbol outline pen
989989
_cmd = [cmd * opt_S * opt_Gsymb * opt_UVXY]
990990

991-
elseif (opt_W != "" && opt_S != "") # We have both line/polygon and a symbol
991+
elseif (opt_W != "" && opt_S != "") # We have both line/polygon and a symbol
992992
(occursin(opt_Gsymb, cmd)) && (opt_Gsymb = "")
993993
c = lowercase(opt_S[4])
994-
if (c == 'v' || c == 'm' || c == 'w' || c == '=') # Are there more cases where the pen applies to the symbol?
994+
if (c == 'v' || c == 'm' || c == 'w' || c == '=' || c == 'q') # Are there more cases where the pen applies to the symbol?
995995
_cmd = [cmd * opt_W * opt_S * opt_Gsymb * opt_UVXY]
996996
else
997997
(opt_Wmarker != "") && (opt_Wmarker = " -W" * opt_Wmarker) # Set Symbol edge color
998998
cmd1 = cmd * opt_W * opt_UVXY
999999
(opt_B != " " && opt_B != "") && (cmd = replace(cmd, opt_B => "")) # Some themes make opt_B = " "
10001000
cmd2 = cmd * opt_S * opt_Gsymb * opt_Wmarker # Don't repeat option -B
10011001
(opt_c != "") && (cmd2 = replace(cmd2, opt_c => "")) # Not in scond call (subplots)
1002-
(opt_ML != "") && (cmd2 = cmd2 * opt_ML) # If we have a symbol outline pen
1002+
(opt_ML != "") && (cmd2 = cmd2 * opt_ML) # If we have a symbol outline pen
10031003
_cmd = [cmd1; cmd2]
10041004
end
10051005

0 commit comments

Comments
 (0)