http://weelookang.blogspot.sg/2013/09/one-dimension-collision-js-model.html