shadow-box-model-0.1.0: 2D Bit array, with binary image collission detection

CopyrightPlow Technologies LLC
LicenseMIT License
MaintainerScott Murphy
Safe HaskellNone
LanguageHaskell2010

Data.ShadowBox

Description

Normal collision detection proceeds by checking one model against another, one at a time.

If you are dealing with a discretized grid you can simulataneously check collissions against all models simultaneously by projecting your models into a Binary grid. Then by looking for an empty intersection set, collissions are avoided and a new world is returned.

Algorithmic complexity is determined by the grid size only. A Grid can be stored in (GridSize/8) Bytes

the theory is to create a Shadow model, that is a rectangular projection into bits.

Then you position that projection onto a World, which is a 2d bit array.

you can do this all in 1 step with

>>> either (fail) (putStrLn. showWorld) $ addModelToWorld 7 7 (shadowRect 3 3) (emptyWorld 10 10)
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  X  X  X 
 _  _  _  _  _  _  _  X  X  X 
 _  _  _  _  _  _  _  X  X  X 
>>> let (Right world1) = addModelToWorld 7 7 (shadowRect 3 3) (emptyWorld 10 10)
>>> let (Right world2) = addModelToWorld 1 1 (shadowRect 3 3) world1
>>> putStrLn . showWorld $ world2
 _  _  _  _  _  _  _  _  _  _ 
 _  X  X  X  _  _  _  _  _  _ 
 _  X  X  X  _  _  _  _  _  _ 
 _  X  X  X  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  _  _  _ 
 _  _  _  _  _  _  _  X  X  X 
 _  _  _  _  _  _  _  X  X  X 
 _  _  _  _  _  _  _  X  X  X 

The interfaces presented here have smart constructors and try to keep you safe.. however, you can go to the internal package which is exposed if you want to violate the model assumptions, you bad person you

|

Synopsis

Documentation

makePatchable :: Int -> Int -> ShadowModel -> World -> Either String Patchable Source

Make a patchable world, grouping world and model together This runs all the boundary tests so that patches can be applied quickly

emptyWorld :: Int -> Int -> World Source

Build a world with no shadows The width and height are in pixel length

addPatchToWorld :: Patchable -> World Source

place a shadow model at a given position, assumes the model is represented in a square matrix the matrix that is projected is actually just [0,1], it uses it as an intermediate while reading values out of sm. This allows us to control a true or false value without having to convert to a list

addModelToWorld :: Int -> Int -> ShadowModel -> World -> Either String World Source

Primary use Function addModelToWorld can be used with a model to create a world that can have more models consistently added to it

showWorld :: World -> String Source

PRetty Print the World into a String

showShadowBoxModel :: ShadowModel -> String Source

Pretty Print a ShadowBox

shadowRect :: Int -> Int -> ShadowModel Source

Build a rectangle shadow of a given width and height Enter the width and height in bits

newtype ShadowModel Source

Shadow Models are the shapes that are inserted into a world at an origin

Constructors

ShadowModel 

data World Source

World shadows are either created empty or are built up by inserting shadows into them. They are correct by construction because these are the only way to build them