From 64b55b91bee201dbfdc21531087140cd227609d0 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 11 Oct 2026 21:28:56 +0900 Subject: [PATCH] =?UTF-8?q?=E8=BB=B8=E3=81=AB=E6=B2=BF=E3=81=A3=E3=81=9F?= =?UTF-8?q?=E8=A7=92=E5=BA=A6=E3=81=A7=E4=BD=99=E7=99=BD=E3=81=8C1?= =?UTF-8?q?=E7=94=BB=E7=B4=A0=E5=BA=83=E3=81=8C=E3=82=8B=E3=81=AE=E3=82=92?= =?UTF-8?q?=E7=9B=B4=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpectrumColorShift.Tests/ShiftGeometryTests.cs | 15 +++++++++++++++ SpectrumColorShift/ShiftGeometry.cs | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/SpectrumColorShift.Tests/ShiftGeometryTests.cs b/SpectrumColorShift.Tests/ShiftGeometryTests.cs index c17c1ca..c60ea8f 100644 --- a/SpectrumColorShift.Tests/ShiftGeometryTests.cs +++ b/SpectrumColorShift.Tests/ShiftGeometryTests.cs @@ -67,6 +67,8 @@ public sealed class ShiftGeometryTests [InlineData(10f, 0f, 1f, -2, -12, 42, 36)] [InlineData(10f, 0.5f, 0.25f, -7, -5, 47, 29)] [InlineData(0.25f, 1f, 0f, -3, -2, 43, 26)] + [InlineData(10.0005f, 1f, 0f, -12, -2, 52, 26)] + [InlineData(10.002f, 1f, 0f, -13, -2, 53, 26)] public void ALinearShiftGrowsTheBoundsByTheRoundedUpComponentsPlusTwoPixels(float distance, float x, float y, int left, int top, int right, int bottom) { var rect = new RawRect(0, 0, 40, 24); @@ -78,6 +80,19 @@ public sealed class ShiftGeometryTests Assert.Equal(output, input); } + [Theory] + [InlineData(90f, -2, -12, 42, 36)] + [InlineData(-90f, -2, -12, 42, 36)] + [InlineData(180f, -12, -2, 52, 26)] + [InlineData(270f, -2, -12, 42, 36)] + [InlineData(0f, -12, -2, 52, 26)] + public void AnAxisAlignedAngleAddsNoPixelFromRoundingNoise(float degrees, int left, int top, int right, int bottom) + { + var output = ShiftGeometry.Output(new RawRect(0, 0, 40, 24), ShiftMode.Linear, 10f, Unit(degrees), Vector2.Zero, 1f); + + Assert.Equal(new RawRect(left, top, right, bottom), output); + } + [Theory] [InlineData(25f, -69, -69, 69, 69)] [InlineData(-25f, -69, -69, 69, 69)] diff --git a/SpectrumColorShift/ShiftGeometry.cs b/SpectrumColorShift/ShiftGeometry.cs index cccca1a..09011d2 100644 --- a/SpectrumColorShift/ShiftGeometry.cs +++ b/SpectrumColorShift/ShiftGeometry.cs @@ -8,6 +8,8 @@ namespace SpectrumColorShift public const float MaxRadialShift = 0.5f; public const int Guard = 2; + private const double RoundingTolerance = 1e-3; + public static Vector2 Center(RawRect rect, Vector2 offset) => new((rect.Left + rect.Right) * 0.5f + offset.X, (rect.Top + rect.Bottom) * 0.5f + offset.Y); @@ -106,7 +108,7 @@ namespace SpectrumColorShift return MathF.Sqrt(dx * dx + dy * dy); } - private static int Margin(float distance) => Saturate((long)Math.Ceiling(distance) + Guard); + private static int Margin(float distance) => Saturate((long)Math.Ceiling(distance - RoundingTolerance) + Guard); private static RawRect Inflate(RawRect rect, int marginX, int marginY) => new(