// the function TestPerformance() measures the running time of // the nearest neighbor search in an ordered dataset of points; // // the test emulates the computation of the distance transform; // it calculates the minimum distance from each point in // the given rectangle to a point in the input dataset; static public cv.Mat TestPerformance ( int rect_width, int rect_height, List <Point> test_points ) { cv.Mat dist = new cv.Mat(rect_height, rect_width, cv.MatType.CV_32F); PointComparer pnt_comparer = new PointComparer(); test_points.Sort(pnt_comparer); Stopwatch watch = new Stopwatch(); watch.Start(); for (int x = 0; x < rect_width; ++x) { for (int y = 0; y < rect_height; ++y) { float nextVal = (float)MinDistanceOrderedSet(new Point(x, y), pnt_comparer, test_points); dist.Set <float>(y, x, nextVal); } } watch.Stop(); Console.WriteLine("execution time of ordered dataset algorithm = {0} ms ;", watch.ElapsedMilliseconds); return(dist); }
public void AddMethod_PointWithComparer_BinaryTree() { var point1 = new Point(12, 10); var point2 = new Point(20, 10); var point3 = new Point(6, 8); var point4 = new Point(3, 5); var point5 = new Point(5, 1); var point6 = new Point(3, 10); var comparer = new PointComparer(); BinarySearchTree <Point> tree = new BinarySearchTree <Point>(new Point[] { point1, point2, point3, point4, point5, point6 }, comparer); List <Point> actual = new List <Point>(); foreach (var item in tree) { actual.Add(item); } List <Point> expected = new List <Point>() { point5, point4, point6, point3, point1, point2 }; Assert.AreEqual(expected, actual); }
private bool WasTargetWalked(IList <Point> currentRoute) { var pointComparer = new PointComparer(); foreach (var foundRoute in _foundRoutes) { if (foundRoute.Count == currentRoute.Count) { var areSame = true; for (int i = 0; i < foundRoute.Count; i++) { if (!pointComparer.Equals(foundRoute[i], currentRoute[i])) { areSame = false; break; } } if (areSame) { return(true); } } } return(false); }
public void Initialize() { List <Point> points = new List <Point> { new Point() { X = 6, Y = 5 }, new Point() { X = 1, Y = 4 }, new Point() { X = 2, Y = 7 }, new Point() { X = 6, Y = 6 }, new Point() { X = 3, Y = 3 }, }; PointComparer pointComparer = new PointComparer(); PointTree = new Tree <Point>(pointComparer); foreach (Point point in points) { PointTree.Add(point); } }
public void CorrectBoundingBoxesFlexPoints() { PointComparer pointComparer = new PointComparer(new DoubleComparer(3)); var documentFolder = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Integration", "Documents")); var filePath = Path.Combine(documentFolder, "data.pdf"); using (var doc = PdfDocument.Open(filePath)) { var page = doc.GetPage(1); var letters = page.Letters; // check 'm' var m = letters[0]; Assert.Equal("m", m.Value); Assert.Equal(new PdfPoint(253.4458, 658.431), m.GlyphRectangle.BottomLeft, pointComparer); Assert.Equal(new PdfPoint(261.22659, 662.83446), m.GlyphRectangle.TopRight, pointComparer); // check 'p' var p = letters[1]; Assert.Equal("p", p.Value); Assert.Equal(new PdfPoint(261.70778, 656.49825), p.GlyphRectangle.BottomLeft, pointComparer); Assert.Equal(new PdfPoint(266.6193, 662.83446), p.GlyphRectangle.TopRight, pointComparer); } }
private void HighlightRoute(IList <Point> route) { var pointComparer = new PointComparer(); for (int i = 1; i <= _targetPosition.Y; i++) { for (int j = 1; j <= _targetPosition.X; j++) { var gridData = tilesContainer.Children.GetData(new Point { X = j, Y = i }); if (route.Any(r => pointComparer.Equals(r, gridData.Position))) { gridData.Background = Utilities.CurrentAreaTileColor(); gridData.BorderBrush = Utilities.CurrentAreaBorderColor(); } else { gridData.Background = Utilities.InnerAreaTileColor(); gridData.BorderBrush = Utilities.InnerAreaBorderColor(); } } } }
public SelectionService(Terminal terminal) { this.terminal = terminal; comparer = new PointComparer(); nullString = NStack.ustring.Make(CharData.Null.Rune); spaceString = NStack.ustring.Make(" "); }
// the function LowerBound() implements a binary search, // which in terms of operator < returns the first position // that satisfies the following condition: // ! ( points_ordered[pos] < point_in ) == true ; // // the computational complexity is O(log N), // where N is the number of points in a dataset; static protected int LowerBound ( List <Point> points_ordered, PointComparer pnt_comparer_in, Point point_in ) { int i_low = 0; int i_high = points_ordered.Count; int i_mid = 0; while (i_low < i_high) { i_mid = (i_low + i_high) / 2; if (pnt_comparer_in.Compare(points_ordered[i_mid], point_in) < 0) { i_low = i_mid + 1; } else { i_high = i_mid; } } return(i_low); }
public void TreeWithPointProvider(CustomPoint[] point, CustomPoint[] resultPoint, IComparer<CustomPoint> comparer) { var tree = new BinaryTree<CustomPoint>(point, comparer); var pointCompare = new PointComparer(); var enumeratorBook = tree.Preorder().ToArray(); CollectionAssert.AreEqual(enumeratorBook, resultPoint, pointCompare); }
public void CanAddHelloWorldToSimplePage() { var path = IntegrationHelpers.GetDocumentPath("Single Page Simple - from open office.pdf"); var doc = PdfDocument.Open(path); var builder = new PdfDocumentBuilder(); var page = builder.AddPage(doc, 1); page.DrawLine(new PdfPoint(30, 520), new PdfPoint(360, 520)); page.DrawLine(new PdfPoint(360, 520), new PdfPoint(360, 250)); page.SetStrokeColor(250, 132, 131); page.DrawLine(new PdfPoint(25, 70), new PdfPoint(100, 70), 3); page.ResetColor(); page.DrawRectangle(new PdfPoint(30, 200), 250, 100, 0.5m); page.DrawRectangle(new PdfPoint(30, 100), 250, 100, 0.5m); var file = TrueTypeTestHelper.GetFileBytes("Andada-Regular.ttf"); var font = builder.AddTrueTypeFont(file); var letters = page.AddText("Hello World!", 12, new PdfPoint(30, 50), font); Assert.NotEmpty(page.CurrentStream.Operations); var b = builder.Build(); WriteFile(nameof(CanAddHelloWorldToSimplePage), b); Assert.NotEmpty(b); using (var document = PdfDocument.Open(b)) { var page1 = document.GetPage(1); Assert.Equal("I am a simple pdf.Hello World!", page1.Text); var h = page1.Letters[18]; Assert.Equal("H", h.Value); Assert.Equal("Andada-Regular", h.FontName); var comparer = new DoubleComparer(0.01); var pointComparer = new PointComparer(comparer); for (int i = 0; i < letters.Count; i++) { var readerLetter = page1.Letters[i + 18]; var writerLetter = letters[i]; Assert.Equal(readerLetter.Value, writerLetter.Value); Assert.Equal(readerLetter.Location, writerLetter.Location, pointComparer); Assert.Equal(readerLetter.FontSize, writerLetter.FontSize, comparer); Assert.Equal(readerLetter.GlyphRectangle.Width, writerLetter.GlyphRectangle.Width, comparer); Assert.Equal(readerLetter.GlyphRectangle.Height, writerLetter.GlyphRectangle.Height, comparer); Assert.Equal(readerLetter.GlyphRectangle.BottomLeft, writerLetter.GlyphRectangle.BottomLeft, pointComparer); } } }
public void PointComparer_MustReturn2() { var point1 = new Point(1, 3); var point2 = new Point(3, 1); var result = new PointComparer().Compare(point1, point2); Assert.AreEqual(result, 0); }
public static List<Point> GetCircle(int Xc, int Yc, int R) { List<Point> points = new List<Point>(); int x = 0; int y = R; int d = 2 * (1 - R); while (y >= 0) { points.Add(new Point(Xc + x, Yc + y)); points.Add(new Point(Xc + x, Yc - y)); points.Add(new Point(Xc - x, Yc + y)); points.Add(new Point(Xc - x, Yc - y)); if (d < 0) { if (2 * (d + y) - 1 <= 0) { x++; d += 2 * x + 1; } else { x++; y--; d += 2 * x - 2 * y + 2; } } else if (d > 0) { if (2 * d - 2 * x - 1 <= 0) { x++; y--; d += 2 * x - 2 * y + 2; } else { y--; d = d - 2 * y + 1; } } else { x++; y--; d += 2 * x - 2 * y + 2; } } PointComparer pc = new PointComparer(); var buf = (from p in points select p).Distinct(pc); return buf.ToList(); }
public void BinaryTree_CustomTypeCustomComparer_ExpetedResult() { Point p1 = new Point() { x = 7, y = 10, z = 10 }; Point p2 = new Point() { x = 4, y = 5, z = 5 }; Point p3 = new Point() { x = 5, y = 3, z = 2 }; Point p4 = new Point() { x = 9, y = 4, z = 6 }; Point p5 = new Point() { x = 7, y = 13, z = 15 }; Point p6 = new Point() { x = 2, y = 22, z = 18 }; Point p7 = new Point() { x = 13, y = 9, z = 9 }; PointComparer comp = new PointComparer(); BinaryTree <Point> tree = new BinaryTree <Point>(comp.Compare); tree.AddElement(p1); tree.AddElement(p2); tree.AddElement(p3); tree.AddElement(p4); tree.AddElement(p5); tree.AddElement(p6); tree.AddElement(p7); Point[] expected = { p3, p2, p4, p1, p7, p5, p6 }; Point[] actual = new Point[expected.Length]; int i = 0; foreach (Point point in tree.InorderTraversal()) { actual[i++] = point; } Assert.AreEqual(expected, actual); }
public static List <List <Point> > Dist(List <List <Point> > points) { var results = new List <List <Point> >(); var comparer = new PointComparer(); foreach (var lst in points) { results.Add(lst.Distinct(comparer).ToList()); } return(results); }
private void WriteObstaclePort(Shape shape, Port port) { Validate.IsFalse(portToIdMap.ContainsKey(port), "Duplicate entries for port in the same or different shape.Ports list(s)"); var relativePort = port as RelativeFloatingPort; if (null != relativePort) { Validate.IsTrue(PointComparer.Equal(shape.BoundingBox.Center, relativePort.CenterDelegate()), "Port CenterDelegate must be Shape.Center for file persistence"); Validate.AreEqual(shape.BoundaryCurve, port.Curve, "Port curve is not the same as that of the Shape in which it is a member"); } portToIdMap.Add(port, NextPortId); WritePort(port, shapeToIdMap[shape]); }
public virtual void OneColumn(IEnumerable <TItem> items, AlignerOptions options) { var comparer = new PointComparer { Order = options.PointOrder, Delta = options.PointOrderDelta }; var colItems = items.OrderBy(item => Locator.GetLocation(item), comparer); var bounds = new Rectangle(int.MaxValue, int.MaxValue, 0, 0); MeasureColumn(colItems, options, ref bounds); var colPos = bounds.Location; var locator = new LocateVisitBuilder <TItem>(this.Locator); LocateColumn(colItems, bounds, bounds, ref colPos, locator, options); }
public void LineIntersection_Smoke_Test() { var pointComparer = new PointComparer(); var line1 = new Line(new Point(1, 1), new Point(10, 1)); var line2 = new Line(new Point(1, 2), new Point(10, 2)); Assert.IsTrue(pointComparer.Equals(null, LineIntersection.Find(line1, line2))); line1 = new Line(new Point(10, 0), new Point(0, 10)); line2 = new Line(new Point(0, 10), new Point(10, 10)); Assert.IsTrue(pointComparer.Equals(new Point(0, 10), LineIntersection.Find(line1, line2))); line1 = new Line(new Point(0, 0), new Point(10, 10)); line2 = new Line(new Point(0, 10), new Point(10, 10)); Assert.IsTrue(pointComparer.Equals(new Point(10, 10), LineIntersection.Find(line1, line2))); line1 = new Line(new Point(10, 0), new Point(0, 10)); line2 = new Line(new Point(0, 0), new Point(10, 10)); Assert.IsTrue(pointComparer.Equals(new Point(5, 5), LineIntersection.Find(line1, line2))); line1 = new Line(new Point(-5, -5), new Point(0, 0)); line2 = new Line(new Point(1, 1), new Point(10, 10)); Assert.IsTrue(pointComparer.Equals(default(Point), LineIntersection.Find(line1, line2))); line1 = new Line(new Point(3, -5), new Point(3, 10)); line2 = new Line(new Point(0, 5), new Point(10, 5)); Assert.IsTrue(pointComparer.Equals(new Point(3, 5), LineIntersection.Find(line1, line2))); line1 = new Line(new Point(0, 5), new Point(10, 5)); line2 = new Line(new Point(3, -5), new Point(3, 10)); Assert.IsTrue(pointComparer.Equals(new Point(3, 5), LineIntersection.Find(line1, line2))); line1 = new Line(new Point(0, 5), new Point(10, 5)); line2 = new Line(new Point(3, -5), new Point(5, 15)); Assert.IsTrue(pointComparer.Equals(new Point(4, 5), LineIntersection.Find(line1, line2))); line1 = new Line(new Point(0, -5), new Point(0, 5)); line2 = new Line(new Point(-3, 0), new Point(3, 0)); Assert.IsTrue(pointComparer.Equals(new Point(0, 0), LineIntersection.Find(line1, line2))); }
public void BinarySearchTree_Point_Remove_NegativeTest() { var point1 = new Point(10, 10); var point2 = new Point(20, 20); var point3 = new Point(30, 30); var point4 = new Point(40, 40); Point[] items = new Point[] { point1, point2, point3, point4 }; var comparer = new PointComparer(); var testTree = new BinarySearchTree <Point>(items, comparer); var point5 = new Point(50, 50); testTree.Remove(point5); Assert.AreEqual(items.Length, testTree.Count); }
public void BinarySearchTree_Point_Remove_PositiveTest() { Point point1 = new Point(10, 10); Point point2 = new Point(20, 20); Point point3 = new Point(30, 30); Point point4 = new Point(40, 40); Point[] items = new Point[] { point1, point2, point3, point4 }; var comparer = new PointComparer(); var testTree = new BinarySearchTree <Point>(items, comparer); testTree.Remove(point2); Assert.AreEqual(items.Length - 1, testTree.Count); Assert.IsFalse(testTree.Contains(point2)); }
IList <Rectangle> CalculateFreeSpace(Point start, Size sizeNeeded, Dimension dimension, IEnumerable <TItem> ignore, double distance) { var h = dimension == Dimension.X ? sizeNeeded.Height : GraphScene.Shape.Size.Height; var w = dimension == Dimension.X ? GraphScene.Shape.Size.Width : sizeNeeded.Width; var iRect = new Rectangle(start, new Size(w, h)); var comparer = new PointComparer { Order = dimension == Dimension.X ? PointOrder.X : PointOrder.Y }; var loc = new GraphSceneItemShapeLocator <TItem, TEdge> { GraphScene = this.GraphScene }; var elems = GraphScene.ElementsIn(iRect) .Where(e => !(e is TEdge)).Except(ignore).OrderBy(e => loc.GetLocation(e), comparer); return(new Rectangle[0]); }
private void display(List <Advanced.Algorithms.Geometry.Line> lines, List <Advanced.Algorithms.Geometry.Point> expectedIntersections, List <Advanced.Algorithms.Geometry.Point> actualIntersections) { myGrid.Children.Clear(); var canvas = new Canvas(); foreach (var line in lines) { // Add a Line Element var myLine = new System.Windows.Shapes.Line(); myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue; myLine.X1 = line.Left.X; myLine.X2 = line.Right.X; myLine.Y1 = line.Left.Y; myLine.Y2 = line.Right.Y; myLine.HorizontalAlignment = HorizontalAlignment.Left; myLine.VerticalAlignment = VerticalAlignment.Center; myLine.StrokeThickness = 2; canvas.Children.Add(myLine); setPoint(canvas, line.Left, true); setPoint(canvas, line.Right, true); } var comparer = new PointComparer(tolerance); expectedIntersections .RemoveAll(x => actualIntersections.Any(y => comparer.Equals(x, y))); foreach (var point in expectedIntersections) { setPoint(canvas, point, false); } foreach (var point in actualIntersections) { setPoint(canvas, point, true); } myGrid.Children.Add(canvas); }
public void BinarySearchTree_Point_Comparer_TraverseTest() { var point1 = new Point(10, 10); var point2 = new Point(20, 20); var point3 = new Point(30, 30); var point4 = new Point(40, 40); var point5 = new Point(50, 50); var point6 = new Point(60, 60); var point7 = new Point(70, 70); Point[] items = new Point[] { point2, point1, point6, point3, point5, point4, point7 }; var comparer = new PointComparer(); var testTree = new BinarySearchTree <Point>(items, comparer); var inOrderTree = new Point[testTree.Count]; int i = 0; foreach (var item in testTree.InOrder()) { inOrderTree[i] = item; i++; } var preOrderTree = new Point[testTree.Count]; i = 0; foreach (var item in testTree.PreOrder()) { preOrderTree[i] = item; i++; } var postOrderTree = new Point[testTree.Count]; i = 0; foreach (var item in testTree.PostOrder()) { postOrderTree[i] = item; i++; } CollectionAssert.AreEqual(new Point[] { point1, point2, point3, point4, point5, point6, point7 }, inOrderTree); CollectionAssert.AreEqual(new Point[] { point2, point1, point6, point3, point5, point4, point7 }, preOrderTree); CollectionAssert.AreEqual(new Point[] { point1, point4, point5, point3, point7, point6, point2 }, postOrderTree); }
// the function MinDistanceOrderedSet() implements // the nearest neighbor search in an ordered set of points; // its average computational complexity - O ( sqrt(N) ) , // where N is the number of points in the set; static protected uint MinDistanceOrderedSet ( Point point_in, PointComparer pnt_comparer_in, List <Point> points_ordered ) { uint dist_min = uint.MaxValue; int i_start = 0; int i_end = points_ordered.Count; int i_low_bound = 0; i_low_bound = LowerBound(points_ordered, pnt_comparer_in, point_in); FindForward(point_in, i_low_bound, i_end, points_ordered, ref dist_min); FindBackward(point_in, i_low_bound, i_start, points_ordered, ref dist_min); return(dist_min); }
public virtual void Columns(IEnumerable <TItem> items, AlignerOptions options) { var comparer = new PointComparer { Order = options.PointOrder, Delta = options.PointOrderDelta }; var walk = items.Select(item => new { location = comparer.Round(Locator.GetLocation(item)), item }); var bounds = new Rectangle(int.MaxValue, int.MaxValue, 0, 0); var cols = new Queue <Tuple <IEnumerable <TItem>, Rectangle> >(); foreach (var col in walk.GroupBy(row => row.location.X).OrderBy(row => row.Key)) { var colItems = col.Select(r => r.item).OrderBy(item => Locator.GetLocation(item).Y); cols.Enqueue(MeasureColumn(colItems, options, ref bounds)); } LocateColumns(cols, bounds, options); }
public override int GetHashCode() { PointComparer comparer = new PointComparer(); return(comparer.GetHashCode(this)); }
public SelectionService(Terminal terminal) { this.terminal = terminal; comparer = new PointComparer(); }
/// <summary> /// 构造函数,参数为大地坐标 /// </summary> /// <param name="start">大地坐标</param> /// <param name="end">大地坐标</param> public LineCrossGrid3D(Point start, Point end) { this.isCalc = this.Init(); if (!this.isCalc) { return; } GridHelper.getInstance().getMaxGGridXY(ref this.maxgxid, ref this.maxgyid); this.isCalc = !PointComparer.Equals1(start, end) && GridHelper.getInstance().PointXYZToGrid3D(start, ref this.cur); if (!this.isCalc) { return; } Vector3D dir = Vector3D.constructVector(start, end); this.line.setLine(start, dir); this.stepx = (this.line.paraEqua.X < 0 ? -1 : 1); this.stepy = (this.line.paraEqua.Y < 0 ? -1 : 1); this.stepz = (this.line.paraEqua.Z < 0 ? -1 : 1); Point ingrid = new Point(); this.isCalc = GridHelper.getInstance().PointXYZInGrid3D(start, ref ingrid); if (!this.isCalc) { return; } if (Math.Round(this.line.paraEqua.X, 3) == 0) { this.tx = this.dx = maxlength; } else if (this.line.paraEqua.X > 0) { this.dx = this.gridlength / this.line.paraEqua.X; this.tx = (this.gridlength - ingrid.X) / this.line.paraEqua.X; } else { this.dx = this.gridlength / (0 - this.line.paraEqua.X); this.tx = ingrid.X / (0 - this.line.paraEqua.X); } if (Math.Round(this.line.paraEqua.Y, 3) == 0) { this.ty = this.dy = maxlength; } else if (this.line.paraEqua.Y > 0) { this.dy = this.gridlength / this.line.paraEqua.Y; this.ty = (this.gridlength - ingrid.Y) / this.line.paraEqua.Y; } else { this.dy = this.gridlength / (0 - this.line.paraEqua.Y); this.ty = ingrid.Y / (0 - this.line.paraEqua.Y); } if (Math.Round(this.line.paraEqua.Z, 3) == 0) { this.tz = this.dz = maxlength;//因为tz太大,dz随便定义 } else if (this.line.paraEqua.Z > 0) { this.dz = this.vgridsize / this.line.paraEqua.Z; this.tz = (this.vgridsize - ingrid.Z) / this.line.paraEqua.Z; } else if (this.line.paraEqua.Z < 0) { this.dz = this.vgridsize / (0 - this.line.paraEqua.Z); this.tz = ingrid.Z / (0 - this.line.paraEqua.Z); } }
public override bool Equals(object obj) { PointComparer comparer = new PointComparer(); return(comparer.Equals(this, (Point)obj)); }
public void WindowsOnlyCanWriteSinglePageHelloWorldSystemFont() { var builder = new PdfDocumentBuilder(); builder.DocumentInformation.Title = "Hello Windows!"; var page = builder.AddPage(PageSize.A4); var file = @"C:\Windows\Fonts\BASKVILL.TTF"; if (!File.Exists(file)) { return; } byte[] bytes; try { bytes = File.ReadAllBytes(file); } catch { return; } var font = builder.AddTrueTypeFont(bytes); var letters = page.AddText("Hello World!", 16, new PdfPoint(30, 520), font); page.AddText("This is some further text continuing to write", 12, new PdfPoint(30, 500), font); Assert.NotEmpty(page.Operations); var b = builder.Build(); WriteFile(nameof(WindowsOnlyCanWriteSinglePageHelloWorldSystemFont), b); Assert.NotEmpty(b); using (var document = PdfDocument.Open(b)) { var page1 = document.GetPage(1); Assert.StartsWith("Hello World!", page1.Text); var h = page1.Letters[0]; Assert.Equal("H", h.Value); Assert.Equal("BaskOldFace", h.FontName); var comparer = new DoubleComparer(0.01); var pointComparer = new PointComparer(comparer); for (int i = 0; i < letters.Count; i++) { var readerLetter = page1.Letters[i]; var writerLetter = letters[i]; Assert.Equal(readerLetter.Value, writerLetter.Value); Assert.Equal(readerLetter.Location, writerLetter.Location, pointComparer); Assert.Equal(readerLetter.FontSize, writerLetter.FontSize, comparer); Assert.Equal(readerLetter.GlyphRectangle.Width, writerLetter.GlyphRectangle.Width, comparer); Assert.Equal(readerLetter.GlyphRectangle.Height, writerLetter.GlyphRectangle.Height, comparer); Assert.Equal(readerLetter.GlyphRectangle.BottomLeft, writerLetter.GlyphRectangle.BottomLeft, pointComparer); } } }
/// <summary> /// Extract the <see cref="PageArea"/>, with its text elements (letters) and rulings (processed PdfPath and PdfSubpath). /// </summary> /// <param name="pageNumber">The page number to extract.</param> public PageArea ExtractPage(int pageNumber) { if (pageNumber > this.pdfDocument.NumberOfPages || pageNumber < 1) { throw new IndexOutOfRangeException("Page number does not exist"); } Page p = this.pdfDocument.GetPage(pageNumber); //ObjectExtractorStreamEngine se = new ObjectExtractorStreamEngine(p); //se.processPage(p); /**************** ObjectExtractorStreamEngine(PDPage page)*******************/ var rulings = new List <Ruling>(); foreach (var image in p.GetImages()) { if (image.TryGetPng(out var png)) { } } foreach (var path in p.ExperimentalAccess.Paths) { if (!path.IsFilled && !path.IsStroked) { continue; // strokeOrFillPath operator => filter stroke and filled } foreach (var subpath in path) { if (!(subpath.Commands[0] is Move first)) { // skip paths whose first operation is not a MOVETO continue; } if (subpath.Commands.Any(c => c is BezierCurve)) { // or contains operations other than LINETO, MOVETO or CLOSE // bobld: skip at subpath or path level? continue; } // TODO: how to implement color filter? PdfPoint? start_pos = RoundPdfPoint(first.Location, rounding); PdfPoint? last_move = start_pos; PdfPoint? end_pos = null; PdfLine line; PointComparer pc = new PointComparer(); foreach (var command in subpath.Commands) { if (command is Line linePath) { end_pos = RoundPdfPoint(linePath.To, rounding); if (!start_pos.HasValue || !end_pos.HasValue) { break; } line = pc.Compare(start_pos.Value, end_pos.Value) == -1 ? new PdfLine(start_pos.Value, end_pos.Value) : new PdfLine(end_pos.Value, start_pos.Value); // already clipped Ruling r = new Ruling(line.Point1, line.Point2); if (r.Length > 0.01) { rulings.Add(r); } } else if (command is Move move) { start_pos = RoundPdfPoint(move.Location, rounding); end_pos = start_pos; } else if (command is Close) { // according to PathIterator docs: // "the preceding subpath should be closed by appending a line // segment // back to the point corresponding to the most recent // SEG_MOVETO." if (!start_pos.HasValue || !end_pos.HasValue) { break; } line = pc.Compare(end_pos.Value, last_move.Value) == -1 ? new PdfLine(end_pos.Value, last_move.Value) : new PdfLine(last_move.Value, end_pos.Value); // already clipped Ruling r = new Ruling(line.Point1, line.Point2); //.intersect(this.currentClippingPath()); if (r.Length > 0.01) { rulings.Add(r); } } start_pos = end_pos; } } } /****************************************************************************/ TextStripper pdfTextStripper = new TextStripper(this.pdfDocument, pageNumber); pdfTextStripper.Process(); Utils.Sort(pdfTextStripper.textElements, new TableRectangle.ILL_DEFINED_ORDER()); return(new PageArea(p.CropBox.Bounds, p.Rotation.Value, pageNumber, p, this.pdfDocument, pdfTextStripper.textElements, rulings, pdfTextStripper.minCharWidth, pdfTextStripper.minCharHeight, pdfTextStripper.spatialIndex)); }
/// <inheritdoc /> public PackingResult PlaceRects(int width, int height, IEnumerable <PPRect> rects, CancellationToken token = default) { Progress = 0; if (width < 0 || height < 0) { throw new ArgumentOutOfRangeException($"The {nameof(width)} and {nameof(height)} should be non-negative"); } var sortedInput = sorter.SortImages(rects); int inputSize = rects.Count(); int placedRects = 0; int actualWidth = 0; int actualHeight = 0; RectComparer rectComparer = new RectComparer(); PointComparer ptComparer = new PointComparer(); SortedSet <PPRect> currentPacking = new SortedSet <PPRect>(rectComparer); SortedDictionary <SKPointI, int> pointsToTry = new SortedDictionary <SKPointI, int>(ptComparer) { { new SKPointI(0, 0), -1 } //the current packing is empty, so only point to try is point [0,0] }; SKPointI[] pointsToAdd = new SKPointI[2]; foreach (var x in sortedInput) { if (token.IsCancellationRequested) { Progress = 0; return(null); } SKPointI?pointToRemove = null; foreach (var ptToTry in pointsToTry) { PPRect tested = new PPRect(ptToTry.Key.X, ptToTry.Key.Y, ptToTry.Key.X + x.Width, ptToTry.Key.Y + x.Height); var possibleIntersections = currentPacking.AsEnumerable(); //have to test everything if (ptToTry.Key.X + x.Width <= width && ptToTry.Key.Y + x.Height <= height && !Intersects(tested, possibleIntersections)) //safe to pack here { if (ptToTry.Key.X + x.Width > actualWidth) { actualWidth = ptToTry.Key.X + x.Width; } if (ptToTry.Key.Y + x.Height > actualHeight) { actualHeight = ptToTry.Key.Y + x.Height; } int improved = 0; if (TryImprove(ref tested, currentPacking, 0)) //Try to position it further to the top / left { improved++; } //Add it to the packing tested.Image = x.Image; currentPacking.Add(tested); if (improved == 0) { pointToRemove = ptToTry.Key; } pointsToAdd[0] = new SKPointI(ptToTry.Key.X + x.Width, ptToTry.Key.Y); pointsToAdd[1] = new SKPointI(ptToTry.Key.X, ptToTry.Key.Y + x.Height); break; } } if (pointToRemove != null) { pointsToTry.Remove(pointToRemove.Value); pointsToTry[pointsToAdd[0]] = -1; pointsToTry[pointsToAdd[1]] = -1; Progress = (int)((++placedRects / (double)inputSize) * 100.0); ProgressChange?.Invoke(this, Progress); } else { Progress = 100; return(null); //we cannot pack it anywhere } } //var result = new PackingResult(width, height, currentPacking.Select(x => (x.Value, x.Key))); // probably better to return result with actual width & height instead of those needed //actual height can be lower than height specified, width also BUT THIS IS NOT DESIRED, BECAUSE THIS CAN BE CALLED FROM FIXEDSIZE..? OR chhange size in FixedSize.. var result = new PackingResult(actualWidth, actualHeight, currentPacking); return(result); }