Skip to content

Commit 7959564

Browse files
authored
Rename roundcoords -> coordround for consistency with other utils (#1185)
1 parent 4c5e825 commit 7959564

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

src/utils/basic.jl

-14
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,3 @@ Generate the coordinate arrays `XYZ` from the coordinate vectors `xyz`.
5555
end
5656
Expr(:tuple, exprs...)
5757
end
58-
59-
"""
60-
roundcoords(point, r=RoundNearest; digits=0, base=10)
61-
roundcoords(point, r=RoundNearest; sigdigits=0)
62-
63-
Rounds the coordinates of a `point` to specified presicion.
64-
"""
65-
function roundcoords(p::Point, r::RoundingMode=RoundNearest; kwargs...)
66-
c = coords(p)
67-
x = CoordRefSystems.values(c)
68-
x′ = round.(eltype(x), x, r; kwargs...)
69-
c′ = CoordRefSystems.constructor(c)(x′...)
70-
Point(c′)
71-
end

src/utils/crs.jl

+24-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If `weights` is passed, the weighted sum will be returned.
4141
"""
4242
function coordsum(points; weights=nothing)
4343
values = _coordsum(points, weights)
44-
fromvalues(first(points), values)
44+
_fromvalues(first(points), values)
4545
end
4646

4747
"""
@@ -57,25 +57,43 @@ function coordmean(points; weights=nothing)
5757
sum(weights)
5858
end
5959
values = _coordsum(points, weights) ./ den
60-
fromvalues(first(points), values)
60+
_fromvalues(first(points), values)
6161
end
6262

63-
function tovalues(p)
63+
"""
64+
coordround(point, r=RoundNearest; digits=0, base=10)
65+
coordround(point, r=RoundNearest; sigdigits=0)
66+
67+
Round the coordinates of a `point` to specified presicion.
68+
"""
69+
function coordround(point::Point, r::RoundingMode=RoundNearest; kwargs...)
70+
c = coords(point)
71+
x = CoordRefSystems.values(c)
72+
x′ = round.(eltype(x), x, r; kwargs...)
73+
c′ = CoordRefSystems.constructor(c)(x′...)
74+
Point(c′)
75+
end
76+
77+
# -----------------
78+
# HELPER FUNCTIONS
79+
# -----------------
80+
81+
function _tovalues(p)
6482
CRS = _basecrs(manifold(p))
6583
c = convert(CRS, coords(p))
6684
CoordRefSystems.values(c)
6785
end
6886

69-
function fromvalues(g, values)
87+
function _fromvalues(g, values)
7088
CRS = _basecrs(manifold(g))
7189
withcrs(g, values, CRS)
7290
end
7391

7492
function _coordsum(points, weights)
7593
if isnothing(weights)
76-
mapreduce(tovalues, .+, points)
94+
mapreduce(_tovalues, .+, points)
7795
else
78-
mapreduce((p, w) -> tovalues(p) .* w, .+, points, weights)
96+
mapreduce((p, w) -> _tovalues(p) .* w, .+, points, weights)
7997
end
8098
end
8199

test/utils.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
# round
5959
p₁ = cart(1, 1)
6060
p₂ = cart(1.0000000000004, 0.9999999999996)
61-
@test Meshes.roundcoords(p₁, sigdigits=5) == p₁
62-
@test Meshes.roundcoords(p₂, digits=10) == p₁
63-
@inferred Meshes.roundcoords(p₁, digits=10)
61+
@test Meshes.coordround(p₁, sigdigits=5) == p₁
62+
@test Meshes.coordround(p₂, digits=10) == p₁
63+
@inferred Meshes.coordround(p₁, digits=10)
6464
end

0 commit comments

Comments
 (0)