Skip to content

Commit 85ec501

Browse files
Cleanup and remove unused methods
1 parent 513abad commit 85ec501

File tree

3 files changed

+15
-167
lines changed

3 files changed

+15
-167
lines changed

src/ImageSharp.Drawing/Processing/PathGradientBrush.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ protected override void Dispose(bool disposing)
349349
Vector2 ip = default;
350350
Vector2 closestIntersection = default;
351351
Edge closestEdge = null;
352-
float minDistance = float.MaxValue;
352+
const float minDistance = float.MaxValue;
353353
foreach (Edge edge in this.edges)
354354
{
355355
if (!edge.Intersect(start, end, ref ip))

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,38 @@ public BoundsF(bool isValid)
5252

5353
public float Width
5454
{
55-
get => this.Right - this.Left;
55+
readonly get => this.Right - this.Left;
5656
set => this.Right = this.Left + value;
5757
}
5858

5959
public float Height
6060
{
61-
get => this.Bottom - this.Top;
61+
readonly get => this.Bottom - this.Top;
6262
set => this.Bottom = this.Top + value;
6363
}
6464

65-
public bool IsEmpty()
65+
public readonly bool IsEmpty()
6666
=> this.Bottom <= this.Top || this.Right <= this.Left;
6767

68-
public Vector2 MidPoint()
68+
public readonly Vector2 MidPoint()
6969
=> new Vector2(this.Left + this.Right, this.Top + this.Bottom) * .5F;
7070

71-
public bool Contains(Vector2 pt)
71+
public readonly bool Contains(Vector2 pt)
7272
=> pt.X > this.Left
7373
&& pt.X < this.Right
7474
&& pt.Y > this.Top && pt.Y < this.Bottom;
7575

76-
public bool Contains(BoundsF bounds)
76+
public readonly bool Contains(BoundsF bounds)
7777
=> bounds.Left >= this.Left
7878
&& bounds.Right <= this.Right
7979
&& bounds.Top >= this.Top
8080
&& bounds.Bottom <= this.Bottom;
8181

82-
public bool Intersects(BoundsF bounds)
82+
public readonly bool Intersects(BoundsF bounds)
8383
=> (Math.Max(this.Left, bounds.Left) < Math.Min(this.Right, bounds.Right))
8484
&& (Math.Max(this.Top, bounds.Top) < Math.Min(this.Bottom, bounds.Bottom));
8585

86-
public PathF AsPath()
86+
public readonly PathF AsPath()
8787
=> new(4)
8888
{
8989
new Vector2(this.Left, this.Top),

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

Lines changed: 6 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -925,158 +925,6 @@ private static OutPt DisposeOutPt(OutPt op)
925925
return result;
926926
}
927927

928-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
929-
private static BoundsF GetBounds(OutPt op)
930-
{
931-
BoundsF result = new(op.Point.X, op.Point.Y, op.Point.X, op.Point.Y);
932-
OutPt op2 = op.Next;
933-
while (op2 != op)
934-
{
935-
if (op2.Point.X < result.Left)
936-
{
937-
result.Left = op2.Point.X;
938-
}
939-
else if (op2.Point.X > result.Right)
940-
{
941-
result.Right = op2.Point.X;
942-
}
943-
944-
if (op2.Point.Y < result.Top)
945-
{
946-
result.Top = op2.Point.Y;
947-
}
948-
else if (op2.Point.Y > result.Bottom)
949-
{
950-
result.Bottom = op2.Point.Y;
951-
}
952-
953-
op2 = op2.Next;
954-
}
955-
956-
return result;
957-
}
958-
959-
private static PointInPolygonResult PointInOpPolygon(Vector2 pt, OutPt op)
960-
{
961-
if (op == op.Next || op.Prev == op.Next)
962-
{
963-
return PointInPolygonResult.IsOutside;
964-
}
965-
966-
OutPt op2 = op;
967-
do
968-
{
969-
if (op.Point.Y != pt.Y)
970-
{
971-
break;
972-
}
973-
974-
op = op.Next;
975-
}
976-
while (op != op2);
977-
978-
// not a proper polygon
979-
if (op.Point.Y == pt.Y)
980-
{
981-
return PointInPolygonResult.IsOutside;
982-
}
983-
984-
// must be above or below to get here
985-
bool isAbove = op.Point.Y < pt.Y, startingAbove = isAbove;
986-
int val = 0;
987-
988-
op2 = op.Next;
989-
while (op2 != op)
990-
{
991-
if (isAbove)
992-
{
993-
while (op2 != op && op2.Point.Y < pt.Y)
994-
{
995-
op2 = op2.Next;
996-
}
997-
}
998-
else
999-
{
1000-
while (op2 != op && op2.Point.Y > pt.Y)
1001-
{
1002-
op2 = op2.Next;
1003-
}
1004-
}
1005-
1006-
if (op2 == op)
1007-
{
1008-
break;
1009-
}
1010-
1011-
// must have touched or crossed the pt.Y horizonal
1012-
// and this must happen an even number of times
1013-
// touching the horizontal
1014-
if (op2.Point.Y == pt.Y)
1015-
{
1016-
if (op2.Point.X == pt.X || (op2.Point.Y == op2.Prev.Point.Y
1017-
&& (pt.X < op2.Prev.Point.X) != (pt.X < op2.Point.X)))
1018-
{
1019-
return PointInPolygonResult.IsOn;
1020-
}
1021-
1022-
op2 = op2.Next;
1023-
if (op2 == op)
1024-
{
1025-
break;
1026-
}
1027-
1028-
continue;
1029-
}
1030-
1031-
if (op2.Point.X <= pt.X || op2.Prev.Point.X <= pt.X)
1032-
{
1033-
if (op2.Prev.Point.X < pt.X && op2.Point.X < pt.X)
1034-
{
1035-
val = 1 - val; // toggle val
1036-
}
1037-
else
1038-
{
1039-
float d = ClipperUtils.CrossProduct(op2.Prev.Point, op2.Point, pt);
1040-
if (d == 0)
1041-
{
1042-
return PointInPolygonResult.IsOn;
1043-
}
1044-
1045-
if ((d < 0) == isAbove)
1046-
{
1047-
val = 1 - val;
1048-
}
1049-
}
1050-
}
1051-
1052-
isAbove = !isAbove;
1053-
op2 = op2.Next;
1054-
}
1055-
1056-
if (isAbove != startingAbove)
1057-
{
1058-
float d = ClipperUtils.CrossProduct(op2.Prev.Point, op2.Point, pt);
1059-
if (d == 0)
1060-
{
1061-
return PointInPolygonResult.IsOn;
1062-
}
1063-
1064-
if ((d < 0) == isAbove)
1065-
{
1066-
val = 1 - val;
1067-
}
1068-
}
1069-
1070-
if (val == 0)
1071-
{
1072-
return PointInPolygonResult.IsOutside;
1073-
}
1074-
else
1075-
{
1076-
return PointInPolygonResult.IsInside;
1077-
}
1078-
}
1079-
1080928
private void ProcessHorzJoins()
1081929
{
1082930
foreach (HorzJoin j in this.horzJoinList)
@@ -1091,6 +939,7 @@ private void ProcessHorzJoins()
1091939
op1b.Prev = op2b;
1092940
op2b.Next = op1b;
1093941

942+
// 'join' is really a split
1094943
if (or1 == or2)
1095944
{
1096945
or2 = new OutRec
@@ -1179,7 +1028,6 @@ private void DoSplitOp(OutRec outrec, OutPt splitOp)
11791028
OutPt prevOp = splitOp.Prev;
11801029
OutPt nextNextOp = splitOp.Next.Next;
11811030
outrec.Pts = prevOp;
1182-
OutPt result = prevOp;
11831031

11841032
ClipperUtils.GetIntersectPoint(
11851033
prevOp.Point, splitOp.Point, splitOp.Next.Point, nextNextOp.Point, out Vector2 ip);
@@ -1193,11 +1041,6 @@ private void DoSplitOp(OutRec outrec, OutPt splitOp)
11931041
return;
11941042
}
11951043

1196-
// nb: area1 is the path's area *before* splitting, whereas area2 is
1197-
// the area of the triangle containing splitOp & splitOp.next.
1198-
// So the only way for these areas to have the same sign is if
1199-
// the split triangle is larger than the path containing prevOp or
1200-
// if there's more than one self=intersection.
12011044
float area2 = AreaTriangle(ip, splitOp.Point, splitOp.Next.Point);
12021045
float absArea2 = Math.Abs(area2);
12031046

@@ -1220,6 +1063,11 @@ private void DoSplitOp(OutRec outrec, OutPt splitOp)
12201063
prevOp.Next = newOp2;
12211064
}
12221065

1066+
// nb: area1 is the path's area *before* splitting, whereas area2 is
1067+
// the area of the triangle containing splitOp & splitOp.next.
1068+
// So the only way for these areas to have the same sign is if
1069+
// the split triangle is larger than the path containing prevOp or
1070+
// if there's more than one self=intersection.
12231071
if (absArea2 > 1 && (absArea2 > absArea1 || ((area2 > 0) == (area1 > 0))))
12241072
{
12251073
OutRec newOutRec = this.NewOutRec();

0 commit comments

Comments
 (0)