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.
"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
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
Positive(..),
Property,
choose)
-import Assertions (assertAlmostEqual, assertClose, assertTrue)
+import Assertions (assertAlmostEqual, assertTrue)
import Comparisons ((~=))
import Cube (Cube(Cube),
find_containing_tetrahedron,
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
module Point (
Point,
- distance,
dot,
- is_close,
scale
)
where
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