-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathClipTests.cs
More file actions
70 lines (60 loc) · 2.9 KB
/
Copy pathClipTests.cs
File metadata and controls
70 lines (60 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp.Drawing.Tests.Drawing;
[GroupOutput("Drawing")]
public class ClipTests
{
[Theory]
[WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, 0, 0, 0.5)]
[WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, -20, -20, 0.5)]
[WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, -20, -100, 0.5)]
[WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, 20, 20, 0.5)]
[WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, 40, 60, 0.2)]
public void Clip<TPixel>(TestImageProvider<TPixel> provider, float dx, float dy, float sizeMult)
where TPixel : unmanaged, IPixel<TPixel>
{
FormattableString testDetails = $"offset_x{dx}_y{dy}";
provider.RunValidatingProcessorTest(
x =>
{
Size size = x.GetCurrentSize();
int outerRadii = (int)(Math.Min(size.Width, size.Height) * sizeMult);
Star star = new(new PointF(size.Width / 2, size.Height / 2), 5, outerRadii / 2, outerRadii);
Matrix3x2 builder = Matrix3x2.CreateTranslation(new Vector2(dx, dy));
x.Clip(star.Transform(builder), x => x.DetectEdges());
},
testOutputDetails: testDetails,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}
[Theory]
[WithFile(TestImages.Png.Ducky, PixelTypes.Rgba32)]
public void Clip_ConstrainsOperationToClipBounds<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
=> provider.RunValidatingProcessorTest(
x =>
{
Size size = x.GetCurrentSize();
RectangleF rect = new(0, 0, size.Width / 2, size.Height / 2);
RectangularPolygon clipRect = new(rect);
x.Clip(clipRect, ctx => ctx.Flip(FlipMode.Vertical));
},
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
[Fact]
public void Issue250_Vertical_Horizontal_Count_Should_Match()
{
PathCollection clip = new(new RectangularPolygon(new PointF(24, 16), new PointF(777, 385)));
Path vert = new(new LinearLineSegment(new PointF(26, 384), new PointF(26, 163)));
Path horiz = new(new LinearLineSegment(new PointF(26, 163), new PointF(176, 163)));
IPath reverse = vert.Clip(clip);
IEnumerable<ReadOnlyMemory<PointF>> result1 = vert.Clip(reverse).Flatten().Select(x => x.Points);
reverse = horiz.Clip(clip);
IEnumerable<ReadOnlyMemory<PointF>> result2 = horiz.Clip(reverse).Flatten().Select(x => x.Points);
bool same = result1.Count() == result2.Count();
}
}