Implement combined functions

This commit is contained in:
Manuel Thalmann 2024-06-16 23:27:38 +02:00
parent 29a62ecc21
commit d017ccd848

View file

@ -41,13 +41,13 @@ unitSq = Shape $ \(x, y) ->
-}
translate :: Vector -> Shape -> Shape
translate (dx, dy) s = Shape $ \(x, y) ->
error "Fixme"
inside s (x + dx, y + dy)
{- Inverting
Inverting a shape i.e. switching outside vs inside
-}
negate :: Shape -> Shape
negate s = error "Fixme"
negate s = Shape $ \ (x, y) -> not (inside s (x, y))
{- General combinator
Combining two shapes with a parametric boolean function
@ -66,19 +66,19 @@ combineBool f s1 s2 = Shape $ \p -> f (f1 p) (f2 p)
All points that are in both shapes
-}
intersect :: Shape -> Shape -> Shape
intersect = error "Fixme"
intersect s1 s2 = Shape $ \ (x, y) -> all (\ s -> inside s (x, y)) [s1, s2]
{-
All points that in at least one of the shapes
-}
merge :: Shape -> Shape -> Shape
merge = error "Fixme"
merge s1 s2 = Shape $ \ (x, y) -> any (\ s -> inside s (x, y)) [s1, s2]
{-
All points in the first shape that are not in the secnond shape
All points in the first shape that are not in the second shape
-}
minus :: Shape -> Shape -> Shape
minus = error "Fixme"
minus s1 s2 = Shape $ \ (x, y) -> inside s1 (x, y) && not (inside s1 (x, y))
{- Matrix transformations
@ -170,4 +170,4 @@ iShape = flipX $ merge
(stretchY 2 unitSq)
(translate (0, 5) unitDisc)
disc50 = stretch 50 unitDisc
disc50 = stretch 50 unitDisc