Skip to content

Commit

Permalink
Update Cartesian constructors (#77)
Browse files Browse the repository at this point in the history
* Update 'Cartesian' constructors

* Apply suggestions
  • Loading branch information
eliascarv authored May 10, 2024
1 parent 118deef commit d9363b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/crs/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ abstract type Basic{Datum} <: CRS{Datum} end
"""
Cartesian(x₁, x₂, ..., xₙ)
Cartesian{Datum}(x₁, x₂, ..., xₙ)
Cartesian((x₁, x₂, ..., xₙ))
Cartesian{Datum}((x₁, x₂, ..., xₙ))
N-dimensional Cartesian coordinates `x₁, x₂, ..., xₙ` in length units (default to meter)
with a given `Datum` (default to `NoDatum`).
Expand All @@ -37,9 +39,9 @@ struct Cartesian{Datum,N,L<:Len} <: Basic{Datum}
end

Cartesian{Datum}(coords::NTuple{N,L}) where {Datum,N,L<:Len} = Cartesian{Datum,N,float(L)}(coords)
Cartesian{Datum}(coords::L...) where {Datum,L<:Len} = Cartesian{Datum}(coords)
Cartesian{Datum}(coords::Len...) where {Datum} = Cartesian{Datum}(promote(coords...))
Cartesian{Datum}(coords::Number...) where {Datum} = Cartesian{Datum}(addunit.(coords, u"m")...)
Cartesian{Datum}(coords::NTuple{N,Len}) where {Datum,N} = Cartesian{Datum}(promote(coords...))
Cartesian{Datum}(coords::NTuple{N,Number}) where {Datum,N} = Cartesian{Datum}(addunit.(coords, u"m"))
Cartesian{Datum}(coords::Number...) where {Datum} = Cartesian{Datum}(coords)

Cartesian(args...) = Cartesian{NoDatum}(args...)

Expand Down
3 changes: 3 additions & 0 deletions test/crs/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
@test Cartesian(T(1), T(1)) == Cartesian(T(1) * u"m", T(1) * u"m")
@test Cartesian(T(1), T(1), T(1)) == Cartesian(T(1) * u"m", T(1) * u"m", T(1) * u"m")
@test Cartesian(T(1) * u"m", 1 * u"m") == Cartesian(T(1) * u"m", T(1) * u"m")
@test Cartesian((T(1), T(1))) == Cartesian((T(1) * u"m", T(1) * u"m"))
@test Cartesian((T(1), T(1), T(1))) == Cartesian((T(1) * u"m", T(1) * u"m", T(1) * u"m"))
@test Cartesian((T(1) * u"m", 1 * u"m")) == Cartesian((T(1) * u"m", T(1) * u"m"))

c = Cartesian(T(1))
@test sprint(show, c) == "Cartesian{NoDatum}(x: 1.0 m)"
Expand Down

0 comments on commit d9363b8

Please sign in to comment.