Skip to content

Commit

Permalink
support ConstructionBase (#41)
Browse files Browse the repository at this point in the history
manual implementation only needed for FK5Coords{e}, other types work out of the box
allows interop with packages listed at https://github.com/JuliaObjects/ConstructionBase.jl
  • Loading branch information
aplavin authored May 17, 2022
1 parent 10cc6dc commit 704857f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ version = "1.0.0"

[deps]
AstroAngles = "5c4adb95-c1fc-4c53-b4ea-2a94080c53d2"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
AstroAngles = "0.1"
ConstructionBase = "1"
StaticArrays = "0.8, 0.9, 1"
julia = "1.3"
1 change: 1 addition & 0 deletions src/SkyCoords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ __precompile__()

module SkyCoords
using StaticArrays
import ConstructionBase: constructorof

export AbstractSkyCoords,
ICRSCoords,
Expand Down
1 change: 1 addition & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ FK5Coords{e}(ra::Real, dec::Real) where {e} =
FK5Coords{e}(promote(float(ra), float(dec))...)
FK5Coords{e}(c::T) where {e,T<:AbstractSkyCoords} = convert(FK5Coords{e}, c)
FK5Coords{e,F}(c::T) where {e,F,T<:AbstractSkyCoords} = convert(FK5Coords{e,F}, c)
constructorof(::Type{<:FK5Coords{e}}) where {e} = FK5Coords{e}


# Scalar coordinate conversions
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
AstroAngles = "5c4adb95-c1fc-4c53-b4ea-2a94080c53d2"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using Printf
using SkyCoords
using Statistics
using Test
using ConstructionBase: setproperties

import SkyCoords: lat, lon

Expand Down Expand Up @@ -179,3 +180,9 @@ end
@test 11.9 < lon(c2) |> rad2deg < 12.0
@test 59.9 < lat(c2) |> rad2deg < 60.0
end

@testset "constructionbase" begin
@test setproperties(ICRSCoords(1, 2), ra=3) == ICRSCoords(3, 2)
@test setproperties(GalCoords(1, 2), l=3) == GalCoords(3, 2)
@test setproperties(FK5Coords{2000}(1, 2), ra=3) == FK5Coords{2000}(3, 2)
end

0 comments on commit 704857f

Please sign in to comment.