Add missing braces

This commit is contained in:
Jason Nelson 2024-03-13 19:01:00 -07:00 committed by BobLd
parent 834fb350a3
commit 3eb01a1e0c
3 changed files with 39 additions and 10 deletions

View File

@ -76,7 +76,10 @@
public static IReadOnlyList<PdfRectangle> GetWhitespaces(IEnumerable<PdfRectangle> boundingboxes, public static IReadOnlyList<PdfRectangle> GetWhitespaces(IEnumerable<PdfRectangle> boundingboxes,
double minWidth, double minHeight, int maxRectangleCount = 40, double whitespaceFuzziness = 0.15, int maxBoundQueueSize = 0) double minWidth, double minHeight, int maxRectangleCount = 40, double whitespaceFuzziness = 0.15, int maxBoundQueueSize = 0)
{ {
if (!boundingboxes.Any()) return Array.Empty<PdfRectangle>(); if (!boundingboxes.Any())
{
return Array.Empty<PdfRectangle>();
}
var obstacles = new HashSet<PdfRectangle>(boundingboxes); var obstacles = new HashSet<PdfRectangle>(boundingboxes);
var pageBound = GetBound(obstacles); var pageBound = GetBound(obstacles);
@ -93,11 +96,11 @@
HashSet<PdfRectangle> obstacles, double minWidth, double minHeight, int maxRectangleCount, HashSet<PdfRectangle> obstacles, double minWidth, double minHeight, int maxRectangleCount,
double whitespaceFuzziness, int maxBoundQueueSize) double whitespaceFuzziness, int maxBoundQueueSize)
{ {
QueueEntries queueEntries = new QueueEntries(maxBoundQueueSize); var queueEntries = new QueueEntries(maxBoundQueueSize);
queueEntries.Enqueue(new QueueEntry(bound, obstacles, whitespaceFuzziness)); queueEntries.Enqueue(new QueueEntry(bound, obstacles, whitespaceFuzziness));
HashSet<PdfRectangle> selected = new HashSet<PdfRectangle>(); var selected = new HashSet<PdfRectangle>();
HashSet<QueueEntry> holdList = new HashSet<QueueEntry>(); var holdList = new HashSet<QueueEntry>();
while (queueEntries.Any()) while (queueEntries.Any())
{ {
@ -105,7 +108,10 @@
if (current.IsEmptyEnough(obstacles)) if (current.IsEmptyEnough(obstacles))
{ {
if (selected.Any(c => Inside(c, current.Bound))) continue; if (selected.Any(c => Inside(c, current.Bound)))
{
continue;
}
// A check was added which impeded the algorithm from accepting // A check was added which impeded the algorithm from accepting
// rectangles which were not adjacent to an already accepted // rectangles which were not adjacent to an already accepted
@ -121,7 +127,10 @@
selected.Add(current.Bound); selected.Add(current.Bound);
if (selected.Count >= maxRectangleCount) return selected.ToList(); if (selected.Count >= maxRectangleCount)
{
return selected.ToList();
}
obstacles.Add(current.Bound); obstacles.Add(current.Bound);
@ -138,8 +147,10 @@
foreach (var overlapping in queueEntries) foreach (var overlapping in queueEntries)
{ {
if (OverlapsHard(current.Bound, overlapping.Bound)) if (OverlapsHard(current.Bound, overlapping.Bound))
{
overlapping.AddWhitespace(current.Bound); overlapping.AddWhitespace(current.Bound);
} }
}
continue; continue;
} }
@ -147,7 +158,7 @@
var pivot = current.GetPivot(); var pivot = current.GetPivot();
var b = current.Bound; var b = current.Bound;
List<PdfRectangle> subRectangles = new List<PdfRectangle>(); var subRectangles = new List<PdfRectangle>();
var rRight = new PdfRectangle(pivot.Right, b.Bottom, b.Right, b.Top); var rRight = new PdfRectangle(pivot.Right, b.Bottom, b.Right, b.Top);
if (b.Right > pivot.Right && rRight.Height > minHeight && rRight.Width > minWidth) if (b.Right > pivot.Right && rRight.Height > minHeight && rRight.Width > minWidth)
@ -292,13 +303,19 @@
public bool IsEmptyEnough(IEnumerable<PdfRectangle> pageObstacles) public bool IsEmptyEnough(IEnumerable<PdfRectangle> pageObstacles)
{ {
if (IsEmptyEnough()) return true; if (IsEmptyEnough())
{
return true;
}
double sum = 0; double sum = 0;
foreach (var obstacle in pageObstacles) foreach (var obstacle in pageObstacles)
{ {
var intersect = Bound.Intersect(obstacle); var intersect = Bound.Intersect(obstacle);
if (!intersect.HasValue) return false; if (!intersect.HasValue)
{
return false;
}
double minimumArea = MinimumOverlappingArea(obstacle, Bound, whitespaceFuzziness); double minimumArea = MinimumOverlappingArea(obstacle, Bound, whitespaceFuzziness);

View File

@ -23,12 +23,21 @@ namespace UglyToad.PdfPig.AcroForms
public static IEnumerable<AcroFieldBase> GetFields(this AcroFieldBase fieldBase) public static IEnumerable<AcroFieldBase> GetFields(this AcroFieldBase fieldBase)
{ {
if (fieldBase.FieldType != AcroFieldType.Unknown) if (fieldBase.FieldType != AcroFieldType.Unknown)
{
yield return fieldBase; yield return fieldBase;
}
if (fieldBase is AcroNonTerminalField nonTerminalField) if (fieldBase is AcroNonTerminalField nonTerminalField)
{
foreach (var child in nonTerminalField.Children) foreach (var child in nonTerminalField.Children)
{
foreach (var item in child.GetFields()) foreach (var item in child.GetFields())
{
yield return item; yield return item;
} }
}
}
}
/// <summary> /// <summary>
/// Get string values of field. /// Get string values of field.

View File

@ -85,7 +85,10 @@ namespace UglyToad.PdfPig.Geometry.ClipperLibrary
public int Compare(ClipperIntersectNode node1, ClipperIntersectNode node2) public int Compare(ClipperIntersectNode node1, ClipperIntersectNode node2)
{ {
long i = node2.Pt.Y - node1.Pt.Y; long i = node2.Pt.Y - node1.Pt.Y;
if (i > 0) return 1; if (i > 0)
{
return 1;
}
return i < 0 ? -1 : 0; return i < 0 ? -1 : 0;
} }