Skip to content

Commit

Permalink
Use length instead of dx to prevent rounding errors (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion authored May 29, 2023
1 parent ac1cd80 commit c651836
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GeoArrays"
uuid = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab"
authors = ["Maarten Pronk <[email protected]>"]
version = "0.8.2"
version = "0.8.3"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Expand Down
4 changes: 1 addition & 3 deletions src/geoarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ function ranges(ga::GeoArray, strategy::AbstractStrategy=Center())
extra = typeof(strategy) == Center ? 0 : 1
lx, ly = coords(ga, (1, 1), strategy)
hx, hy = coords(ga, size(ga)[1:2] .+ extra, strategy)
dx = ga.f.linear[1, 1]
dy = ga.f.linear[2, 2]
lx:dx:hx, ly:dy:hy
range(lx, hx, length=size(ga)[1] + extra), range(ly, hy, length=size(ga)[2] + extra)
end

"""
Expand Down
14 changes: 11 additions & 3 deletions test/test_geoarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,16 @@ end
end

@testset "Ranges" begin
ga = GeoArray(rand(10, 10))
ga = GeoArray(rand(Bool, 21601, 10801))
ga.f = AffineMap([0.016666666666666666 0.0; 0.0 -0.016666666666666666], [-180.00833333333333, 90.00833333333334])
X, Y = GeoArrays.ranges(ga)
@test X == 0.5:1.0:9.5
@test Y == 0.5:1.0:9.5
@test last(X) 180.00
@test last(Y) -90.00
@test length(X) == 21601
@test length(Y) == 10801
X, Y = GeoArrays.ranges(ga, GeoArrays.Vertex())
@test length(X) == 21602
@test length(Y) == 10802
@test last(X) 180.00833333333333
@test last(Y) -90.00833333333334
end

2 comments on commit c651836

@evetion
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/84453

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.3 -m "<description of version>" c65183612d7d9c02395d190ae019e5755a030fd1
git push origin v0.8.3

Please sign in to comment.