From f5ec8511039124d8d304af7c6a20d9943c61941c Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Fri, 11 Oct 2024 09:53:31 -0700 Subject: [PATCH] Halve the number of calls to cosd, sind in spherical `cellarea` (#794) --- ext/RastersProjExt/cellarea.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ext/RastersProjExt/cellarea.jl b/ext/RastersProjExt/cellarea.jl index 9d9d506d..7b2cda59 100644 --- a/ext/RastersProjExt/cellarea.jl +++ b/ext/RastersProjExt/cellarea.jl @@ -38,9 +38,11 @@ end _lonlat_to_sphericalpoint(args) = _lonlat_to_sphericalpoint(args...) function _lonlat_to_sphericalpoint(lon, lat) - x = cosd(lat) * cosd(lon) - y = cosd(lat) * sind(lon) - z = sind(lat) + lonsin, loncos = sincosd(lon) + latsin, latcos = sincosd(lat) + x = latcos * loncos + y = latcos * lonsin + z = latsin return SphericalPoint(x,y,z) end @@ -182,4 +184,4 @@ function axis_is_degrees(crs::Proj.CRS, axis_index::Int; context::Ptr{Proj.PJ_CO # in which case we should technically return true. # We'd also have to return the conversion factor in this case, and maybe the category (radians or degrees)... return isequal(unit_str, "degree") -end \ No newline at end of file +end