module Graphics.Implicit.Definitions where
import Data.IORef (IORef, newIORef, readIORef)
import System.IO.Unsafe (unsafePerformIO)
import Data.VectorSpace
type ℝ = Float
type ℝ2 = (ℝ,ℝ)
type ℝ3 = (ℝ,ℝ,ℝ)
type ℕ = Int
(⋅) :: InnerSpace a => a -> a -> Scalar a
(⋅) = (<.>)
class ComponentWiseMultable a where
(⋯*) :: a -> a -> a
(⋯/) :: a -> a -> a
instance ComponentWiseMultable ℝ2 where
(x,y) ⋯* (x',y') = (x*x', y*y')
(x,y) ⋯/ (x',y') = (x/x', y/y')
instance ComponentWiseMultable ℝ3 where
(x,y,z) ⋯* (x',y',z') = (x*x', y*y', z*z')
(x,y,z) ⋯/ (x',y',z') = (x/x', y/y', z/z')
type M2 a = ((a,a),(a,a))
type M3 a = ((a,a,a),(a,a,a),(a,a,a))
type Polyline = [ℝ2]
type Triangle = (ℝ3, ℝ3, ℝ3)
type NormedTriangle = ((ℝ3, ℝ3), (ℝ3, ℝ3), (ℝ3, ℝ3))
type TriangleMesh = [Triangle]
type NormedTriangleMesh = [NormedTriangle]
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
| Mirror2 ℝ SymbolicObj2
| Outset2 ℝ SymbolicObj2
| Shell2 ℝ SymbolicObj2
| EmbedBoxedObj2 BoxedObj2
deriving Show
data SymbolicObj3 =
Rect3R ℝ ℝ3 ℝ3
| Sphere ℝ
| Cylinder ℝ ℝ ℝ
| Complement3 SymbolicObj3
| UnionR3 ℝ [SymbolicObj3]
| IntersectR3 ℝ [SymbolicObj3]
| DifferenceR3 ℝ [SymbolicObj3]
| Translate3 ℝ3 SymbolicObj3
| Scale3 ℝ3 SymbolicObj3
| Rotate3 (ℝ,ℝ,ℝ) SymbolicObj3
| Rotate3V ℝ ℝ3 SymbolicObj3
| Mirror3 (ℝ,ℝ,ℝ) SymbolicObj3
| Outset3 ℝ SymbolicObj3
| Shell3 ℝ SymbolicObj3
| EmbedBoxedObj3 BoxedObj3
| ExtrudeR ℝ SymbolicObj2 ℝ
| ExtrudeRotateR ℝ ℝ SymbolicObj2 ℝ
| ExtrudeRM
ℝ
(Maybe (ℝ -> ℝ))
(Maybe (ℝ -> ℝ))
(Maybe (ℝ -> ℝ2))
SymbolicObj2
(Either ℝ (ℝ2 -> ℝ))
| RotateExtrude
ℝ
(Maybe ℝ)
(Either ℝ2 (ℝ -> ℝ2))
(Either ℝ (ℝ -> ℝ ))
SymbolicObj2
| ExtrudeOnEdgeOf SymbolicObj2 SymbolicObj2
deriving Show
type Rectilinear2 = [Box2]
type Rectilinear3 = [Box3]
xmlErrorOn :: IORef Bool
xmlErrorOn = unsafePerformIO $ newIORef False
errorMessage :: Int -> String -> IO()
errorMessage line msg = do
useXML <- readIORef xmlErrorOn
let
msg' = "At line <line>" ++ show line ++ "</line>:" ++ msg
dropXML inQuote False ('"':xs) = '"':dropXML (not inQuote) False xs
dropXML True _ ( x :xs) = x:dropXML True False xs
dropXML False False ('<':xs) = dropXML False True xs
dropXML False True ('>':xs) = dropXML False False xs
dropXML inQuote True ( _ :xs) = dropXML inQuote True xs
dropXML inQuote False ( x :xs) = x:dropXML inQuote False xs
dropXML _ _ [] = []
putStrLn $ if useXML
then "<error>" ++ msg' ++ "</error>"
else dropXML False False msg'
return ()
instance Show (a -> b) where
show _ = "<function>"