Skip to content

Commit

Permalink
Add FT(Point)
Browse files Browse the repository at this point in the history
It is easy to go from a number to a Geometry.Point, but it is not easy
to go in the other direction (unless the type of point of point is
known). This PR adds new methods to Float32, Float64, and BigFloat to
X/Y/Z/Lat/Long point to convert them into numbers.

This feature would be very useful in converting a Field of ZPoints into
a scalar field, which is what we need for the interpolation routines
  • Loading branch information
Sbozzolo committed Feb 1, 2024
1 parent 578a032 commit 475f41f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Geometry/coordinates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ Define a subtype `name` of `AbstractPoint` with appropriate conversion functions
macro pointtype(name, fields...)
if length(fields) == 1
supertype = :(Abstract1DPoint{FT})
coord = fields[1]
tofloat = quote
Base.Float32(p::$name) = Base.Float32(p.$coord)
Base.Float64(p::$name) = Base.Float64(p.$coord)
Base.BigFloat(p::$name) = Base.BigFloat(p.$coord)
end
elseif length(fields) == 2
supertype = :(Abstract2DPoint{FT})
tofloat = :()
elseif length(fields) == 3
supertype = :(Abstract3DPoint{FT})
tofloat = :()
end
esc(
quote
Expand All @@ -90,6 +98,7 @@ macro pointtype(name, fields...)
::Type{$name{FT1}},
::Type{$name{FT2}},
) where {FT1, FT2} = $name{promote_type(FT1, FT2)}
$tofloat
end,
)
end
Expand Down
1 change: 1 addition & 0 deletions test/Geometry/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using LinearAlgebra, StaticArrays
@test pt < pt * FT(2)
@test pt <= pt
@test pt <= pt * FT(2)
@test FT(pt) == one(FT)
end
end

Expand Down

0 comments on commit 475f41f

Please sign in to comment.