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.Internal

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.

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.

|

Synopsis

Documentation

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

newtype ShadowModel Source

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

Constructors

ShadowModel 

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

showWorld :: World -> String Source

PRetty Print the World into a String

newtype 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

Constructors

World 

(!?) :: World -> (Int, Int) -> Maybe Bool Source

Read Value directly from World

emptyWorld :: Int -> Int -> World Source

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

data Patchable Source

overlapping if any bit is 1 inff both worlds, an intersection is reported as true

Constructors

Patchable 

Fields

_ix :: !Int
 
_iy :: !Int
 
_shadow :: ShadowModel
 
_world :: World
 

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

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

trueIdx :: (Int, Int) Source

return True index in twobitArray

falseIdx :: (Int, Int) Source

return False index in twobitArray

twobitArray :: BitArray (Int, Int) Source

The index mapping in bit array makes fora common pattern to convert from one array into another using an intermediate structure and exploiting the fact that each array can only be True or false. ixmap can be used to project one array onto another.