From 68b7d1002448a896236050caceb4f38463b996f4 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 1 May 2011 12:02:28 -0400 Subject: [PATCH] Fix the definition of cube_at; it had the 'x' and 'z' axes flipped. --- src/Cube.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Cube.hs b/src/Cube.hs index d741f49..3011281 100644 --- a/src/Cube.hs +++ b/src/Cube.hs @@ -38,8 +38,7 @@ instance Show Cube where empty_cube :: Cube empty_cube = Cube empty_grid 0 0 0 0 --- TODO: The paper considers 'i' to be the front/back direction, --- whereas I have it in the left/right direction. + instance Gridded Cube where back c = cube_at (grid c) ((i c) + 1) (j c) (k c) down c = cube_at (grid c) (i c) (j c) ((k c) - 1) @@ -146,11 +145,14 @@ instance Fractional Cube where fromRational q = empty_cube { datum = fromRational q } --- | Constructs a cube, switching the i and k axes. +-- | Constructs a cube, switching the x and z axes. reverse_cube :: Grid -> Int -> Int -> Int -> Double -> Cube reverse_cube g k' j' i' = Cube g i' j' k' +-- | Return the cube corresponding to the grid point i,j,k. The list +-- of cubes is stored as [z][y][x] but we'll be requesting it by +-- [x][y][z] so we flip the indices in the last line. cube_at :: Grid -> Int -> Int -> Int -> Cube cube_at g i' j' k' | i' >= length (function_values g) = Cube g i' j' k' 0 @@ -160,7 +162,8 @@ cube_at g i' j' k' | k' >= length (((function_values g) !! i') !! j') = Cube g i' j' k' 0 | k' < 0 = Cube g i' j' k' 0 | otherwise = - Cube g i' j' k' ((((function_values g) !! i') !! j') !! k') + (((cubes g) !! k') !! j') !! i' + -- These next three functions basically form a 'for' loop, looping -- through the xs, ys, and zs in that order. -- 2.43.2