Skip to content

Commit 7c57bb0

Browse files
authored
Merge pull request #110 from SymbolicML/meshes-compat
Add `Base.float(::Type{Q})` to fix Meshes.jl
2 parents 756836e + c479ed3 commit 7c57bb0

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ julia = "1.6"
3434
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3535
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3636
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
37+
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
3738
Ratios = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439"
3839
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
3940
SaferIntegers = "88634af6-177f-5301-88b8-7819386cfa38"
@@ -43,4 +44,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4344
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
4445

4546
[targets]
46-
test = ["Aqua", "LinearAlgebra", "Measurements", "Ratios", "SaferIntegers", "SafeTestsets", "ScientificTypes", "StaticArrays", "Test", "Unitful"]
47+
test = ["Aqua", "LinearAlgebra", "Measurements", "Meshes", "Ratios", "SaferIntegers", "SafeTestsets", "ScientificTypes", "StaticArrays", "Test", "Unitful"]

src/utils.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ Base.oneunit(::AbstractDimensions) = error("There is no such thing as a dimensio
286286
Base.oneunit(::Type{<:UnionAbstractQuantity}) = error("Cannot create a dimensionful 1 for a `UnionAbstractQuantity` type without knowing the dimensions. Please use `oneunit(::UnionAbstractQuantity)` instead.")
287287
Base.oneunit(::Type{<:AbstractDimensions}) = error("There is no such thing as a dimensionful 1 for a `AbstractDimensions` type, as + is only defined for `UnionAbstractQuantity`.")
288288

289+
Base.float(::Type{Q}) where {T,D,Q<:UnionAbstractQuantity{T,D}} = with_type_parameters(Q, Base.float(T), D)
290+
289291
Base.show(io::IO, d::AbstractDimensions) =
290292
let tmp_io = IOBuffer()
291293
for k in filter(k -> !iszero(d[k]), keys(d))

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ else
1919
@safetestset "Measurements.jl integration tests" begin
2020
include("test_measurements.jl")
2121
end
22+
@safetestset "Meshes.jl integration tests" begin
23+
include("test_meshes.jl")
24+
end
2225
@safetestset "Unit tests" begin
2326
include("unittests.jl")
2427
end

test/test_meshes.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using DynamicQuantities
2+
using Meshes: Meshes
3+
4+
v = Meshes.Vec(1.0u"m/s", 2.0u"m/s", 3.0u"m/s")
5+
@test typeof(v) <: Meshes.Vec{3, <:Quantity{Float64, <:Dimensions}}
6+
@test v.coords == (1.0u"m/s", 2.0u"m/s", 3.0u"m/s")

test/unittests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,12 @@ end
438438
@test typeof(d) == D
439439
@test typeof(ulength(d)) == R
440440
end
441+
442+
# Can convert type with float(...):
443+
x = Quantity{Int}(u"m/s")
444+
@test typeof(x) == Quantity{Int64,DEFAULT_DIM_TYPE}
445+
y = float(typeof(x))
446+
@test y == Quantity{Float64,DEFAULT_DIM_TYPE}
441447
end
442448

443449
@testset "Units" begin

0 commit comments

Comments
 (0)