Skip to content

Commit

Permalink
Virtual grid slice issue has been fixed. (#5)
Browse files Browse the repository at this point in the history
* Virtual grid slice issue has been fixed.

* Remove System.Buffer reference because we no longer use range and indices.
  • Loading branch information
Desz01ate committed Jun 26, 2021
1 parent 254a143 commit 420d412
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 28 deletions.
9 changes: 3 additions & 6 deletions VirtualGrid/VirtualGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Version>2.0</Version>
<Version>2.0.1</Version>
<Description>A library to simplify RGB tasks when working with multiple devices and vendors by create single lightweight abstract LED array and convert into device or vendor specific implementation via adapter at later state.</Description>
<Copyright>Copyright © Chanvut Booneid 2021</Copyright>
<PackageProjectUrl>https://github.com/Desz01ate/VirtualGrid</PackageProjectUrl>
<RepositoryUrl>https://github.com/Desz01ate/VirtualGrid</RepositoryUrl>
<PackageReleaseNotes>This release contains code update to address issue on VirtualGrid.Slice not working correctly.</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand All @@ -18,10 +19,6 @@

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<DocumentationFile>G:\Documents\GitHub\ListenerX\Submodules\VirtualGrid\VirtualGrid\VirtualGrid.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Buffers" Version="4.5.1" />
</ItemGroup>

</Project>
255 changes: 255 additions & 0 deletions VirtualGrid/VirtualGrid.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 4 additions & 22 deletions VirtualGrid/VirtualLedGrid.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using VirtualGrid.Interfaces;

namespace VirtualGrid
Expand Down Expand Up @@ -126,33 +127,14 @@ IEnumerator IEnumerable.GetEnumerator()

public IVirtualLedGrid? Slice(int column, int row, int columnCount, int rowCount)
{
var requestedColumn = column + columnCount;
var requestedRow = row + rowCount;
if (requestedColumn > this._totalColumnCount)
{
requestedColumn = this._totalColumnCount - 1 - column;
}

if (requestedRow > this._totalRowCount)
{
requestedRow = this._totalRowCount - 1 - row;
}

//even after adjustment, still exceed grid dimension.
if (requestedColumn < 0 || this._totalColumnCount < requestedColumn ||
requestedRow < 0 || this._totalRowCount < requestedRow)
{
return null;
}

var grid = new IVirtualKey[rowCount][];
var subRow = this._grid[row..requestedRow];
var subRow = this._grid.Skip(row).Take(rowCount).ToArray();
for (var rowIdx = 0; rowIdx < subRow.Length; rowIdx++)
{
var currentRow = subRow[rowIdx][column..requestedColumn];
var currentRow = subRow[rowIdx].Skip(column).Take(columnCount).ToArray();
grid[rowIdx] = currentRow;
}
return new VirtualLedGrid(grid, requestedColumn - column, requestedRow - row);
return new VirtualLedGrid(grid, grid.First().Length, subRow.Length);
}
}
}

0 comments on commit 420d412

Please sign in to comment.