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.
Just what it sounds like. For fifteen days, I will make a D3.js v4 block every single day. Rules:
https://d3js.org/d3.v4.min.js