Skip to content

Commit a043faa

Browse files
Additional post merge cleanup
1 parent d06507d commit a043faa

18 files changed

+147
-131
lines changed

PolygonClipper.sln

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
4-
VisualStudioVersion = 17.12.35707.178 d17.12
4+
VisualStudioVersion = 17.12.35707.178
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PolygonClipper", "src\PolygonClipper\PolygonClipper.csproj", "{3C8D945E-6074-437E-B6EA-237BD0C80411}"
77
EndProject
@@ -74,4 +74,8 @@ Global
7474
GlobalSection(ExtensibilityGlobals) = postSolution
7575
SolutionGuid = {2C73BEEC-091B-45E4-A0BD-7D7CD16A8451}
7676
EndGlobalSection
77+
GlobalSection(SharedMSBuildProjectFiles) = preSolution
78+
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{3c8d945e-6074-437e-b6ea-237bd0c80411}*SharedItemsImports = 5
79+
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
80+
EndGlobalSection
7781
EndGlobal

src/PolygonClipper/Contour.cs

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

44
using System.Collections;
5-
using System.Collections.Generic;
65
using System.Diagnostics;
76
using System.Runtime.CompilerServices;
87

src/PolygonClipper/Polygon.cs

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

44
using System.Collections;
5-
using System.Collections.Generic;
65
using System.Runtime.CompilerServices;
76

87
namespace SixLabors.PolygonClipper;

