Skip to content

Commit b7402f4

Browse files
Merge pull request #288 from SixLabors/js/conditions
Remove compiler conditions
2 parents b23aa22 + b3078c1 commit b7402f4

File tree

10 files changed

+8
-567
lines changed

10 files changed

+8
-567
lines changed

src/ImageSharp.Drawing/Shapes/Path.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,6 @@ private static ReadOnlySpan<char> TrimSeparator(ReadOnlySpan<char> data)
419419
return data.Slice(idx);
420420
}
421421

422-
#if !NETCOREAPP2_1_OR_GREATER
423-
private static unsafe float ParseFloat(ReadOnlySpan<char> str)
424-
{
425-
fixed (char* p = str)
426-
{
427-
return float.Parse(new string(p, 0, str.Length));
428-
}
429-
}
430-
#else
431422
private static float ParseFloat(ReadOnlySpan<char> str)
432423
=> float.Parse(str, provider: CultureInfo.InvariantCulture);
433-
#endif
434424
}

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

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

4545
for (int j = 0; j < path.Count; j++)
4646
{
47-
#if NET472
48-
Vector2 v = path[j];
49-
points[j] = new PointF((float)(v.X / (double)ScalingFactor), (float)(v.Y / (double)ScalingFactor));
50-
#else
5147
points[j] = path[j] / ScalingFactor;
52-
#endif
5348
}
5449

5550
shapes[index++] = new Polygon(points);
@@ -62,12 +57,7 @@ public IPath[] GenerateClippedShapes(ClippingOperation operation, IntersectionRu
6257

6358
for (int j = 0; j < path.Count; j++)
6459
{
65-
#if NET472
66-
Vector2 v = path[j];
67-
points[j] = new PointF((float)(v.X / (double)ScalingFactor), (float)(v.Y / (double)ScalingFactor));
68-
#else
6960
points[j] = path[j] / ScalingFactor;
70-
#endif
7161
}
7262

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

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

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

5045
polygons[i] = new Polygon(points);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void Execute(float delta, PathsF solution)
7777
this.ExecuteInternal(delta);
7878
if (this.groupList.Count == 0)
7979
{
80-
goto Error;
80+
return;
8181
}
8282

8383
// Clean up self-intersections.
@@ -99,8 +99,6 @@ public void Execute(float delta, PathsF solution)
9999
clipper.Execute(ClippingOperation.Union, FillRule.Positive, solution);
100100
}
101101

102-
Error:
103-
104102
// PolygonClipper will throw for unhandled exceptions but we need to explicitly capture an empty result.
105103
if (solution.Count == 0)
106104
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Six Labors Split License.
33

44
using System.Runtime.CompilerServices;
5-
using SixLabors.ImageSharp.Drawing.Utilities;
65

76
namespace SixLabors.ImageSharp.Drawing.Shapes.Rasterization;
87

@@ -36,7 +35,7 @@ public ActiveEdgeList(Span<int> buffer)
3635
this.Buffer = buffer;
3736
}
3837

39-
private Span<int> ActiveEdges => this.Buffer.Slice(0, this.count);
38+
private readonly Span<int> ActiveEdges => this.Buffer.Slice(0, this.count);
4039

4140
public void EnterEdge(int edgeIdx) => this.Buffer[this.count++] = edgeIdx | EnteringEdgeFlag;
4241

@@ -120,7 +119,8 @@ public Span<float> ScanOddEven(float y, Span<ScanEdge> edges, Span<float> inters
120119
this.count -= offset;
121120

122121
intersections = intersections.Slice(0, intersectionCounter);
123-
SortUtility.Sort(intersections);
122+
intersections.Sort();
123+
124124
return intersections;
125125
}
126126

