diff --git a/src/PVector.jl b/src/PVector.jl index f234c96..0c13318 100644 --- a/src/PVector.jl +++ b/src/PVector.jl @@ -226,4 +226,15 @@ measurement(p::PVector2D) = PVector2D(measurement(p.x), measurement(p.y)) measurement(p::PVector) = PVector(measurement(p.x), measurement(p.y), measurement(p.z)) measurement(p::PVector2D, e::PVector2D) = PVector2D(measurement(p.x, e.x), measurement(p.y, e.y)) -measurement(p::PVector, e::PVector) = PVector(measurement(p.x, e.x), measurement(p.y, e.y), measurement(p.z, e.z)) \ No newline at end of file +measurement(p::PVector, e::PVector) = PVector(measurement(p.x, e.x), measurement(p.y, e.y), measurement(p.z, e.z)) + +function ismeasurement(x) + if x isa Unitful.Quantity + return x.val isa Measurement + end + + return x isa Measurement +end + +ismeasurement(p::AbstractPoint2D) = ismeasurement(p.x) && ismeasurement(p.y) +ismeasurement(p::AbstractPoint3D) = ismeasurement(p.x) && ismeasurement(p.y) && ismeasurement(p.z) diff --git a/src/PhysicalParticles.jl b/src/PhysicalParticles.jl index 44ec09d..15eb9c0 100644 --- a/src/PhysicalParticles.jl +++ b/src/PhysicalParticles.jl @@ -137,6 +137,7 @@ export @u_str, Measurement, measurement, + ismeasurement, # Random randn_pvector, randn_pvector2d, diff --git a/test/testUnits.jl b/test/testUnits.jl index 17c783a..7763278 100644 --- a/test/testUnits.jl +++ b/test/testUnits.jl @@ -235,5 +235,10 @@ p = Massless2D(Measurement, Int, uAstro) @test p.Pos.x == measurement(0.0u"kpc") @test value(p).Pos.x == 0.0u"kpc" + + @test ismeasurement(PVector(Measurement)) + @test ismeasurement(PVector2D(Measurement)) + @test ismeasurement(PVector(Measurement, u"m")) + @test ismeasurement(PVector2D(Measurement, u"m")) end end \ No newline at end of file