Hacker News new | ask | show | jobs
by dsp1234 4196 days ago
This additional twist makes the original statement of:

without the need for backtracking or bookkeeping

appear to be misleading. You have to do some bookkeeping in order to know if the wall that your line just hit is connected to the start point, or any midpoint of the line you are drawing. The complexity is just hidden behind simpler words (They may only cross some other line at most once.).

Also, I'm not sure how the backtracking is missing. Once you've hit a new wall with your line, and check connectivity, if it's actually connected, then you have to backtrack that line until it's back to a place where it's no longer connected. Connectivity could be checked right before hitting a wall, but then it's just backtracking by another name. So I'm really not understanding how this would be implemented in an simpler and/or faster way.

1 comments

I'm coming around to your way of thinking.

If you have a way to draw a wall (twisty line) that doesn't intersect with any other wall, then it's trivial. Just draw a new wall optionally anchored on a wall. The line crossing bookkeeping seems annoying. If i had to do something right now, i'd use a bitmap of cells to indicate the presence or absence of a wall. Can't set a bit with more than 1 adjacent (north/south/east/west) bit set.

Can't set a bit with more than 1 adjacent (north/south/east/west) bit set.

Then you couldn't make a T (or + intersection) because as the newly incoming line was about to attach to the existing wall (regardless of any other connectivity), the final "bit" that would attach to the line and existing wall would have 2 adjacent bits set. ex: assuming a wall that travels east/west, and a line coming from the south northwards, when drawing the last pixel of the line before it attaches to the wall, the test would fail. The "south" bit would be set because that bit was set just one step prior, and the "north" bit would be set because that's where the wall is.

  ---------
      x   
      |
      |
Can't set "x" because there is more than one "adjacent" bit set (north and south).