src/PolygonClipper/PolygonClipper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public Polygon Run()
208208
if (sweepEvent.Left)
209209
{
210210
// Insert the event into the status line and get neighbors
211-
int it = sweepEvent.PosSL = statusLine.Insert(sweepEvent);
211+
int it = sweepEvent.PosSL = statusLine.Add(sweepEvent);
212212
prevEvent = statusLine.Prev(it);
213213
nextEvent = statusLine.Next(it);
214214

@@ -428,13 +428,13 @@ private static void ComputeFields(SweepEvent le, SweepEvent? prev, BooleanOperat
428428
{
429429
// Previous line segment in sl belongs to a different polygon that "se" belongs to.
430430
le.InOut = !prev.OtherInOut;
431-
le.OtherInOut = prev.Vertical() ? !prev.InOut : prev.InOut;
431+
le.OtherInOut = prev.IsVertical() ? !prev.InOut : prev.InOut;
432432
}
433433

434434
// Compute PrevInResult field
435435
if (prev != null)
436436
{
437-
le.PrevInResult = (!InResult(prev, operation) || prev.Vertical())
437+
le.PrevInResult = (!InResult(prev, operation) || prev.IsVertical())
438438
? prev.PrevInResult
439439
: prev;
440440
}
@@ -562,8 +562,8 @@ private static int PossibleIntersection(
562562

563563
// Point intersections
564564
int nIntersections = PolygonUtilities.FindIntersection(
565-
le1.Segment(),
566-
le2.Segment(),
565+
le1.GetSegment(),
566+
le2.GetSegment(),
567567
out Vertex ip1,
568568
out Vertex _); // Currently unused but could be used to detect collinear overlapping segments
569569

src/PolygonClipper/SegmentComparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public int Compare(SweepEvent? x, SweepEvent? y)
5656
// If they share their left endpoint, use the right endpoint to sort
5757
if (perhapsInversedX.Point == perhapsInversedY.Point)
5858
{
59-
return LessIf(perhapsInversedX.Below(perhapsInversedY.OtherEvent.Point), inversed);
59+
return LessIf(perhapsInversedX.IsBelow(perhapsInversedY.OtherEvent.Point), inversed);
6060
}
6161

6262
// Different left endpoints: use the y-coordinate to sort if x-coordinates are the same

src/PolygonClipper/StablePriorityQueue{T,TComparer}.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ internal sealed class StablePriorityQueue<T, TComparer>
1717
where TComparer : IComparer<T>
1818
{
1919
private const int Log2Arity = 2;
20+
private const int DefaultCapacity = 16;
2021
private readonly List<T> heap;
2122

23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="StablePriorityQueue{T, TComparer}"/> class with a specified comparer.
25+
/// </summary>
26+
/// <param name="comparer">The comparer to determine the priority of the elements.</param>
27+
public StablePriorityQueue(TComparer comparer)
28+
: this(comparer, DefaultCapacity)
29+
{
30+
}
31+
2232
/// <summary>
2333
/// Initializes a new instance of the <see cref="StablePriorityQueue{T, TComparer}"/> class with a specified comparer.
2434
/// </summary>
@@ -27,7 +37,7 @@ internal sealed class StablePriorityQueue<T, TComparer>
2737
public StablePriorityQueue(TComparer comparer, int capacity)
2838
{
2939
this.Comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
30-
this.heap = new List<T>(capacity > 0 ? capacity : 16);
40+
this.heap = new List<T>(capacity > 0 ? capacity : DefaultCapacity);
3141
}
3242

3343
/// <summary>

src/PolygonClipper/StatusLine.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ namespace SixLabors.PolygonClipper;
2525
[DebuggerDisplay("Count = {Count}")]
2626
internal sealed class StatusLine
2727
{
28+
private const int DefaultCapacity = 16;
2829
private readonly List<SweepEvent> sortedEvents;
2930
private readonly SegmentComparer comparer = new();
3031

32+
public StatusLine()
33+
: this(DefaultCapacity)
34+
{
35+
}
36+
3137
public StatusLine(int capacity)
32-
=> this.sortedEvents = new List<SweepEvent>(capacity > 0 ? capacity : 16);
38+
=> this.sortedEvents = new List<SweepEvent>(capacity > 0 ? capacity : DefaultCapacity);
3339

3440
/// <summary>
3541
/// Gets the number of events in the status line.
@@ -40,6 +46,24 @@ public int Count
4046
get => this.sortedEvents.Count;
4147
}
4248

49+
/// <summary>
50+
/// Gets the minimum sweep event in the status line (first in sort order).
51+
/// </summary>
52+
public SweepEvent Min
53+
{
54+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
55+
get => this.sortedEvents[0];
56+
}
57+
58+
/// <summary>
59+
/// Gets the maximum sweep event in the status line (last in sort order).
60+
/// </summary>
61+
public SweepEvent Max
62+
{
63+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
64+
get => this.sortedEvents[^1];
65+
}
66+
4367
/// <summary>
4468
/// Gets the event at the specified index.
4569
/// </summary>
@@ -52,11 +76,11 @@ public SweepEvent this[int index]
5276
}
5377

5478
/// <summary>
55-
/// Inserts a sweep event into the status line, maintaining sorted order.
79+
/// Adds a sweep event into the status line, maintaining sorted order.
5680
/// </summary>
5781
/// <param name="e">The sweep event to insert.</param>
5882
/// <returns>The index where the event was inserted.</returns>
59-
public int Insert(SweepEvent e)
83+
public int Add(SweepEvent e)
6084
{
6185
int index = this.sortedEvents.BinarySearch(e, this.comparer);
6286
if (index < 0)

src/PolygonClipper/SweepEvent.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public SweepEvent(Vertex point, bool left, int contourId)
152152
/// <see langword="true"/> if the line segment is below the point; otherwise <see langword="false"/>.
153153
/// </returns>
154154
[MethodImpl(MethodImplOptions.AggressiveInlining)]
155-
public bool Below(in Vertex p)
155+
public bool IsBelow(in Vertex p)
156156
=> this.Left
157157
? PolygonUtilities.SignedArea(this.Point, this.OtherEvent.Point, p) > 0D
158158
: PolygonUtilities.SignedArea(this.OtherEvent.Point, this.Point, p) > 0D;
@@ -165,7 +165,7 @@ public bool Below(in Vertex p)
165165
/// <see langword="true"/> if the line segment is above the point; otherwise <see langword="false"/>.
166166
/// </returns>
167167
[MethodImpl(MethodImplOptions.AggressiveInlining)]
168-
public bool Above(in Vertex p) => !this.Below(p);
168+
public bool IsAbove(in Vertex p) => !this.IsBelow(p);
169169

170170
/// <summary>
171171
/// Is the line segment (point, otherEvent->point) a vertical line segment.
@@ -174,7 +174,7 @@ public bool Below(in Vertex p)
174174
/// <see langword="true"/> if the line segment is vertical; otherwise <see langword="false"/>.
175175
/// </returns>
176176
[MethodImpl(MethodImplOptions.AggressiveInlining)]
177-
public bool Vertical() => this.Point.X == this.OtherEvent.Point.X;
177+
public bool IsVertical() => this.Point.X == this.OtherEvent.Point.X;
178178

179179
/// <summary>
180180
/// Determines if this sweep event comes before another sweep event.
@@ -199,7 +199,7 @@ public bool IsBefore(SweepEvent other)
199199
/// <summary>
200200
/// Returns the segment associated with the sweep event.
201201
/// </summary>
202-
/// <returns>The <see cref="Segment"/>.</returns>
202+
/// <returns>The <see cref="GetSegment"/>.</returns>
203203
[MethodImpl(MethodImplOptions.AggressiveInlining)]
204-
public Segment Segment() => new(this.Point, this.OtherEvent.Point);
204+
public Segment GetSegment() => new(this.Point, this.OtherEvent.Point);
205205
}

src/PolygonClipper/SweepEventComparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public int Compare(SweepEvent? x, SweepEvent? y)
5050
double area = PolygonUtilities.SignedArea(x.Point, x.OtherEvent.Point, y.OtherEvent.Point);
5151
if (area != 0)
5252
{
53-
return x.Below(y.OtherEvent.Point) ? -1 : 1;
53+
return x.IsBelow(y.OtherEvent.Point) ? -1 : 1;
5454
}
5555

5656
// Compare by polygon type: subject polygons have higher priority

tests/PolygonClipper.Benchmarks/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace SixLabors.PolygonClipper.Benchmarks;
77

8-
internal class Program
8+
internal sealed class Program
99
{
1010
public static void Main(string[] args)
1111
=> BenchmarkSwitcher

0 commit comments

Comments
 (0)