Skip to content

Commit

Permalink
Merge pull request #110 from SymbolicML/meshes-compat
Browse files Browse the repository at this point in the history
Add `Base.float(::Type{Q})` to fix Meshes.jl
  • Loading branch information
MilesCranmer authored Jan 19, 2024
2 parents 756836e + c479ed3 commit 7c57bb0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
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

0 comments on commit 7c57bb0

Please sign in to comment.