Skip to content

Commit 94e2ae2

Browse files
More tests and NET 472 hacks
1 parent b0f3858 commit 94e2ae2

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public IPath[] GenerateClippedShapes(ClippingOperation operation, IntersectionRu
4646

4747
for (int j = 0; j < path.Count; j++)
4848
{
49+
#if NET472
50+
Vector2 v = path[j];
51+
points[j] = new PointF((float)(v.X / (double)ScalingFactor), (float)(v.Y / (double)ScalingFactor));
52+
#else
4953
points[j] = path[j] / ScalingFactor;
54+
#endif
5055
}
5156

5257
shapes[index++] = new Polygon(new LinearLineSegment(points));
@@ -59,7 +64,12 @@ public IPath[] GenerateClippedShapes(ClippingOperation operation, IntersectionRu
5964

6065
for (int j = 0; j < path.Count; j++)
6166
{
67+
#if NET472
68+
Vector2 v = path[j];
69+
points[j] = new PointF((float)(v.X / (double)ScalingFactor), (float)(v.Y / (double)ScalingFactor));
70+
#else
6271
points[j] = path[j] / ScalingFactor;
72+
#endif
6373
}
6474

6575
shapes[index++] = new Polygon(new LinearLineSegment(points));

src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperOffset.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ public ComplexPolygon Execute(float width)
4040
var points = new PointF[pt.Count];
4141
for (int j = 0; j < pt.Count; j++)
4242
{
43+
#if NET472
44+
Vector2 v = pt[j];
45+
points[j] = new PointF((float)(v.X / (double)ScalingFactor), (float)(v.Y / (double)ScalingFactor));
46+
#else
4347
points[j] = pt[j] / ScalingFactor;
48+
#endif
4449
}
4550

4651
polygons[i] = new Polygon(new LinearLineSegment(points));

tests/ImageSharp.Drawing.Tests/Drawing/ClipTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
57
using System.Numerics;
68
using SixLabors.ImageSharp.Drawing.Processing;
79
using SixLabors.ImageSharp.PixelFormats;
@@ -36,5 +38,22 @@ public void Clip<TPixel>(TestImageProvider<TPixel> provider, float dx, float dy,
3638
appendPixelTypeToFileName: false,
3739
appendSourceFileOrDescription: false);
3840
}
41+
42+
[Fact]
43+
public void Issue250_Vertical_Horizontal_Count_Should_Match()
44+
{
45+
var clip = new PathCollection(new RectangularPolygon(new PointF(24, 16), new PointF(777, 385)));
46+
47+
var vert = new Path(new LinearLineSegment(new PointF(26, 384), new PointF(26, 163)));
48+
var horiz = new Path(new LinearLineSegment(new PointF(26, 163), new PointF(176, 163)));
49+
50+
IPath reverse = vert.Clip(clip);
51+
IEnumerable<ReadOnlyMemory<PointF>> result1 = vert.Clip(reverse).Flatten().Select(x => x.Points);
52+
53+
reverse = horiz.Clip(clip);
54+
IEnumerable<ReadOnlyMemory<PointF>> result2 = horiz.Clip(reverse).Flatten().Select(x => x.Points);
55+
56+
bool same = result1.Count() == result2.Count();
57+
}
3958
}
4059
}

tests/ImageSharp.Drawing.Tests/Drawing/FillPolygonTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public void FillPolygon_StarCircle_AllOperations(TestImageProvider<Rgba32> provi
192192
IPath circle = new EllipsePolygon(36, 36, 36).Translate(28, 28);
193193
var star = new Star(64, 64, 5, 24, 64);
194194

195+
// See http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/ClipType.htm for reference.
195196
foreach (ClippingOperation operation in (ClippingOperation[])Enum.GetValues(typeof(ClippingOperation)))
196197
{
197198
IPath shape = star.Clip(operation, IntersectionRule.EvenOdd, circle);

tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ public void CanDrawTextAlongPathHorizontal<TPixel>(TestImageProvider<TPixel> pro
704704
provider.RunValidatingProcessorTest(
705705
c => c.Fill(Color.White).Draw(Color.Red, 1, path).Fill(Color.Black, glyphs),
706706
new { type = exampleImageKey },
707-
comparer: ImageComparer.TolerantPercentage(0.002f));
707+
comparer: ImageComparer.TolerantPercentage(0.0025f));
708708
}
709709

710710
[Theory]

0 commit comments

Comments
 (0)