From f770b2bfd60a7cda8db355f3fbf60b4b3d64b6ce Mon Sep 17 00:00:00 2001 From: routersys Date: Thu, 8 Oct 2026 12:45:59 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=83=8D=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E6=A4=9C=E8=A8=BC=E3=82=92TilePlan=E3=81=AE=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=81=AB=E5=88=86=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SpectralConvolution.Tests/TilePlanTests.cs | 9 +++++++++ .../SpectralConvolution/KernelSpectrum.cs | 2 +- SpectralConvolution/SpectralConvolution/TilePlan.cs | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/SpectralConvolution/SpectralConvolution.Tests/TilePlanTests.cs b/SpectralConvolution/SpectralConvolution.Tests/TilePlanTests.cs index b95a46e..108dd15 100644 --- a/SpectralConvolution/SpectralConvolution.Tests/TilePlanTests.cs +++ b/SpectralConvolution/SpectralConvolution.Tests/TilePlanTests.cs @@ -146,6 +146,15 @@ public sealed class TilePlanTests Assert.Equal(plan.TileCount * expected, plan.GroupCount); } + [Fact] + public void AKernelThatDoesNotFitTheTileIsRejected() + { + Assert.Throws(() => TilePlan.ValidateKernel(64, 32)); + Assert.Throws(() => TilePlan.ValidateKernel(63, 1)); + Assert.Throws(() => TilePlan.ValidateKernel(64, -1)); + TilePlan.ValidateKernel(64, 31); + } + [Fact] public void TheShadersHoldTwoValuesPerThreadInEveryGroup() { diff --git a/SpectralConvolution/SpectralConvolution/KernelSpectrum.cs b/SpectralConvolution/SpectralConvolution/KernelSpectrum.cs index 228c020..26f4d96 100644 --- a/SpectralConvolution/SpectralConvolution/KernelSpectrum.cs +++ b/SpectralConvolution/SpectralConvolution/KernelSpectrum.cs @@ -24,7 +24,7 @@ internal sealed class KernelSpectrum public void Update(ReadOnlySpan values, int radius, int size) { - _ = TilePlan.Create(size, radius, 0, 0, 1, 1); + TilePlan.ValidateKernel(size, radius); var kernelSize = radius * 2 + 1; var kernelArea = kernelSize * kernelSize; if (values.Length != kernelArea) diff --git a/SpectralConvolution/SpectralConvolution/TilePlan.cs b/SpectralConvolution/SpectralConvolution/TilePlan.cs index 1da45c0..c94e6e0 100644 --- a/SpectralConvolution/SpectralConvolution/TilePlan.cs +++ b/SpectralConvolution/SpectralConvolution/TilePlan.cs @@ -76,12 +76,17 @@ internal readonly record struct TilePlan public static TilePlan Create(int radius, int regionX, int regionY, int regionWidth, int regionHeight) => Create(SelectSize(radius), radius, regionX, regionY, regionWidth, regionHeight); - public static TilePlan Create(int size, int radius, int regionX, int regionY, int regionWidth, int regionHeight) + public static void ValidateKernel(int size, int radius) { if (!IsSupportedSize(size)) throw new ArgumentOutOfRangeException(nameof(size)); ArgumentOutOfRangeException.ThrowIfNegative(radius); ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(radius * 2, size); + } + + public static TilePlan Create(int size, int radius, int regionX, int regionY, int regionWidth, int regionHeight) + { + ValidateKernel(size, radius); ArgumentOutOfRangeException.ThrowIfNegativeOrZero(regionWidth); ArgumentOutOfRangeException.ThrowIfNegativeOrZero(regionHeight); return new TilePlan(size, radius, regionX, regionY, regionWidth, regionHeight);