Skip to content
Snippets Groups Projects
Select Git revision
  • c74aceba660f587086f932240ec69932b62b44e0
  • develop default protected
  • ical-export
  • feature/audit_log
  • fix/index
  • badge-redeem-404
  • 720-schedule_source
  • room-docu
  • chore/event-views
  • 511-schedule-foo-fixed
  • 607-schedule-versions
  • deploy/curl-verbose
  • fix/public-badge-access-rights
  • 445-schedule-redirects
  • 623-wiki-im-baustellenmodus-sollte-mal-als-wiki-admin-trotzdem-seiten-anlegen-bearbeiten-konnen
  • fix/registration_mail_subject
  • feature/conference-query-set
  • feature/568-habitatmanagement
  • feat/unit-integration-tests
  • camp23-prod
  • production
  • prod-2024-12-27_20-15
  • prod-2024-12-27_16-37
  • prod-2024-12-27_16-01
  • prod-2024-12-27_13-29
  • prod-2024-12-27_00-34
  • prod-2024-12-26_21-45
  • prod-2024-12-26_13-12
  • prod-2024-12-26_00-21
  • prod-2024-12-25_21-04
  • prod-2024-12-25_15-54
  • prod-2024-12-25_01-29
  • prod-2024-12-24_14-48
  • prod-2024-12-23_23-39
  • prod-2024-12-22_21-12
  • prod-2024-12-22_17-25
  • prod-2024-12-22_01-34
  • prod-2024-12-22_00-55
  • prod-2024-12-21_13-42
  • prod-2024-12-21_10-44
  • prod-2024-12-20_12-25
41 results

map.py

Blame
  • Forked from hub / hub
    Source project has a limited visibility.
    LayerData.hs 1.59 KiB
    {-# LANGUAGE OverloadedStrings #-}
    
    module LayerData where
    
    
    import           Control.Monad.Zip (mzipWith)
    import           Data.Set          (Set, insert)
    import           Data.Text         (Text)
    import qualified Data.Text         as T
    import           Data.Vector       (Vector, uncons)
    import           Tiled             (GlobalId (unGlobalId), Layer (..))
    import           Util              (PrettyPrint (..))
    
    -- | A collision between two layers of the given names.
    -- Wrapped in a newtype so that Eq can ignore the order of the two
    newtype Collision = Collision { fromCollision ::  (Text, Text) }
      deriving Ord
    
    instance Eq Collision where
      (Collision (a,b)) == (Collision (a',b')) = ((a,b) == (a',b')) || ((a,b) == (b',a'))
    
    instance PrettyPrint Collision where
      prettyprint (Collision (a,b)) = a <> " and " <> b
    
    instance Show Collision where
      show c = T.unpack $ prettyprint c
    
    -- | Finds pairwise tile collisions between the given layers.
    layerOverlaps :: Vector Layer -> Set Collision
    layerOverlaps layers = case uncons layers of
      Nothing -> mempty
      Just (l, ls) ->
       fst . foldr overlapBetween (mempty, l) $ ls
       where overlapBetween :: Layer -> (Set Collision, Layer) -> (Set Collision, Layer)
             overlapBetween layer (acc, oldlayer) =
              (if collides then insert collision acc else acc, layer)
              where
               collision = Collision (layerName layer, layerName oldlayer)
               collides = case (layerData layer, layerData oldlayer) of
                 (Just d1, Just d2) ->
                   0 /= maximum (mzipWith (\a b -> unGlobalId a * unGlobalId b) d1 d2)
                 _ -> False