coursera-parallel-programming-scala icon indicating copy to clipboard operation
coursera-parallel-programming-scala copied to clipboard

Error in `Fork.insert`

Open xiongtx opened this issue 8 years ago • 0 comments

I believe there is an error in the insert method of the Fork class. The insertions into quadrants appear to be wrong:

def insert(b: Body): Fork = {
  if (b.x < centerX && b.y < centerY) Fork(nw.insert(b), ne, sw, se)
  else if (b.x < centerX && b.y >= centerY) Fork(nw, ne.insert(b), sw, se)
  else if (b.x >= centerX && b.y < centerY) Fork(nw, ne, sw.insert(b), se)
  else Fork(nw, ne, sw, se.insert(b))
}

In particular, b.x < centerX && b.y >= centerY should correspond to sw, not ne. Similarly, b.x >= centerX && b.y < centerY should correspond to ne, not sw.

xiongtx avatar Sep 12 '16 06:09 xiongtx