WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit ef89dd0

Browse files
Use Vertex.Cross
1 parent 8e7164e commit ef89dd0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using System.Runtime.CompilerServices;
45
using SixLabors.PolygonClipper;
56
using ClipperPolygon = SixLabors.PolygonClipper.Polygon;
67

@@ -100,6 +101,7 @@ public static ClipperPolygon FromSimplePaths(IEnumerable<ISimplePath> paths, Int
100101
}
101102

102103
// Parent assignment: pick the smallest-area ring that contains the bottom-left vertex.
104+
// TODO: We can use pooling here if we care about large numbers of rings.
103105
int[] parent = new int[m];
104106
Array.Fill(parent, -1);
105107

@@ -131,6 +133,7 @@ public static ClipperPolygon FromSimplePaths(IEnumerable<ISimplePath> paths, Int
131133
}
132134

133135
// Depth = number of ancestors by following Parent links.
136+
// TODO: We can pool this if we care about large numbers of rings.
134137
int[] depth = new int[m];
135138
for (int i = 0; i < m; i++)
136139
{
@@ -350,9 +353,6 @@ private static bool PointInPolygonNonZero(in Vertex p, List<Vertex> ring)
350353
/// </code>
351354
/// Left if cross &gt; 0, right if cross &lt; 0, collinear if cross == 0.
352355
/// </remarks>
353-
private static bool IsLeft(Vertex a, Vertex b, Vertex p)
354-
{
355-
double cross = ((b.X - a.X) * (p.Y - a.Y)) - ((b.Y - a.Y) * (p.X - a.X));
356-
return cross > 0d;
357-
}
356+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
357+
private static bool IsLeft(Vertex a, Vertex b, Vertex p) => Vertex.Cross(b - a, p - a) > 0d;
358358
}

0 commit comments

Comments
 (0)