Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a perfectly simple and practical solution (C++):</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; struct Run { int x, w; }; enum { EAST, NORTHEAST, NORTH, NORTHWEST, WEST, SOUTHWEST, SOUTH, SOUTHEAST }; int main() { const Run data[] = { { 7, 2 }, { 5, 6 }, { 5, 7 }, { 5, 7 }, { 6, 6 }, { 0, 12 }, { 0, 12 }, { 0, 11 }, { 1, 7 }, { 3, 4 }, { 3, 4 }, { 3, 5 }, { 3, 7 }, { 3, 7 }, { 5, 5 } }; std::vector&lt;Run&gt; runs(data, data + 15); std::vector&lt;int&gt; before; std::vector&lt;int&gt; after; unsigned int i; int j; for (i = 0; i &lt; runs.size() - 1; ++i) { if (runs[i].x &lt; runs[i + 1].x) { for (j = 0; j &lt; runs[i + 1].x - runs[i].x - 1; ++j) before.push_back(WEST); before.push_back(NORTHWEST); } else if (runs[i].x &gt; runs[i + 1].x) { before.push_back(NORTHEAST); for (j = 0; j &lt; runs[i].x - runs[i + 1].x - 1; ++j) before.push_back(EAST); } else { before.push_back(NORTH); } int first_right(runs[i].x + runs[i].w); int second_right(runs[i + 1].x + runs[i + 1].w); if (first_right &lt; second_right) { after.push_back(SOUTHEAST); for (j = 0; j &lt; second_right - first_right - 1; ++j) after.push_back(EAST); } else if (first_right &gt; second_right) { for (j = 0; j &lt; first_right - second_right - 1; ++j) after.push_back(WEST); after.push_back(SOUTHWEST); } else { after.push_back(SOUTH); } } for (j = 0; j &lt; runs.back().w - 1; ++j) after.push_back(WEST); std::reverse(before.begin(), before.end()); after.insert(after.end(), before.begin(), before.end()); for (j = 0; j &lt; int(after.size()); ++j) { switch (after[j]) { case EAST: std::cout &lt;&lt; "EAST\n"; break; case NORTHEAST: std::cout &lt;&lt; "NORTHEAST\n"; break; case NORTH: std::cout &lt;&lt; "NORTH\n"; break; case NORTHWEST: std::cout &lt;&lt; "NORTHWEST\n"; break; case WEST: std::cout &lt;&lt; "WEST\n"; break; case SOUTHWEST: std::cout &lt;&lt; "SOUTHWEST\n"; break; case SOUTH: std::cout &lt;&lt; "SOUTH\n"; break; case SOUTHEAST: std::cout &lt;&lt; "SOUTHEAST\n"; break; } } } </code></pre> <p>This works by iterating over the runs, testing the left and right endpoints for the direction they're jumping to, and adding the appropriate number of chain elements to two vectors: one in forward order, for the right side, and one in reverse order, for the left. It then connects the two chains by adding the appropriate number of links for the last scanline, then reverses the left side chain and appends it to the right one to produce the final chain.</p> <p>Hope this is what you're looking for!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload