Skip to content

Commit 1c62d12

Browse files
authored
Add reconstruct method for Cartesian without units (#328)
1 parent 18f67f2 commit 1c62d12

File tree

2 files changed

+48
-17
lines changed

2 files changed

+48
-17
lines changed

src/crs/basic/cartesian.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ constructor(::Type{<:Cartesian{Datum}}) where {Datum} = Cartesian{Datum}
119119

120120
constructor(::Type{<:Cartesian}) = Cartesian
121121

122+
reconstruct(C::Type{Cartesian{Datum}}, raw) where {Datum} = constructor(C)(raw...)
123+
124+
reconstruct(C::Type{Cartesian}, raw) = constructor(C)(raw...)
125+
122126
lentype(::Type{<:Cartesian{Datum,N,L}}) where {Datum,N,L} = L
123127

124128
==(coords₁::Cartesian{Datum,N}, coords₂::Cartesian{Datum,N}) where {Datum,N} = _coords(coords₁) == _coords(coords₂)

test/crs/api.jl

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,37 +219,64 @@
219219

220220
@testset "reconstruct" begin
221221
c = Cartesian(T(1) * mm, T(2) * mm)
222-
rv = CoordRefSystems.raw(c)
223-
@test CoordRefSystems.reconstruct(typeof(c), rv) == c
224-
c = Polar(T(1) * km, T(2) * rad)
225-
rv = CoordRefSystems.raw(c)
226-
@test CoordRefSystems.reconstruct(typeof(c), rv) == c
222+
r = CoordRefSystems.raw(c)
223+
@test CoordRefSystems.reconstruct(typeof(c), r) == c
224+
C = Cartesian{WGS84Latest}
225+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * m)
226+
C = Cartesian
227+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * m)
228+
227229
c = Cartesian(T(1) * cm, T(2) * cm, T(3) * cm)
228-
rv = CoordRefSystems.raw(c)
229-
@test CoordRefSystems.reconstruct(typeof(c), rv) == c
230+
r = CoordRefSystems.raw(c)
231+
@test CoordRefSystems.reconstruct(typeof(c), r) == c
232+
C = Cartesian{WGS84Latest}
233+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * m, T(3) * m)
234+
C = Cartesian
235+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * m, T(3) * m)
236+
237+
c = Polar(T(1) * km, T(2) * rad)
238+
r = CoordRefSystems.raw(c)
239+
@test CoordRefSystems.reconstruct(typeof(c), r) == c
240+
C = Polar{WGS84Latest}
241+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * rad)
242+
C = Polar
243+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * rad)
244+
230245
c = Cylindrical(T(1) * cm, T(2) * rad, T(3) * cm)
231-
rv = CoordRefSystems.raw(c)
232-
@test CoordRefSystems.reconstruct(typeof(c), rv) == c
246+
r = CoordRefSystems.raw(c)
247+
@test CoordRefSystems.reconstruct(typeof(c), r) == c
248+
C = Cylindrical{WGS84Latest}
249+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * rad, T(3) * m)
250+
C = Cylindrical
251+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * rad, T(3) * m)
252+
233253
c = Spherical(T(1) * mm, T(2) * rad, T(3) * rad)
234-
rv = CoordRefSystems.raw(c)
235-
@test CoordRefSystems.reconstruct(typeof(c), rv) == c
254+
r = CoordRefSystems.raw(c)
255+
@test CoordRefSystems.reconstruct(typeof(c), r) == c
256+
C = Spherical{WGS84Latest}
257+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * rad, T(3) * rad)
258+
C = Spherical
259+
@test CoordRefSystems.reconstruct(C, r) == C(T(1) * m, T(2) * rad, T(3) * rad)
236260

237261
for C in geographic2D
238262
c = C(T(30), T(60))
239-
rv = CoordRefSystems.raw(c)
240-
@test CoordRefSystems.reconstruct(typeof(c), rv) == c
263+
r = CoordRefSystems.raw(c)
264+
@test CoordRefSystems.reconstruct(typeof(c), r) == c
265+
@test CoordRefSystems.reconstruct(C, r) == c
241266
end
242267

243268
for C in geographic3D
244269
c = C(T(30), T(60), T(1))
245-
rv = CoordRefSystems.raw(c)
246-
@test CoordRefSystems.reconstruct(typeof(c), rv) == c
270+
r = CoordRefSystems.raw(c)
271+
@test CoordRefSystems.reconstruct(typeof(c), r) == c
272+
@test CoordRefSystems.reconstruct(C, r) == c
247273
end
248274

249275
for C in projected
250276
c = C(T(1), T(2))
251-
rv = CoordRefSystems.raw(c)
252-
@test CoordRefSystems.reconstruct(typeof(c), rv) == c
277+
r = CoordRefSystems.raw(c)
278+
@test CoordRefSystems.reconstruct(typeof(c), r) == c
279+
@test CoordRefSystems.reconstruct(C, r) == c
253280
end
254281
end
255282

0 commit comments

Comments
 (0)