Is the code below a sound use of multiple dispatch?
Are there cleaner or more sound ways to the same?
using StaticArrays
const Point1D = SVector{1,Float64}
const Point2D = SVector{2,Float64}
" Generates a one-dimensional uniform mesh "
function genMesh(N;a=Point1D(0.),b=Point1D(1.))
if (a.x>=b.x)
ErrorException("Wrong input")
else
mesh = [a + (i-1)*(b-a)/N for i=1:N+1]
end
end
" Generates a two-dimensional uniform mesh "
function genMesh(N,a::Point2D,b::Point2D)
if ((a.x>=b.x)||(a.y>=b.y))
ErrorException("Wrong input")
else
mesh = [Point2D(a.x + (i-1)*(b.x-a.x)/N, b.y + (j-1)*(b.y-a.y)/N) for i=1:N+1,j=1:N+1]
end
end
with output
# Generate a one-dimensional mesh with 5 intervals
mesh = genMesh(5)
and
# Generate a two-dimensional mesh with 5 intervals
mesh = genMesh(10,Point2D(0,0.),Point2D(1.,1.))
Thanks.