```#'@title add_padding
#'
#'
#'@param heightmap A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced.
#'@keywords internal
temp = matrix(0, nrow = nrow(heightmap) + 2, ncol = ncol(heightmap) + 2)
temp[2:(nrow(temp)-1), 2:(ncol(temp)-1)] = heightmap
temp[2:(nrow(temp)-1), 1] = heightmap[,1]
temp[1, 2:(ncol(temp)-1)] = heightmap[1,]
temp[2:(nrow(temp)-1), ncol(temp)] = heightmap[,ncol(heightmap)]
temp[nrow(temp), 2:(ncol(temp)-1)] = heightmap[nrow(heightmap),]
temp[1,1] = temp[1,2]
temp[1,ncol(temp)] = temp[1,ncol(temp)-1]
temp[nrow(temp),1] = temp[nrow(temp)-1,2]
temp[nrow(temp),ncol(temp)] = temp[nrow(temp)-1,ncol(temp)]
temp
}

#'
#'
#'@param heightmap A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced.
#'@keywords internal
if(length(dim(heightmap)) == 2) {
temp = matrix(0, nrow = nrow(heightmap) + 2*pad, ncol = ncol(heightmap) + 2*pad)
}
}
}
return(temp)
} else {
temp_height = list()
for(i in seq_len(dim(heightmap)[3])) {
}
temp_array = array(0,dim = c(dim(temp_height[[i]]), dim(heightmap)[3]))
for(i in seq_len(dim(heightmap)[3])) {
temp_array[,,i] = temp_height[[i]]
}
return(temp_array)
}
}

#'
#'
#'@param heightmap A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced.
#'@keywords internal
if(length(dim(heightmap)) == 2) {
} else {
}
}

#'
#'
#'@param heightmap A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced.
#'@keywords internal
whichdim = which.min(dim)
if(dim[1] != dim[2]) {
if(whichdim == 1) {
extra_rows = dim[2]-dim[1]
if(extra_rows %% 2 == 0) {
pad = matrix(0, nrow = extra_rows/2, ncol = ncol(kernel))
} else {
pad1 = matrix(0, nrow = floor(extra_rows/2)+1, ncol = ncol(kernel))
pad2 = matrix(0, nrow = floor(extra_rows/2), ncol = ncol(kernel))
}
} else {
extra_cols = dim[1]-dim[2]
if(extra_cols %% 2 == 0) {
pad = matrix(0, nrow = nrow(kernel), ncol = extra_cols/2)
} else {
pad1 = matrix(0, nrow = nrow(kernel), ncol = floor(extra_cols/2)+1)
pad2 = matrix(0, nrow = nrow(kernel), ncol = floor(extra_cols/2))
}
}
}
return(kernel)
}

#'@title expand to fit
#'
#'
#'@param dim desired size
#'@keywords internal
expand_to_fit = function(dim, kernel) {
kdim = dim(kernel)
if(!all(kdim <= dim)) {
stop("kernel dimensions must be less than or equal to image")
}
if(kdim[1] != dim[1]) {
extra_rows = dim[1] - kdim[1]
if(extra_rows %% 2 == 0) {
pad = matrix(0, nrow = extra_rows/2, ncol = ncol(kernel))
} else {
pad1 = matrix(0, nrow = floor(extra_rows/2)+1, ncol = ncol(kernel))
pad2 = matrix(0, nrow = floor(extra_rows/2), ncol = ncol(kernel))
}
}
if(kdim[2] != dim[2]) {
extra_cols = dim[2] - kdim[2]
if(extra_cols %% 2 == 0) {
pad = matrix(0, nrow = nrow(kernel), ncol = extra_cols/2)
} else {
pad1 = matrix(0, nrow = nrow(kernel), ncol = floor(extra_cols/2)+1)
pad2 = matrix(0, nrow = nrow(kernel), ncol = floor(extra_cols/2))