Skip to content

Commit 3ff3e59

Browse files
committed
remove OrientationHandling customization
1 parent 47f5e8e commit 3ff3e59

12 files changed

Lines changed: 67 additions & 153 deletions

File tree

src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
7777
maxY,
7878
subpixelCount,
7979
shapeOptions.IntersectionRule,
80-
configuration.MemoryAllocator,
81-
shapeOptions.OrientationHandling);
80+
configuration.MemoryAllocator);
8281

8382
try
8483
{

src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ private Buffer2D<float> Render(IPath path)
389389
size.Height,
390390
subpixelCount,
391391
IntersectionRule.Nonzero,
392-
this.MemoryAllocator,
393-
this.Options.TextOptions.OrientationHandling);
392+
this.MemoryAllocator);
394393

395394
try
396395
{

src/ImageSharp.Drawing/Processing/ShapeOptions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public ShapeOptions()
2020
private ShapeOptions(ShapeOptions source)
2121
{
2222
this.IntersectionRule = source.IntersectionRule;
23-
this.OrientationHandling = source.OrientationHandling;
2423
}
2524

2625
/// <summary>
@@ -29,9 +28,6 @@ private ShapeOptions(ShapeOptions source)
2928
/// </summary>
3029
public IntersectionRule IntersectionRule { get; set; } = IntersectionRule.OddEven;
3130

32-
internal OrientationHandling OrientationHandling { get; set; } =
33-
OrientationHandling.ForcePositiveOrientationOnSimplePolygons;
34-
3531
/// <inheritdoc/>
3632
public ShapeOptions DeepClone() => new ShapeOptions(this);
3733
}

src/ImageSharp.Drawing/Processing/TextOptions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ private TextOptions(TextOptions source)
3535
this.VerticalAlignment = source.VerticalAlignment;
3636
this.FallbackFonts.AddRange(source.FallbackFonts);
3737
this.RenderColorFonts = source.RenderColorFonts;
38-
this.OrientationHandling = source.OrientationHandling;
3938
}
4039

4140
/// <summary>
@@ -131,9 +130,6 @@ public float DpiY
131130
/// </summary>
132131
public bool RenderColorFonts { get; set; } = true;
133132

134-
internal OrientationHandling OrientationHandling { get; set; } =
135-
OrientationHandling.ForcePositiveOrientationOnSimplePolygons;
136-
137133
/// <inheritdoc/>
138134
public TextOptions DeepClone() => new TextOptions(this);
139135
}

src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,11 @@ public static PolygonScanner Create(
9696
int maxY,
9797
int subsampling,
9898
IntersectionRule intersectionRule,
99-
MemoryAllocator allocator,
100-
OrientationHandling orientationHandling)
99+
MemoryAllocator allocator)
101100
{
102-
TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, allocator, orientationHandling);
103-
ScanEdgeCollection edges = ScanEdgeCollection.Create(multipolygon, allocator, subsampling);
104-
PolygonScanner scanner = new PolygonScanner(edges, multipolygon.TotalVertexCount * 2, minY, maxY, subsampling, intersectionRule, allocator);
101+
var multipolygon = TessellatedMultipolygon.Create(polygon, allocator);
102+
var edges = ScanEdgeCollection.Create(multipolygon, allocator, subsampling);
103+
var scanner = new PolygonScanner(edges, multipolygon.TotalVertexCount * 2, minY, maxY, subsampling, intersectionRule, allocator);
105104
scanner.Init();
106105
return scanner;
107106
}

