@@ -24,13 +24,13 @@ RegularGrid((10, 20, 30), Point(Cylindrical(0.0, 0.0, 0.0)), (3.0, 2.0, 1.0))
24
24
25
25
See also [`CartesianGrid`](@ref).
26
26
"""
27
- struct RegularGrid{M<: Manifold ,C<: CRS ,S<: Tuple ,N } <: Grid{M,C,N}
27
+ struct RegularGrid{M<: Manifold ,C<: CRS ,N, S<: NTuple{N,Quantity} } <: Grid{M,C,N}
28
28
origin:: Point{M,C}
29
29
spacing:: S
30
30
offset:: Dims{N}
31
31
topology:: GridTopology{N}
32
32
33
- function RegularGrid {M,C,S,N } (origin, spacing, offset, topology) where {M<: Manifold ,C<: CRS ,S<: Tuple ,N }
33
+ function RegularGrid {M,C,N,S } (origin, spacing, offset, topology) where {M<: Manifold ,C<: CRS ,N, S<: NTuple{N,Quantity} }
34
34
if ! all (s -> s > zero (s), spacing)
35
35
throw (ArgumentError (" spacing must be positive" ))
36
36
end
40
40
41
41
function RegularGrid (
42
42
origin:: Point{M,C} ,
43
- spacing:: Tuple ,
43
+ spacing:: NTuple{N,Number} ,
44
44
offset:: Dims{N} ,
45
45
topology:: GridTopology{N}
46
46
) where {M<: Manifold ,C<: CRS ,N}
47
- if manifold (origin) < : 🌐 && ! (crs (origin) <: LatLon )
47
+ if M < : 🌐 && ! (C <: LatLon )
48
48
throw (ArgumentError (" regular spacing on `🌐` requires `LatLon` coordinates" ))
49
49
end
50
50
51
51
T = CoordRefSystems. mactype (C)
52
52
nc = CoordRefSystems. ncoords (C)
53
53
us = CoordRefSystems. units (C)
54
- ns = length (spacing)
55
54
56
55
if N ≠ nc
57
56
throw (ArgumentError ("""
@@ -60,19 +59,17 @@ function RegularGrid(
60
59
""" ))
61
60
end
62
61
63
- if ns ≠ nc
64
- throw (ArgumentError ("""
65
- A $N -dimensional regular grid requires $N spacing values.
66
- The provided spacing has $ns values.
67
- """ ))
68
- end
69
-
70
62
sp = ntuple (i -> numconvert (T, withunit (spacing[i], us[i])), nc)
71
63
72
- RegularGrid {M,C,typeof(sp),N } (origin, sp, offset, topology)
64
+ RegularGrid {M,C,N, typeof(sp)} (origin, sp, offset, topology)
73
65
end
74
66
75
- function RegularGrid (dims:: Dims{N} , origin:: Point , spacing:: Tuple , offset:: Dims{N} = ntuple (i -> 1 , N)) where {N}
67
+ function RegularGrid (
68
+ dims:: Dims{N} ,
69
+ origin:: Point ,
70
+ spacing:: NTuple{N,Number} ,
71
+ offset:: Dims{N} = ntuple (i -> 1 , N)
72
+ ) where {N}
76
73
if ! all (> (0 ), dims)
77
74
throw (ArgumentError (" dimensions must be positive" ))
78
75
end
@@ -90,7 +87,7 @@ function vertex(g::RegularGrid, ijk::Dims)
90
87
Point (ctor (vals... ))
91
88
end
92
89
93
- @generated function xyz (g:: RegularGrid{M,C,S, N} ) where {M,C,S ,N}
90
+ @generated function xyz (g:: RegularGrid{M,C,N} ) where {M,C,N}
94
91
exprs = ntuple (N) do i
95
92
:(range (start= orig[$ i], step= spac[$ i], length= (dims[$ i] + 1 )))
96
93
end
0 commit comments