[英]Numeric matrix tiles in Haskell
具有数字矩阵,如何使用Haskell从中提取图块?
例:
Int -> Int -> Int -> Int -> [Int] -> Int -> Int -> [Int]
getTile height width x y xs matrix_height matrix_width = ...
getTile 2 2 1 1 [1,2,3,4,5,
6,7,8,9,10] 2 5 = [2,3
7,8]
您可能需要使用床和早餐包中的Numeric.Matrix 。 它效率更高,并且具有构造子矩阵的好方法(固定,选择不合适)。
getTile height width x y m = matrix getElem (height,width) where
getElem (i,j) = m `at` (i+x-1, j+y-1)
Numeric.Matrix使用基于1的索引,因此可能会使事情复杂一些。
import Data.Matrix
let flat_matrix=[1,2,3,4,5,6,7,8,9,10]
let mat = Data.Matrix.fromList width height flat_matrix
let tile = submatrix start_row end_row start_column end_column mat
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.