src/ImageSharp.Drawing/Shapes/Rasterization/ScanEdgeCollection.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ public void Dispose()
4040
public static ScanEdgeCollection Create(
4141
IPath polygon,
4242
MemoryAllocator allocator,
43-
int subsampling,
44-
OrientationHandling orientationHandling = OrientationHandling.FirstRingIsContourFollowedByHoles)
43+
int subsampling)
4544
{
46-
TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, allocator, orientationHandling);
45+
TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, allocator, OrientationHandling.ForcePositiveOrientationOnSimplePolygons);
4746
return Create(multipolygon, allocator, subsampling);
4847
}
4948
}
50-
}
49+
}

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

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,12 @@ public void FillPolygon_Complex<TPixel>(TestImageProvider<TPixel> provider, bool
9393
ComplexPolygon polygon = new ComplexPolygon(
9494
new Path(new LinearLineSegment(contour)),
9595
new Path(new LinearLineSegment(hole)));
96-
96+
9797
provider.RunValidatingProcessorTest(
9898
c =>
9999
{
100100
c.SetShapeOptions(new ShapeOptions()
101101
{
102-
OrientationHandling = OrientationHandling.KeepOriginal,
103102
IntersectionRule = intersectionRule
104103
});
105104
c.Fill(Color.White, polygon);
@@ -133,14 +132,7 @@ public void FillPolygon_Concave<TPixel>(TestImageProvider<TPixel> provider, bool
133132
var color = Color.LightGreen;
134133

135134
provider.RunValidatingProcessorTest(
136-
c =>
137-
{
138-
c.SetShapeOptions(new ShapeOptions()
139-
{
140-
OrientationHandling = OrientationHandling.KeepOriginal
141-
});
142-
c.FillPolygon(color, points);
143-
},
135+
c => c.FillPolygon(color, points),
144136
testOutputDetails: $"Reverse({reverse})",
145137
comparer: ImageComparer.TolerantPercentage(0.01f),
146138
appendSourceFileOrDescription: false,
@@ -154,44 +146,14 @@ public void FillPolygon_StarCircle(TestImageProvider<Rgba32> provider)
154146
EllipsePolygon circle = new EllipsePolygon(32, 32, 30);
155147
Star star = new Star(32, 32, 7, 10, 27);
156148
IPath shape = circle.Clip(star);
157-
149+
158150
provider.RunValidatingProcessorTest(
159-
c =>
160-
{
161-
c.SetShapeOptions(new ShapeOptions()
162-
{
163-
OrientationHandling = OrientationHandling.KeepOriginal
164-
});
165-
c.Fill(Color.White, shape);
166-
},
151+
c => c.Fill(Color.White, shape),
167152
comparer: ImageComparer.TolerantPercentage(0.01f),
168153
appendSourceFileOrDescription: false,
169154
appendPixelTypeToFileName: false);
170155
}
171156

172-
[Theory]
173-
[WithSolidFilledImages(30, 30, "Black", PixelTypes.Rgba32)]
174-
public void FillPolygon_Reverse<TPixel>(TestImageProvider<TPixel> provider)
175-
where TPixel : unmanaged, IPixel<TPixel>
176-
{
177-
PointF[] points = PolygonFactory.CreatePointArray(
178-
(2.5644531f, 2.6796875f),
179-
(2.9794922f, 10.443359f),
180-
(3.6386719f, 23.382812f),
181-
(24.634766f, 23.382812f));
182-
183-
using var image = provider.GetImage();
184-
image.Mutate(c =>
185-
{
186-
c.SetShapeOptions(new ShapeOptions()
187-
{
188-
OrientationHandling = OrientationHandling.KeepOriginal
189-
});
190-
c.FillPolygon(Color.White, points);
191-
});
192-
image.DebugSave(provider);
193-
}
194-
195157
[Theory]
196158
[WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32)]
197159
public void FillPolygon_Pattern<TPixel>(TestImageProvider<TPixel> provider)
@@ -285,16 +247,15 @@ public void Fill_EllipsePolygon<TPixel>(TestImageProvider<TPixel> provider, bool
285247
{
286248
polygon = polygon.Reverse();
287249
}
288-
250+
289251
var color = Color.Azure;
290252

291253
provider.RunValidatingProcessorTest(
292254
c =>
293255
{
294256
c.SetShapeOptions(new ShapeOptions()
295257
{
296-
IntersectionRule = intersectionRule,
297-
OrientationHandling = OrientationHandling.KeepOriginal
258+
IntersectionRule = intersectionRule
298259
});
299260
c.Fill(color, polygon);
300261
},

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class DrawTextOnImageTests
2626
private const string TestText = "Sphinx of black quartz, judge my vow\n0123456789";
2727

2828
public static ImageComparer TextDrawingComparer = TestEnvironment.IsFramework
29-
? ImageComparer.TolerantPercentage(1e-3f) // Relax comparison on .NET Framework
29+
? ImageComparer.TolerantPercentage(1e-3f) // Relax comparison on .NET Framework
3030
: ImageComparer.TolerantPercentage(1e-5f);
3131

3232
public static ImageComparer OutlinedTextDrawingComparer = ImageComparer.TolerantPercentage(5e-4f);
@@ -155,17 +155,9 @@ public void FontShapesAreRenderedCorrectly<TPixel>(
155155
where TPixel : unmanaged, IPixel<TPixel>
156156
{
157157
Font font = CreateFont(fontName, fontSize);
158-
var color = Color.Black;
159158

160159
provider.RunValidatingProcessorTest(
161-
c =>
162-
{
163-
c.SetTextOptions(new TextOptions()
164-
{
165-
OrientationHandling = OrientationHandling.KeepOriginal
166-
});
167-
c.DrawText(text, new Font(font, fontSize), color, new PointF(x, y));
168-
},
160+
c => c.DrawText(text, font, Color.Black, new PointF(x, y)),
169161
$"{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}-({x},{y})",
170162
TextDrawingComparer,
171163
appendPixelTypeToFileName: false,

tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,14 @@ private void TestScan(
7070
int max,
7171
int subsampling,
7272
FuzzyFloat[][] expected,
73-
IntersectionRule intersectionRule,
74-
OrientationHandling orientationHandling = OrientationHandling.FirstRingIsContourFollowedByHoles)
73+
IntersectionRule intersectionRule)
7574
{
7675
var scanner = PolygonScanner.Create(path,
7776
min,
7877
max,
7978
subsampling,
8079
intersectionRule,
81-
Configuration.Default.MemoryAllocator,
82-
orientationHandling);
80+
Configuration.Default.MemoryAllocator);
8381

8482
try
8583
{
@@ -317,7 +315,7 @@ public void SelfIntersecting03(IntersectionRule rule)
317315

318316
TestScan(poly, 1, 5, 2, expected, rule);
319317
}
320-
318+
321319
[Theory]
322320
[InlineData(IntersectionRule.OddEven)]
323321
[InlineData(IntersectionRule.Nonzero)]
@@ -326,7 +324,7 @@ public void SelfIntersecting04(IntersectionRule rule)
326324
IPath poly = PolygonFactory.CreatePolygon((1, 4), (1, 3), (3, 3), (3, 2), (2, 2), (2, 4), (1, 4), (1, 1),
327325
(4, 1), (4, 4), (3, 4), (3, 5), (2, 5), (2, 4), (1, 4));
328326
DebugDraw.Polygon(poly, 1f, 100f);
329-
327+
330328
FuzzyFloat[][] expected;
331329
if (rule == IntersectionRule.OddEven)
332330
{
@@ -358,17 +356,25 @@ public void SelfIntersecting04(IntersectionRule rule)
358356
new FuzzyFloat[] {2, 3},
359357
};
360358
}
361-
359+
362360
TestScan(poly, 1, 5, 2, expected, rule);
363361
}
364-
365-
362+
363+
366364
[Theory]
367365
[InlineData(IntersectionRule.OddEven)]
368366
[InlineData(IntersectionRule.Nonzero)]
369367
public void NegativeOrientation01(IntersectionRule intersectionRule)
370368
{
371-
IPath poly = PolygonFactory.CreatePolygon((0, 0), (0, 2), (2, 2), (2, 0));
369+
// IPath poly = PolygonFactory.CreatePolygon((0, 0), (0, 2), (2, 2), (2, 0));
370+
PointF[] interest = PolygonFactory.CreatePointArray((0, 0), (0, 2), (2, 2), (2, 0));
371+
372+
// Adding a dummy ring outside the area of interest, so the actual loop is not oriented positively
373+
PointF[] dummy = PolygonFactory.CreatePointArray((0, 10), (10, 10), (0, 11));
374+
375+
var poly = new ComplexPolygon(
376+
new Polygon(new LinearLineSegment(interest)),
377+
new Polygon(new LinearLineSegment(dummy)));
372378

373379
FuzzyFloat[][] expected =
374380
{
@@ -378,8 +384,8 @@ public void NegativeOrientation01(IntersectionRule intersectionRule)
378384
new FuzzyFloat[] { 0, 2 },
379385
new FuzzyFloat[] { 0, 0, 2, 2},
380386
};
381-
382-
TestScan(poly, 0, 2, 2, expected, intersectionRule, OrientationHandling.KeepOriginal);
387+
388+
TestScan(poly, 0, 2, 2, expected, intersectionRule);
383389
}
384390

385391
private static (float y, FuzzyFloat[] x) Empty(float y) => (y, new FuzzyFloat[0]);
@@ -451,7 +457,7 @@ public void NegativeOrientation01(IntersectionRule intersectionRule)
451457
{
452458
Empty(4f),
453459

454-
// Eps = 0.01 to address inaccuracies on .NET Framework
460+
// Eps = 0.01 to address inaccuracies on .NET Framework
455461
(4.25f, new FuzzyFloat[] { F(13, 0.01f), F(13, 0.01f)}),
456462
(4.5f, new FuzzyFloat[] {F(12.714286f, 0.5f), F(13.444444f, 0.5f), 16, 16}),
457463
(4.75f, new FuzzyFloat[] {F(12.357143f, 0.5f), 14, 14, 16}),
@@ -510,7 +516,7 @@ public void NumericCornerCases(string name, (float y, FuzzyFloat[] x)[] expected
510516
result.Add(offset, (string)data[0], ((float y, FuzzyFloat[] x)[]) data[1]);
511517
}
512518
}
513-
519+
514520
return result;
515521
}
516522

@@ -520,7 +526,7 @@ public void NumericCornerCases_Offset(float offset, string name, (float y, Fuzzy
520526
{
521527
float dx = offset;
522528
float dy = offset;
523-
529+
524530
IPath poly = NumericCornerCasePolygons.GetByName(name).Transform(Matrix3x2.CreateTranslation(dx, dy));
525531
expectedIntersections = TranslateIntersections(expectedIntersections, dx, dy);
526532

0 commit comments

Comments
 (0)