packages feed

geomancy-0.4.0.0: test/Spec/Point.hs

{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}

module Spec.Point (tests) where

import Geomancy
import Hedgehog
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.Hedgehog (testPropertyNamed)

import Geomancy.Point qualified

tests :: TestTree
tests = testGroup "Point"
  [ testPropertyNamed "dpoint" "prop_dpoint" prop_dpoint
  ]

prop_dpoint :: Property
prop_dpoint = withTests 1 $ property do
  let
    far = 1e9
    a = Point (dvec3 far 0 0) :: DPoint3
    b = Point (dvec3 (far + 0.5) 0 0)
  0.5 === Geomancy.Point.distance a b
  b === a .+^ dvec3 0.5 0 0
  dvec3 0.5 0 0 === b .-. a
  Point (dvec3 (far + 0.25) 0 0) === Geomancy.Point.lerp a b 0.5

  5 === Geomancy.Point.distance (Point (vec3 0 0 0)) (Point (vec3 3 4 0))