{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
module Graphics.Implicit.Definitions (
module F,
module N,
ℝ,
ℝ2,
both,
ℝ3,
allthree,
minℝ,
(⋅),
(⋯*),
(⋯/),
Polyline(Polyline),
Polytri(Polytri),
Triangle(Triangle),
NormedTriangle(NormedTriangle),
TriangleMesh(TriangleMesh),
NormedTriangleMesh(NormedTriangleMesh),
Obj2,
Obj3,
Box2,
Box3,
Boxed2,
Boxed3,
BoxedObj2,
BoxedObj3,
SymbolicObj2(
RectR,
Circle,
PolygonR,
Complement2,
UnionR2,
DifferenceR2,
IntersectR2,
Translate2,
Scale2,
Rotate2,
Shell2,
Outset2,
EmbedBoxedObj2),
SymbolicObj3(
Rect3R,
Sphere,
Cylinder,
Complement3,
UnionR3,
IntersectR3,
DifferenceR3,
Translate3,
Scale3,
Rotate3,
Rotate3V,
Shell3,
Outset3,
EmbedBoxedObj3,
ExtrudeR,
ExtrudeRotateR,
ExtrudeRM,
ExtrudeOnEdgeOf,
RotateExtrude),
fromℕtoℝ,
fromFastℕtoℝ,
fromℝtoFloat
)
where
import Prelude (Show, Double, Either, show, (*), (/), fromIntegral, Float, realToFrac)
import Data.Maybe (Maybe)
import Data.VectorSpace (Scalar, InnerSpace, (<.>))
import Graphics.Implicit.FastIntUtil as F (Fastℕ(Fastℕ), fromFastℕ, toFastℕ)
import Graphics.Implicit.IntegralUtil as N (ℕ, fromℕ, toℕ)
import Control.DeepSeq (NFData, rnf)
type ℝ = Double
type ℝ2 = (ℝ,ℝ)
type ℝ3 = (ℝ,ℝ,ℝ)
minℝ :: ℝ
minℝ = 0.0000000000000002
both :: (t -> b) -> (t, t) -> (b, b)
both f (x,y) = (f x, f y)
{-# INLINABLE both #-}
allthree :: (t -> b) -> (t, t, t) -> (b, b, b)
allthree f (x,y,z) = (f x, f y, f z)
{-# INLINABLE allthree #-}
(⋅) :: InnerSpace a => a -> a -> Scalar a
(⋅) = (<.>)
{-# INLINABLE (⋅) #-}
fromℕtoℝ :: ℕ -> ℝ
fromℕtoℝ = fromIntegral
{-# INLINABLE fromℕtoℝ #-}
fromFastℕtoℝ :: Fastℕ -> ℝ
fromFastℕtoℝ (Fastℕ a) = fromIntegral a
{-# INLINABLE fromFastℕtoℝ #-}
fromℝtoFloat :: ℝ -> Float
fromℝtoFloat = realToFrac
{-# INLINABLE fromℝtoFloat #-}
instance Show (ℝ -> ℝ) where
show _ = "<function ℝ>"
instance Show (ℝ -> ℝ2) where
show _ = "<expand ℝ -> ℝ2>"
instance Show (ℝ2 -> ℝ) where
show _ = "<collapse ℝ2 -> ℝ>"
instance Show (ℝ3 -> ℝ) where
show _ = "<collapse ℝ3 -> ℝ>"
class ComponentWiseMultable a where
(⋯*) :: a -> a -> a
(⋯/) :: a -> a -> a
instance ComponentWiseMultable ℝ2 where
(x,y) ⋯* (x',y') = (x*x', y*y')
{-# INLINABLE (⋯*) #-}
(x,y) ⋯/ (x',y') = (x/x', y/y')
{-# INLINABLE (⋯/) #-}
instance ComponentWiseMultable ℝ3 where
(x,y,z) ⋯* (x',y',z') = (x*x', y*y', z*z')
{-# INLINABLE (⋯*) #-}
(x,y,z) ⋯/ (x',y',z') = (x/x', y/y', z/z')
{-# INLINABLE (⋯/) #-}
newtype Polyline = Polyline [ℝ2]
newtype Polytri = Polytri (ℝ2, ℝ2, ℝ2)
newtype Triangle = Triangle (ℝ3, ℝ3, ℝ3)
newtype NormedTriangle = NormedTriangle ((ℝ3, ℝ3), (ℝ3, ℝ3), (ℝ3, ℝ3))
newtype TriangleMesh = TriangleMesh [Triangle]
newtype NormedTriangleMesh = NormedTriangleMesh [NormedTriangle]
instance NFData Triangle where
rnf (Triangle (a,b,c)) = rnf (a,b,c)
instance NFData TriangleMesh where
rnf (TriangleMesh xs) = rnf xs
instance NFData Polytri where
rnf (Polytri (a,b,c)) = rnf (a,b,c)
instance NFData Polyline where
rnf (Polyline xs) = rnf xs
type Obj2 = (ℝ2 -> ℝ)
type Obj3 = (ℝ3 -> ℝ)
type Box2 = (ℝ2, ℝ2)
type Box3 = (ℝ3, ℝ3)
type Boxed2 a = (a, Box2)
type Boxed3 a = (a, Box3)
type BoxedObj2 = Boxed2 Obj2
type BoxedObj3 = Boxed3 Obj3
data SymbolicObj2 =
RectR ℝ ℝ2 ℝ2
| Circle ℝ
| PolygonR ℝ [ℝ2]
| Complement2 SymbolicObj2
| UnionR2 ℝ [SymbolicObj2]
| DifferenceR2 ℝ [SymbolicObj2]
| IntersectR2 ℝ [SymbolicObj2]
| Translate2 ℝ2 SymbolicObj2
| Scale2 ℝ2 SymbolicObj2
| Rotate2 ℝ SymbolicObj2
| Outset2 ℝ SymbolicObj2
| Shell2 ℝ SymbolicObj2
| EmbedBoxedObj2 BoxedObj2
deriving Show
data SymbolicObj3 =
Rect3R ℝ ℝ3 ℝ3
| Sphere ℝ
| Cylinder ℝ ℝ ℝ
| Complement3 SymbolicObj3
| UnionR3 ℝ [SymbolicObj3]
| DifferenceR3 ℝ [SymbolicObj3]
| IntersectR3 ℝ [SymbolicObj3]
| Translate3 ℝ3 SymbolicObj3
| Scale3 ℝ3 SymbolicObj3
| Rotate3 ℝ3 SymbolicObj3
| Rotate3V ℝ ℝ3 SymbolicObj3
| Outset3 ℝ SymbolicObj3
| Shell3 ℝ SymbolicObj3
| EmbedBoxedObj3 BoxedObj3
| ExtrudeR ℝ SymbolicObj2 ℝ
| ExtrudeRotateR ℝ ℝ SymbolicObj2 ℝ
| ExtrudeRM
ℝ
(Either ℝ (ℝ -> ℝ))
(Either ℝ (ℝ -> ℝ))
(Either ℝ2 (ℝ -> ℝ2))
SymbolicObj2
(Either ℝ (ℝ2 -> ℝ))
| RotateExtrude
ℝ
(Maybe ℝ)
(Either ℝ2 (ℝ -> ℝ2))
(Either ℝ (ℝ -> ℝ ))
SymbolicObj2
| ExtrudeOnEdgeOf SymbolicObj2 SymbolicObj2
deriving Show