Skip to content

Commit c34ed71

Browse files
committed
Test the signed distance relative to the normal.
1 parent cd3e74e commit c34ed71

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test/Geometry/Plane/Test.hs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE TemplateHaskell #-}
2+
{-# LANGUAGE TypeApplications #-}
23
module Geometry.Plane.Test
34
( tests
45
) where
@@ -7,15 +8,21 @@ import Geometry.Plane
78
import Hedgehog
89
import qualified Hedgehog.Gen as Gen
910
import qualified Hedgehog.Range as Range
11+
import Linear.Metric
1012
import Linear.V2
1113

1214
prop_signedDistance_identity = property $ do
1315
v <- forAll $ v2 coord
1416
n <- forAll $ v2 (nonZero coord)
1517
signedDistance v n v === 0
1618

19+
prop_signedDistance_unit = property $ do
20+
v <- forAll $ v2 coord
21+
n <- signorm <$> forAll (v2 (nonZero coord))
22+
roundToPlaces 5 (signedDistance v n (v + n)) === 1
23+
1724

18-
coord :: MonadGen m => m Rational
25+
coord :: MonadGen m => m Double
1926
coord = Gen.realFrac_ (Range.linearFracFrom 0 (-100) 100)
2027

2128
nonZero :: (MonadGen m, Num a, Eq a) => m a -> m a
@@ -27,3 +34,9 @@ v2 g = V2 <$> g <*> g
2734

2835
tests :: IO Bool
2936
tests = checkParallel $$(discover)
37+
38+
39+
roundToPlaces :: RealFrac a => Int -> a -> a
40+
roundToPlaces p x = fromInteger (round (x * p')) / p'
41+
where
42+
p' = 10 ^ p

0 commit comments

Comments
 (0)