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

Add Base.float(::Type{Q}) to fix Meshes.jl #110

Merged
merged 2 commits into from
Jan 19, 2024
Merged
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
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ julia = "1.6"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
Ratios = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SaferIntegers = "88634af6-177f-5301-88b8-7819386cfa38"
Expand All @@ -43,4 +44,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[targets]
test = ["Aqua", "LinearAlgebra", "Measurements", "Ratios", "SaferIntegers", "SafeTestsets", "ScientificTypes", "StaticArrays", "Test", "Unitful"]
test = ["Aqua", "LinearAlgebra", "Measurements", "Meshes", "Ratios", "SaferIntegers", "SafeTestsets", "ScientificTypes", "StaticArrays", "Test", "Unitful"]
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ Base.oneunit(::AbstractDimensions) = error("There is no such thing as a dimensio
Base.oneunit(::Type{<:UnionAbstractQuantity}) = error("Cannot create a dimensionful 1 for a `UnionAbstractQuantity` type without knowing the dimensions. Please use `oneunit(::UnionAbstractQuantity)` instead.")
Base.oneunit(::Type{<:AbstractDimensions}) = error("There is no such thing as a dimensionful 1 for a `AbstractDimensions` type, as + is only defined for `UnionAbstractQuantity`.")

Base.float(::Type{Q}) where {T,D,Q<:UnionAbstractQuantity{T,D}} = with_type_parameters(Q, Base.float(T), D)

Base.show(io::IO, d::AbstractDimensions) =
let tmp_io = IOBuffer()
for k in filter(k -> !iszero(d[k]), keys(d))
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ else
@safetestset "Measurements.jl integration tests" begin
include("test_measurements.jl")
end
@safetestset "Meshes.jl integration tests" begin
include("test_meshes.jl")
end
@safetestset "Unit tests" begin
include("unittests.jl")
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_meshes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using DynamicQuantities
using Meshes: Meshes

v = Meshes.Vec(1.0u"m/s", 2.0u"m/s", 3.0u"m/s")
@test typeof(v) <: Meshes.Vec{3, <:Quantity{Float64, <:Dimensions}}
@test v.coords == (1.0u"m/s", 2.0u"m/s", 3.0u"m/s")
6 changes: 6 additions & 0 deletions test/unittests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ end
@test typeof(d) == D
@test typeof(ulength(d)) == R
end

# Can convert type with float(...):
x = Quantity{Int}(u"m/s")
@test typeof(x) == Quantity{Int64,DEFAULT_DIM_TYPE}
y = float(typeof(x))
@test y == Quantity{Float64,DEFAULT_DIM_TYPE}
end

@testset "Units" begin
Expand Down
Loading