From f7fca3fce3d7cbb13cdb2409faff1e7490f74bc1 Mon Sep 17 00:00:00 2001 From: Jack Wines Date: Wed, 26 Jun 2024 12:21:28 -0400 Subject: [PATCH] voronoi spelling fix --- src/Main.hs | 12 ++++++------ src/Triangles.hs | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 5d97b28..3b2bf8c 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -54,8 +54,8 @@ genImage image dimensionsVec minDistance gen = . reflectY . rectEnvelope (mkP2 0 0) (1 ^& 1) . mconcat - . map ((\x -> drawVoroniRegion x <> overlayEdges x) . uncurry Tri.voroniDiagramCorners) - $ voroni + . map ((\x -> drawVoronoiRegion x <> overlayEdges x) . uncurry Tri.voronoiDiagramCorners) + $ voronoi where overlayEdges = lw (local 0.001) @@ -63,9 +63,9 @@ genImage image dimensionsVec minDistance gen = . strokeLocLoop . fromVertices - drawVoroniRegion shape = + drawVoronoiRegion shape = lw 0 - . fillColor (Tri.voroniRegionAverageColor image dimensions shape) + . fillColor (Tri.voronoiRegionAverageColor image dimensions shape) . strokeLocLoop . fromVertices $ shape @@ -76,9 +76,9 @@ genImage image dimensionsVec minDistance gen = dimensions :: (Int, Int) dimensions = (ceiling $ dimensionsVec ^. _x, ceiling $ dimensionsVec ^. _y) - singleVoroni = last voroni + singleVoronoi = last voronoi - voroni = map (\x -> (x, Tri.nClosestPoints 20 x corners')) corners' + voronoi = map (\x -> (x, Tri.nClosestPoints 20 x corners')) corners' averageSideSize = (fromIntegral (uncurry (+) dimensions)) / 2 diff --git a/src/Triangles.hs b/src/Triangles.hs index c606af0..f8b21e9 100644 --- a/src/Triangles.hs +++ b/src/Triangles.hs @@ -87,8 +87,8 @@ withinShape pointInShape verticies candidate = all ((< quarterTurn) . fmap abs . sortOnAngle center = sortOn (normalizeAngle . signedAngleBetweenDirs xDir . dirBetween center) -voroniDiagramCorners :: (RealFloat n) => Point V2 n -> [Point V2 n] -> [Point V2 n] -voroniDiagramCorners center midpoints = +voronoiDiagramCorners :: (RealFloat n) => Point V2 n -> [Point V2 n] -> [Point V2 n] +voronoiDiagramCorners center midpoints = sortOnAngle center . filter isValidMidpoint . concat @@ -155,8 +155,8 @@ nClosestPoints n p = . takeSortOn n (abs . distanceA p) . filter (/= p) -findVoroniDiagram :: (RealFloat n) => [(Point V2 n, Point V2 n)] -> [(Point V2 n, [Point V2 n])] -findVoroniDiagram = +findVoronoiDiagram :: (RealFloat n) => [(Point V2 n, Point V2 n)] -> [(Point V2 n, [Point V2 n])] +findVoronoiDiagram = M.toList . M.mapWithKey ( \key -> @@ -204,8 +204,8 @@ blendEqually colors = C.affineCombo (map (fraction,) colors) C.white where fraction = 1.0 / (fromIntegral . length $ colors) -voroniRegionAverageColor :: (Integral a, Integral b) => Ma.Image Ma.S (Co.SRGB 'Co.Linear) Double -> (a, b) -> [P2 Double] -> Colour Double -voroniRegionAverageColor image (x', y') = +voronoiRegionAverageColor :: (Integral a, Integral b) => Ma.Image Ma.S (Co.SRGB 'Co.Linear) Double -> (a, b) -> [P2 Double] -> Colour Double +voronoiRegionAverageColor image (x', y') = blendEqually . concatMap (getColorsInTriangle image (x', y')) . filter ((== 3) . S.size)