@@ -180,7 +180,7 @@ public Span<float> ScanNonZero(
180180

181181
intersections = intersections.Slice(0, intersectionCounter);
182182
intersectionTypes = intersectionTypes.Slice(0, intersectionCounter);
183-
SortUtility.Sort(intersections, intersectionTypes);
183+
intersections.Sort(intersectionTypes);
184184

185185
return ApplyNonzeroRule(intersections, intersectionTypes);
186186
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Buffers;
55
using System.Runtime.InteropServices;
6-
using SixLabors.ImageSharp.Drawing.Utilities;
76
using SixLabors.ImageSharp.Memory;
87

98
namespace SixLabors.ImageSharp.Drawing.Shapes.Rasterization;
@@ -120,8 +119,8 @@ private void Init()
120119
this.sorted1[i] = i;
121120
}
122121

123-
SortUtility.Sort(keys0, this.sorted0);
124-
SortUtility.Sort(keys1, this.sorted1);
122+
keys0.Sort(this.sorted0);
123+
keys1.Sort(this.sorted1);
125124

126125
this.SkipEdgesBeforeMinY();
127126
}
@@ -195,7 +194,7 @@ public ReadOnlySpan<float> ScanCurrentLine()
195194
? this.activeEdges.ScanOddEven(this.SubPixelY, this.edges, this.intersections)
196195
: this.activeEdges.ScanNonZero(this.SubPixelY, this.edges, this.intersections, this.intersectionTypes);
197196

198-
public void Dispose()
197+
public readonly void Dispose()
199198
{
200199
this.edgeCollection.Dispose();
201200
this.dataBuffer.Dispose();

src/ImageSharp.Drawing/Utilities/NumericUtilities.cs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,6 @@ public static void AddToAllElements(this Span<float> span, float value)
3838
}
3939
}
4040

41-
// https://apisof.net/catalog/System.Numerics.BitOperations.Log2(UInt32)
42-
// BitOperations.Log2() has been introduced in .NET Core 3.0,
43-
// since we do target only 3.1+, we can detect it's presence by using SUPPORTS_RUNTIME_INTRINSICS
44-
// TODO: Ideally this should have a separate definition in Build.props, but that adaption should be done cross-repo. Using a workaround until then.
45-
#if SUPPORTS_RUNTIME_INTRINSICS
46-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47-
public static int Log2(uint value) => BitOperations.Log2(value);
48-
49-
#else
50-
51-
#pragma warning disable SA1515, SA1414, SA1114, SA1201
52-
private static ReadOnlySpan<byte> Log2DeBruijn => new byte[32]
53-
{
54-
00, 09, 01, 10, 13, 21, 02, 29,
55-
11, 14, 16, 18, 22, 25, 03, 30,
56-
08, 12, 20, 28, 15, 17, 24, 07,
57-
19, 27, 23, 06, 26, 05, 04, 31
58-
};
59-
60-
// Adapted from:
61-
// https://github.com/dotnet/runtime/blob/5c65d891f203618245184fa54397ced0a8ca806c/src/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs#L205-L223
62-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
63-
public static int Log2(uint value)
64-
{
65-
// No AggressiveInlining due to large method size
66-
// Has conventional contract 0->0 (Log(0) is undefined)
67-
68-
// Fill trailing zeros with ones, eg 00010010 becomes 00011111
69-
value |= value >> 01;
70-
value |= value >> 02;
71-
value |= value >> 04;
72-
value |= value >> 08;
73-
value |= value >> 16;
74-
75-
// uint.MaxValue >> 27 is always in range [0 - 31] so we use Unsafe.AddByteOffset to avoid bounds check
76-
return Unsafe.AddByteOffset(
77-
// Using deBruijn sequence, k=2, n=5 (2^5=32) : 0b_0000_0111_1100_0100_1010_1100_1101_1101u
78-
ref MemoryMarshal.GetReference(Log2DeBruijn),
79-
// uint|long -> IntPtr cast on 32-bit platforms does expensive overflow checks not needed here
80-
(IntPtr)(int)((value * 0x07C4ACDDu) >> 27));
81-
}
82-
83-
#pragma warning restore
84-
#endif
8541
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8642
public static float ClampFloat(float value, float min, float max)
8743
{

src/ImageSharp.Drawing/Utilities/SortUtility.KeyValueSort.cs

Lines changed: 0 additions & 205 deletions
This file was deleted.

0 commit comments

Comments
 (0)