block by cmgiven 547658968d365bcc324f3e62e175709b

Rectangular Collision Detection

Full Screen

Block-a-Day #8. Adapts the core library’s forceCollide force to work with rectangles instead of circles. Note that collide.radius([radius_]) is replaced with _collide.size([_size_]), which should return an array in the format [width, height].

Nate Bates’s block provided a useful reference. The bounding force was created for yesterday’s block (although note the addition of checks on lines 182-183 and 188-189, which prevent a rectangle from getting trapped out of bounds).

What I Learned: I now have at least some sense for what every line of forceCollide is doing. Whether I understand it all, well, that’s another matter.

What I’d Do With More Time: There’s at least one bug that can fail to detect the overlap of two rectangles, causing them to eventually rebound with too much force. I went back and realized where the problem was, cleaning up some other stuff too.

Block-a-Day

Just what it sounds like. For fifteen days, I will make a D3.js v4 block every single day. Rules:

  1. Ideas over implementation. Do something novel, don’t sweat the details.
  2. No more than two hours can be spent on coding (give or take).
  3. Every. Single. Day.

Previously

index.html