From d9363b8a68b42651a5c84e75d032f648aadda096 Mon Sep 17 00:00:00 2001 From: Elias Carvalho <73039601+eliascarv@users.noreply.github.com> Date: Fri, 10 May 2024 15:10:44 -0300 Subject: [PATCH] Update `Cartesian` constructors (#77) * Update 'Cartesian' constructors * Apply suggestions --- src/crs/basic.jl | 8 +++++--- test/crs/constructors.jl | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/crs/basic.jl b/src/crs/basic.jl index ee23ca8..9634385 100644 --- a/src/crs/basic.jl +++ b/src/crs/basic.jl @@ -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`). @@ -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...) diff --git a/test/crs/constructors.jl b/test/crs/constructors.jl index eef03d7..c7b13f1 100644 --- a/test/crs/constructors.jl +++ b/test/crs/constructors.jl @@ -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)"