From 610d0f0af8a802c26d51231d6e2426a72e40fd2d Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 25 Oct 2011 17:25:17 -0400 Subject: [PATCH] Remove the Point.distance function and associated assertion. We only need the dot product. --- src/Assertions.hs | 10 +--------- src/Cube.hs | 5 +++-- src/Grid.hs | 4 ++-- src/Point.hs | 14 -------------- 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/Assertions.hs b/src/Assertions.hs index b2ec7c1..4e09b82 100644 --- a/src/Assertions.hs +++ b/src/Assertions.hs @@ -10,7 +10,7 @@ import Test.HUnit (Assertion, assertFailure) import Comparisons ((~=)) -import Point (Point, is_close) + -- | An HUnit assertion that wraps the almost_equals function. Stolen -- from the definition of 'assertEqual' in Test\/HUnit\/Base.hs. @@ -21,14 +21,6 @@ assertAlmostEqual preface expected actual = "expected: " ++ show expected ++ "\n but got: " ++ show actual --- | An HUnit assertion that wraps the is_close function. Stolen --- from the definition of 'assertEqual' in Test\/HUnit\/Base.hs. -assertClose :: String -> Point -> Point -> Assertion -assertClose preface expected actual = - unless (actual `is_close` expected) (assertFailure msg) - where msg = (if null preface then "" else preface ++ "\n") ++ - "expected: " ++ show expected ++ "\n but got: " ++ show actual - -- | It's asinine that this doesn't exist already. assertTrue :: String -> Bool -> Assertion diff --git a/src/Cube.hs b/src/Cube.hs index 32b4b65..1c654ff 100644 --- a/src/Cube.hs +++ b/src/Cube.hs @@ -655,8 +655,9 @@ find_containing_tetrahedron cube p = else back_right_down_tetrahedra cube - -- Use the dot product instead of 'distance' here to save a - -- sqrt(). So, "distances" below really means "distances squared." + -- Use the dot product instead of Euclidean distance here to save + -- a sqrt(). So, "distances" below really means "distances + -- squared." distances = V.map ((dot p) . center) candidates shortest_distance = V.minimum distances lucky_idx = V.findIndex diff --git a/src/Grid.hs b/src/Grid.hs index 71e39a0..d5553b4 100644 --- a/src/Grid.hs +++ b/src/Grid.hs @@ -22,7 +22,7 @@ import Test.QuickCheck ((==>), Positive(..), Property, choose) -import Assertions (assertAlmostEqual, assertClose, assertTrue) +import Assertions (assertAlmostEqual, assertTrue) import Comparisons ((~=)) import Cube (Cube(Cube), find_containing_tetrahedron, @@ -282,7 +282,7 @@ trilinear_c0_t0_tests = test_trilinear_f0_t0_v3 :: Assertion test_trilinear_f0_t0_v3 = - assertClose "v3 is correct" (v3 t) (0.5, 1.5, 1.5) + assertEqual "v3 is correct" (v3 t) (0.5, 1.5, 1.5) test_trilinear_reproduced :: Assertion diff --git a/src/Point.hs b/src/Point.hs index 4b9eaec..49ad534 100644 --- a/src/Point.hs +++ b/src/Point.hs @@ -2,9 +2,7 @@ module Point ( Point, - distance, dot, - is_close, scale ) where @@ -28,19 +26,7 @@ scale :: Point -> Double -> Point scale (x, y, z) d = (x*d, y*d, z*d) --- | Returns the distance between p1 and p2. -distance :: Point -> Point -> Double -distance p1 p2 = - sqrt $ p1 `dot` p2 - - -- | Returns the dot product of two points (taken as three-vectors). dot :: Point -> Point -> Double dot (x1, y1, z1) (x2, y2, z2) = (x2 - x1)^(2::Int) + (y2 - y1)^(2::Int) + (z2 - z1)^(2::Int) - - --- | Returns 'True' if p1 is close to (within 'epsilon' of) p2, --- 'False' otherwise. -is_close :: Point -> Point -> Bool -is_close p1 p2 = (distance p1 p2) ~= 0 -- 2.44.2