module Geometry.Algorithms.Clipping (
cutLineWithLine
, CutLine(..)
, cutPolygon
, cohenSutherland
, LineType(..)
, clipPolygonWithLine
, clipPolygonWithLineSegment
, sutherlandHodgman
, IslandOrHole(..)
, intersectionPP
, unionPP
, differencePP
, hatch
) where
import Geometry.Algorithms.Clipping.CohenSutherland
import Geometry.Algorithms.Clipping.Internal
import Geometry.Algorithms.Clipping.MargalitKnott
(IslandOrHole (..), differencePP, intersectionPP, unionPP)
import Geometry.Algorithms.Clipping.SutherlandHodgman
import Geometry.Core
hatch
:: Polygon
-> Angle
-> Double
-> Double
-> [Line]
hatch :: Polygon -> Angle -> Double -> Double -> [Line]
hatch Polygon
polygon Angle
angle Double
interval Double
offset = do
let transformation :: Transformation
transformation = Angle -> Transformation
rotate (Angle -> Angle
forall v. VectorSpace v => v -> v
negateV Angle
angle)
polygonAligned :: Polygon
polygonAligned = Transformation -> Polygon -> Polygon
forall geo. Transform geo => Transformation -> geo -> geo
transform Transformation
transformation Polygon
polygon
BoundingBox (Vec2 Double
xLo Double
yLo) (Vec2 Double
xHi Double
yHi) = Polygon -> BoundingBox
forall a. HasBoundingBox a => a -> BoundingBox
boundingBox Polygon
polygonAligned
yMid :: Double
yMid = (Double
yLo Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
yHi) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
offset
yUp :: [Double]
yUp = (Double -> Bool) -> [Double] -> [Double]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
yHi) ((Double -> Double) -> Double -> [Double]
forall a. (a -> a) -> a -> [a]
iterate (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
interval) Double
yMid)
yDown :: [Double]
yDown = (Double -> Bool) -> [Double] -> [Double]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
yLo) ([Double] -> [Double]
forall a. HasCallStack => [a] -> [a]
tail ((Double -> Double) -> Double -> [Double]
forall a. (a -> a) -> a -> [a]
iterate (Double -> Double -> Double
forall a. Num a => a -> a -> a
subtract Double
interval) Double
yMid))
Line
horizontalScissors <- do
Double
y <- [Double]
yUp [Double] -> [Double] -> [Double]
forall a. [a] -> [a] -> [a]
++ [Double]
yDown
Line -> [Line]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vec2 -> Vec2 -> Line
Line (Double -> Double -> Vec2
Vec2 Double
xLo Double
y) (Double -> Double -> Vec2
Vec2 Double
xHi Double
y))
Line
horizontalHatches <- [Line
line | (Line
line, LineType
LineInsidePolygon) <- Polygon -> Line -> [(Line, LineType)]
clipPolygonWithLine Polygon
polygonAligned Line
horizontalScissors]
Line -> [Line]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Transformation -> Line -> Line
forall geo. Transform geo => Transformation -> geo -> geo
transform (Transformation -> Transformation
forall a. Group a => a -> a
inverse Transformation
transformation) Line
horizontalHatches)