Skip to content

Commit 7bbb5af

Browse files
committed
improvve PolygonScanning.MD and add benchmark results
1 parent e2e1ef6 commit 7bbb5af

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanning.MD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SCANLINE 2 >>>> | >>>>>>>>>>>>>> + - - - - - - - - - - + >>>>>>>>>
2626
| |
2727
| D |
2828
| |
29-
| |
29+
| (1) | (1)
3030
+ - - - - - - - +
3131
3232
```
@@ -36,14 +36,14 @@ SCANLINE 2 >>>> | >>>>>>>>>>>>>> + - - - - - - - - - - + >>>>>>>>>
3636

3737
- Intersection with edge A is trivial, since it's being intersected on an internal point of the edge
3838
- The second intersection is more tricky: the intersection point is at the connection (vertex) between edges B and C, but we do not want to emit the intersection 2 times.
39-
- To avoid this, when checking the scanline's collision against edge B we emit 0 intersections for edge B at it's endpoint (Y1), when checking against edge C we emit 1 point at its start point (Y0)
39+
- To avoid this, when checking the scanline's collision against edge B we emit 0 intersections at it's endpoint (Y1), when checking against edge C we emit 1 point at its start point (Y0)
4040

4141
#### Intersections at SCANLINE 2
4242

4343
- Intersection with edge A is trivial, since it's being intersected on an internal point
4444
- However the rest is tricky: We want to to emulate the intersection with the collinear edge X not being listed in `ScanEdgeCollection`.
4545
- The easiest way is to emit a point pair for the line part between A-D and a second point pair for D-C (to emulate the intersection with X)
46-
- To achieve this, we should emit the start point (Y0) intersection of the D edge 2 times!
46+
- To achieve this, we should emit the start point (Y0) of the D edge 2 times when intersecting it!
4747

4848
### Edge emit rules
4949

tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPolygon.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ protected override PointF[][] GetPoints(FeatureCollection features)
147147
* Matrix3x2.CreateScale(60, 60);
148148
return PolygonFactory.GetGeoJsonPoints(state, transform).ToArray();
149149
}
150+
151+
// ** 11/13/2020 @ Anton's PC ***
152+
// BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.1198 (1909/November2018Update/19H2)
153+
// Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
154+
// .NET Core SDK=5.0.100-preview.6.20318.15
155+
// [Host] : .NET Core 3.1.1 (CoreCLR 4.700.19.60701, CoreFX 4.700.19.60801), X64 RyuJIT
156+
// DefaultJob : .NET Core 3.1.1 (CoreCLR 4.700.19.60701, CoreFX 4.700.19.60801), X64 RyuJIT
157+
//
158+
//
159+
// | Method | Mean | Error | StdDev | Ratio | RatioSD |
160+
// |-------------- |-----------:|---------:|----------:|------:|--------:|
161+
// | SystemDrawing | 457.4 us | 9.07 us | 23.40 us | 2.15 | 0.10 |
162+
// | ImageSharp | 3,079.5 us | 61.45 us | 138.71 us | 14.30 | 0.89 |
163+
// | SkiaSharp | 217.7 us | 4.29 us | 6.55 us | 1.00 | 0.00 |
150164
}
151165

152166
public class FillPolygonSmall : FillPolygon

0 commit comments

Comments
 (0)