Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix show #177

Closed
wants to merge 6 commits into from
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
16 changes: 9 additions & 7 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@
# But not if geom is already a WrapperGeometry
convert(::Type{$geomtype}, ::$trait, geom::$geomtype) = geom

function Base.show(io::IO, ::MIME"text/plain", geom::$geomtype{Z, M, T, E, C}; show_mz::Bool = true, screen_ncols::Int = displaysize(io)[2]) where {Z, M, T, E <: Union{Nothing,Extents.Extent}, C}
function Base.show(io::IO, ::MIME"text/plain", geom::$geomtype{Z, M, T, E, C};

Check warning on line 175 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L175

Added line #L175 was not covered by tests
show_mz::Bool = true, screen_ncols::Int = displaysize(io)[2]
) where {Z, M, T, E <: Union{Nothing,Extents.Extent}, C}
compact = get(io, :compact, false)
spacing = compact ? "" : " "
show_mz &= !compact
Expand All @@ -188,7 +190,7 @@
end
end

str = "$($geomtype)"
str = string($geomtype)

Check warning on line 193 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L193

Added line #L193 was not covered by tests
if show_mz
str *= "{$Z,$(spacing)$M}"
end
Expand Down Expand Up @@ -234,7 +236,7 @@

str *= "]"
else
str *= _nice_geom_str(g, false, compact, screen_ncols - currently_used_space)
str *= _nice_geom_str(parent(geom), false, compact, screen_ncols - currently_used_space)

Check warning on line 239 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L239

Added line #L239 was not covered by tests
end

str *= extent_str
Expand Down Expand Up @@ -449,7 +451,7 @@
end
Base.:(!=)(g1::Point, g2::Point) = !(g1 == g2)

function Base.show(io::IO, ::MIME"text/plain", point::Point{Z, M, T, C}; show_mz::Bool = true) where {Z,M,T,C}
function Base.show(io::IO, ::MIME"text/plain", point::Point{Z, M, T, C}; show_mz::Bool = true, screen_ncols::Int = displaysize(io)[2]) where {Z,M,T,C}

Check warning on line 454 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L454

Added line #L454 was not covered by tests
rafaqz marked this conversation as resolved.
Show resolved Hide resolved
print(io, "Point")
this_crs = crs(point)

Expand Down Expand Up @@ -652,9 +654,9 @@
isfeaturecollection(fc::Type{<:FeatureCollection}) = true
trait(fc::FeatureCollection) = FeatureCollectionTrait()

nfeature(::FeatureCollectionTrait, fc::FeatureCollection) =
nfeature(t::FeatureCollectionTrait, fc::FeatureCollection) =

Check warning on line 657 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L657

Added line #L657 was not covered by tests
_parent_is_fc(fc) ? nfeature(t, parent(fc)) : length(parent(fc))
getfeature(::FeatureCollectionTrait, fc::FeatureCollection) =
getfeature(t::FeatureCollectionTrait, fc::FeatureCollection) =

Check warning on line 659 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L659

Added line #L659 was not covered by tests
_parent_is_fc(fc) ? getfeature(t, parent(fc)) : parent(fc)
getfeature(t::FeatureCollectionTrait, fc::FeatureCollection, i::Integer) =
_parent_is_fc(fc) ? getfeature(t, parent(fc), i) : parent(fc)[i]
Expand All @@ -665,4 +667,4 @@

_parent_is_fc(x) = isfeaturecollection(parent(x))

end # module
end # module
44 changes: 36 additions & 8 deletions test/test_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ using Test, GeoFormatTypes, Extents
import GeoInterface as GI
using GeoInterface.Wrappers

# use this to test our string representations for geoms
buf = IOBuffer()
compact_buf = IOContext(buf, :compact => true)

# checks that our string display for geoms in regular/compact form is as expected
function test_display(geom, expected_str, expected_compact_str)
# checks non-compact string repr
show(buf, MIME"text/plain"(), geom)
@test expected_str == String(take!(buf))
generated_str = sprint() do io
show(io, MIME"text/plain"(), geom)
end
@test expected_str == generated_str
# checks compact string repr
show(compact_buf, MIME"text/plain"(), geom)
@test expected_compact_str == String(take!(buf))
generated_compact_str = sprint() do io
show(IOContext(io, :compact => true), MIME"text/plain"(), geom)
end
@test expected_compact_str == generated_compact_str
end

# Point
Expand Down Expand Up @@ -365,6 +365,34 @@ test_display(fc, "FeatureCollection([Feature(MultiPolygon{false, false}([Polygon
vecfc = GI.FeatureCollection([(geometry=(1,2), a=1, b=2)])
@test GI.getfeature(vecfc, 1) == (geometry=(1,2), a=1, b=2)



struct MaPointRappa
x::Float64
y::Float64
end

@testset "Wrapped geometry printing" begin

GI.geomtrait(::MaPointRappa) = GI.PointTrait()
GI.ncoord(::GI.PointTrait, ::MaPointRappa) = 2
GI.x(::GI.PointTrait, p::MaPointRappa) = p.x
GI.y(::GI.PointTrait, p::MaPointRappa) = p.y


test_display(GI.Point(MaPointRappa(1.0, 2.0)), "Point{false, false}((1.0, 2.0))", "Point((1.0,2.0))")

GI.geomtrait(::Vector{MaPointRappa}) = GI.LineStringTrait()
GI.npoint(::GI.LineStringTrait, v::Vector{MaPointRappa}) = length(v)
GI.getpoint(::GI.LineStringTrait, v::Vector{MaPointRappa}, i::Integer) = v[i]

test_display(
GI.LineString([MaPointRappa(1.0, 2.0), MaPointRappa(3.0, 4.0)]),
"LineString{false, false}([MaPointRappa(1.0, 2.0), MaPointRappa(3.0, 4.0)])",
"LineString([MaPointRappa(1.0, 2.0),MaPointRappa(3.0, 4.0)])" # FIXME: this should not show the point type!
)
end

# TODO

# # Triangle
Expand Down
Loading