Я пытаюсь изменить один элемент в двумерном массиве с aset
, но он меняет столбец.Как я могу это исправить?
Я создаю double[][]
массив:
user=> (def z-buffer
(into-array (repeat 5 (double-array 5 Double/MIN_VALUE))))
user=> (pprint z-buffer)
[[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324]]
nil
Метод, который должен изменить элемент:
user=> (defn z-buffer-check [x y z]
(let [val (double z)]
(if (> val (aget z-buffer x y))
(do
(aset z-buffer x y val)
true)
false)))
Мои действия:
user=> (z-buffer-check 2 2 6.6)
true
user=> (pprint z-buffer)
Ожидаемый результат:
[[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 6.6, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324, 4.9E-324]]
nil
Фактический результат:
[[4.9E-324, 4.9E-324, 6.6, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 6.6, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 6.6, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 6.6, 4.9E-324, 4.9E-324],
[4.9E-324, 4.9E-324, 6.6, 4.9E-324, 4.9E-324]]
nil