{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-type-defaults #-}
module Language.GLSL.Runtime.Math where

import           Prelude (Float, fromIntegral, max, min, (*), (-), (.), (/),
                          (<))
import qualified Prelude

floor :: Float -> Float
floor :: Float -> Float
floor = Integer -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Float) -> (Float -> Integer) -> Float -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
Prelude.floor

fract :: Float -> Float
fract :: Float -> Float
fract Float
x = Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float -> Float
floor Float
x

mod :: Float -> Float -> Float
mod :: Float -> Float -> Float
mod Float
x Float
y = Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
y Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float -> Float
floor (Float
xFloat -> Float -> Float
forall a. Fractional a => a -> a -> a
/Float
y)

clamp :: Float -> Float -> Float -> Float
clamp :: Float -> Float -> Float -> Float
clamp Float
x Float
a = Float -> Float -> Float
forall a. Ord a => a -> a -> a
min (Float -> Float -> Float
forall a. Ord a => a -> a -> a
max Float
x Float
a)

saturate :: Float -> Float
saturate :: Float -> Float
saturate Float
x = Float -> Float -> Float -> Float
clamp Float
x Float
0 Float
1

step :: Float -> Float -> Float
step :: Float -> Float -> Float
step Float
a Float
x = if Float
x Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
< Float
a then Float
0 else Float
1

smoothstep :: Float -> Float -> Float -> Float
smoothstep :: Float -> Float -> Float -> Float
smoothstep Float
a Float
b Float
x = let t :: Float
t = Float -> Float
saturate ((Float
xFloat -> Float -> Float
forall a. Num a => a -> a -> a
-Float
a) Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ (Float
bFloat -> Float -> Float
forall a. Num a => a -> a -> a
-Float
a)) in Float
tFloat -> Float -> Float
forall a. Num a => a -> a -> a
*Float
tFloat -> Float -> Float
forall a. Num a => a -> a -> a
*(Float
3Float -> Float -> Float
forall a. Num a => a -> a -> a
-Float
2Float -> Float -> Float
forall a. Num a => a -> a -> a
*Float
t)