Skip to content

Commit

Permalink
add ismeasurement [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
islent committed Jan 15, 2024
1 parent f205911 commit 1d6e57f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/PVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
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)
1 change: 1 addition & 0 deletions src/PhysicalParticles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export

@u_str,
Measurement, measurement,
ismeasurement,

# Random
randn_pvector, randn_pvector2d,
Expand Down
5 changes: 5 additions & 0 deletions test/testUnits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1d6e57f

Please sign in to comment.