private void SetCrossings(VoxelStencil stencil, int xStart, int xEnd, int yStart, int yEnd) { bool crossHorizontalGap = false; bool lastVerticalRow = false; bool crossVerticalGap = false; if (xStart > 0) { xStart -= 1; } if (xEnd == resolution - 1) { xEnd -= 1; crossHorizontalGap = xNeighbor != null; } if (yStart > 0) { yStart -= 1; } if (yEnd == resolution - 1) { yEnd -= 1; lastVerticalRow = true; crossVerticalGap = yNeighbor != null; } Voxel a, b; for (int y = yStart; y <= yEnd; y++) { int i = y * resolution + xStart; b = voxels[i]; for (int x = xStart; x <= xEnd; x++, i++) { a = b; b = voxels[i + 1]; stencil.SetHorizontalCrossing(a, b); stencil.SetVerticalCrossing(a, voxels[i + resolution]); } stencil.SetVerticalCrossing(b, voxels[i + resolution]); if (crossHorizontalGap) { dummyX.BecomeXDummyOf(xNeighbor.voxels[y * resolution], gridSize); stencil.SetHorizontalCrossing(b, dummyX); } } if (lastVerticalRow) { int i = voxels.Length - resolution + xStart; b = voxels[i]; for (int x = xStart; x <= xEnd; x++, i++) { a = b; b = voxels[i + 1]; stencil.SetHorizontalCrossing(a, b); if (crossVerticalGap) { dummyY.BecomeYDummyOf(yNeighbor.voxels[x], gridSize); stencil.SetVerticalCrossing(a, dummyY); } } if (crossVerticalGap) { dummyY.BecomeYDummyOf(yNeighbor.voxels[xEnd + 1], gridSize); stencil.SetVerticalCrossing(b, dummyY); } if (crossHorizontalGap) { dummyX.BecomeXDummyOf(xNeighbor.voxels[voxels.Length - resolution], gridSize); stencil.SetHorizontalCrossing(b, dummyX); } } }