コード例 #1
0
        public VoxelRegionEnumerator(VoxelBlob aBlob, int aLayer, bool isReverse)
        {
            bool isEmpty;

            int2 minBoundary;
            int2 maxBoundary;

            aBlob.GetLayer(aLayer, ref m_layer, out isEmpty, out minBoundary, out maxBoundary);

            m_width  = m_layer.GetLength(0);
            m_depth  = m_layer.GetLength(1);
            m_region = new VoxelRegion(m_width, m_depth, minBoundary, maxBoundary);

            m_minVals = minBoundary;
            m_maxVals = maxBoundary;

            if (isReverse)
            {
                m_x = maxBoundary.x - 1;
                m_z = maxBoundary.y - 1;
                DirectedMoveNext = ReverseMoveNext;
            }
            else
            {
                m_x = minBoundary.x;
                m_z = minBoundary.y;
                DirectedMoveNext = ForwardMoveNext;
            }

            // Positioned before the first region when created;
            // <http://msdn.microsoft.com/en-us/library/system.collections.ienumerator.movenext(v=vs.110).aspx>
        }
コード例 #2
0
        public ListEnumerator(IEnumerator <T> enumerator)
        {
            _enumerator = enumerator ?? throw new ArgumentNullException(nameof(enumerator));
            _list       = null;
            _roList     = null;

            _moveDelegate = _moveNextEnumerator;
            _index        = 0;
            Current       = default !;
コード例 #3
0
        public VoxelSurfaceEnumerator(VoxelBlob aBlob, VoxelRegion sourceRegion,
                                      int voxelLayer, int printLayer, float layerHeight, bool isReverse)
        {
            // We don't want to surface the first layer, we want 100% infill instead.
            if (printLayer == 0)
            {
                DirectedMoveNext = Empty;
                return;
            }

            float logicalHeight = Mathf.Repeat(printLayer * layerHeight, VoxelBlob.kVoxelSizeInMm);

            if (!(Mathf.Approximately(logicalHeight, 0) ||
                  Mathf.Approximately(logicalHeight + layerHeight, VoxelBlob.kVoxelSizeInMm)))
            {
                // We're neither at the bottom of a voxel nor
                // at the top, so we don't care about surfacing.
                DirectedMoveNext = Empty;
                return;
            }

            // NOTE: Caching the information means that we're not thread safe!
            if (m_width != aBlob.width || m_depth != aBlob.depth)
            {
                m_currentLayer    = new byte[aBlob.width, aBlob.depth];
                m_checkLayer      = new byte[aBlob.width, aBlob.depth];
                m_otherCheckLayer = new byte[aBlob.width, aBlob.depth];
            }

            bool isEmpty;
            bool checkedFirstLayer = false;

            // Grab the adjacent layers to check for space.
            if (Mathf.Approximately(logicalHeight, 0.0f) && voxelLayer > 0)
            {
                // At the bottom of a voxel, so we need to check the lower layer.
                aBlob.GetLayer(voxelLayer - 1, ref m_checkLayer, out isEmpty, out m_minVals, out m_maxVals);
                checkedFirstLayer = true;
            }
            if (Mathf.Approximately(logicalHeight + layerHeight, VoxelBlob.kVoxelSizeInMm) &&
                voxelLayer + 1 < aBlob.height)
            {
                if (!checkedFirstLayer)
                {
                    aBlob.GetLayer(voxelLayer + 1, ref m_checkLayer, out isEmpty, out m_minVals, out m_maxVals);
                }
                else
                {
                    aBlob.GetLayer(voxelLayer + 1, ref m_otherCheckLayer, out isEmpty, out m_minVals, out m_maxVals);
                    for (int x = m_minVals.x; x <= m_maxVals.x; x++)
                    {
                        for (int y = m_minVals.y; y <= m_maxVals.y; y++)
                        {
                            m_checkLayer[x, y] = (byte)Mathf.Min(m_checkLayer[x, y], m_otherCheckLayer[x, y]);
                        }
                    }
                }
            }

            // Grab the current layer for later comparison.
            aBlob.GetLayer(voxelLayer, ref m_currentLayer, out isEmpty, out m_minVals, out m_maxVals);
            if (isEmpty)
            {
                DirectedMoveNext = Empty;
                return;
            }

            m_width = m_checkLayer.GetLength(0);
            m_depth = m_checkLayer.GetLength(1);

            m_region       = new VoxelRegion(m_width, m_depth, m_minVals, m_maxVals);
            m_sourceRegion = sourceRegion;

            if (isReverse)
            {
                // This means we're actually within a voxel, and so we
                // shouldn't do anything.
                m_x = m_maxVals.x - 1;
                m_z = m_maxVals.y - 1;
                DirectedMoveNext = ReverseMoveNext;
            }
            else
            {
                m_x = m_minVals.x;
                m_z = m_minVals.y;
                DirectedMoveNext = ForwardMoveNext;
            }

            // Positioned before the first region when created;
            // <http://msdn.microsoft.com/en-us/library/system.collections.ienumerator.movenext(v=vs.110).aspx>
        }
コード例 #4
0
 private RuneEnumerator(MoveNextDelegate moveNext) : this()
 {
     _moveNext = moveNext;
 }
コード例 #5
0
 public RuneEnumerator(MoveNextDelegate moveNext, object?state) : this()
 {
     _moveNext = moveNext;
     State     = state;
 }