module Graphics.Implicit.Export.SymbolicObj2 (symbolicGetContour) where
import Prelude((==), pure, fmap, ($), (/), (+), (*), cos, pi, sin, max, ceiling)
import Graphics.Implicit.Definitions (objectRounding, ObjectContext, ℝ, ℝ2, Fastℕ, SymbolicObj2(Square, Circle, Shared2), SharedObj(Translate, Scale, WithRounding), Polyline(Polyline), (⋯*), fromFastℕtoℝ)
import Linear ( V2(V2) )
import Graphics.Implicit.Export.Render (getContour)
symbolicGetContour :: ℝ -> ObjectContext -> SymbolicObj2 -> [Polyline]
symbolicGetContour :: ℝ -> ObjectContext -> SymbolicObj2 -> [Polyline]
symbolicGetContour ℝ
_ ObjectContext
ctx (Square (V2 ℝ
dx ℝ
dy))
| ObjectContext -> ℝ
objectRounding ObjectContext
ctx ℝ -> ℝ -> Bool
forall a. Eq a => a -> a -> Bool
== ℝ
0 = [[V2 ℝ] -> Polyline
Polyline [ℝ -> ℝ -> V2 ℝ
forall a. a -> a -> V2 a
V2 ℝ
0 ℝ
0, ℝ -> ℝ -> V2 ℝ
forall a. a -> a -> V2 a
V2 ℝ
dx ℝ
0, ℝ -> ℝ -> V2 ℝ
forall a. a -> a -> V2 a
V2 ℝ
dx ℝ
dy, ℝ -> ℝ -> V2 ℝ
forall a. a -> a -> V2 a
V2 ℝ
0 ℝ
dy, ℝ -> ℝ -> V2 ℝ
forall a. a -> a -> V2 a
V2 ℝ
0 ℝ
0]]
symbolicGetContour ℝ
res ObjectContext
_ (Circle ℝ
r) =
[ [V2 ℝ] -> Polyline
Polyline
[ ℝ -> ℝ -> V2 ℝ
forall a. a -> a -> V2 a
V2 (ℝ
rℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*ℝ -> ℝ
forall a. Floating a => a -> a
cos(ℝ
2ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*ℝ
forall a. Floating a => a
piℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*Fastℕ -> ℝ
fromFastℕtoℝ Fastℕ
mℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/Fastℕ -> ℝ
fromFastℕtoℝ Fastℕ
n)) (ℝ
rℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*ℝ -> ℝ
forall a. Floating a => a -> a
sin(ℝ
2ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*ℝ
forall a. Floating a => a
piℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*Fastℕ -> ℝ
fromFastℕtoℝ Fastℕ
mℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/Fastℕ -> ℝ
fromFastℕtoℝ Fastℕ
n))
| Fastℕ
m <- [Fastℕ
0.. Fastℕ
n]
]
]
where
n :: Fastℕ
n :: Fastℕ
n = Fastℕ -> Fastℕ -> Fastℕ
forall a. Ord a => a -> a -> a
max Fastℕ
5 (Fastℕ -> Fastℕ) -> Fastℕ -> Fastℕ
forall a b. (a -> b) -> a -> b
$ ℝ -> Fastℕ
forall a b. (RealFrac a, Integral b) => a -> b
ceiling (ℝ -> Fastℕ) -> ℝ -> Fastℕ
forall a b. (a -> b) -> a -> b
$ ℝ
2ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*ℝ
forall a. Floating a => a
piℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*ℝ
rℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/ℝ
res
symbolicGetContour ℝ
res ObjectContext
ctx (Shared2 (WithRounding ℝ
r SymbolicObj2
obj)) = ℝ -> ObjectContext -> SymbolicObj2 -> [Polyline]
symbolicGetContour ℝ
res (ObjectContext
ctx { objectRounding :: ℝ
objectRounding = ℝ
r }) SymbolicObj2
obj
symbolicGetContour ℝ
res ObjectContext
ctx (Shared2 (Translate V2 ℝ
v SymbolicObj2
obj)) = (V2 ℝ -> V2 ℝ) -> [Polyline] -> [Polyline]
appOpPolylines (V2 ℝ -> V2 ℝ -> V2 ℝ
forall a. Num a => a -> a -> a
+ V2 ℝ
v) ([Polyline] -> [Polyline]) -> [Polyline] -> [Polyline]
forall a b. (a -> b) -> a -> b
$ ℝ -> ObjectContext -> SymbolicObj2 -> [Polyline]
symbolicGetContour ℝ
res ObjectContext
ctx SymbolicObj2
obj
symbolicGetContour ℝ
res ObjectContext
ctx (Shared2 (Scale s :: V2 ℝ
s@(V2 ℝ
a ℝ
b) SymbolicObj2
obj)) = (V2 ℝ -> V2 ℝ) -> [Polyline] -> [Polyline]
appOpPolylines (V2 ℝ -> V2 ℝ -> V2 ℝ
forall a. ComponentWiseMultable a => a -> a -> a
⋯* V2 ℝ
s) ([Polyline] -> [Polyline]) -> [Polyline] -> [Polyline]
forall a b. (a -> b) -> a -> b
$ ℝ -> ObjectContext -> SymbolicObj2 -> [Polyline]
symbolicGetContour (ℝ
resℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/ℝ
sc) ObjectContext
ctx SymbolicObj2
obj
where sc :: ℝ
sc = ℝ -> ℝ -> ℝ
forall a. Ord a => a -> a -> a
max ℝ
a ℝ
b
symbolicGetContour ℝ
res ObjectContext
_ SymbolicObj2
obj = V2 ℝ -> SymbolicObj2 -> [Polyline]
getContour (ℝ -> V2 ℝ
forall (f :: * -> *) a. Applicative f => a -> f a
pure ℝ
res) SymbolicObj2
obj
appOpPolylines :: (ℝ2 -> ℝ2) -> [Polyline] -> [Polyline]
appOpPolylines :: (V2 ℝ -> V2 ℝ) -> [Polyline] -> [Polyline]
appOpPolylines V2 ℝ -> V2 ℝ
op = (Polyline -> Polyline) -> [Polyline] -> [Polyline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((V2 ℝ -> V2 ℝ) -> Polyline -> Polyline
appOpPolyline V2 ℝ -> V2 ℝ
op)
appOpPolyline :: (ℝ2 -> ℝ2) -> Polyline -> Polyline
appOpPolyline :: (V2 ℝ -> V2 ℝ) -> Polyline -> Polyline
appOpPolyline V2 ℝ -> V2 ℝ
op (Polyline [V2 ℝ]
xs) = [V2 ℝ] -> Polyline
Polyline ([V2 ℝ] -> Polyline) -> [V2 ℝ] -> Polyline
forall a b. (a -> b) -> a -> b
$ (V2 ℝ -> V2 ℝ) -> [V2 ℝ] -> [V2 ℝ]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap V2 ℝ -> V2 ℝ
op [V2 ℝ]
xs