Skip to content

Commit ce17100

Browse files
BezrukovMiText-CI
authored andcommitted
Add ClipperBridgeTest
DEVSIX-4513 Autoported commit. Original commit hash: [f1b601954]
1 parent dd9e204 commit ce17100

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using iText.Kernel.Geom;
4+
using iText.Kernel.Pdf.Canvas;
5+
using iText.Test;
6+
7+
namespace iText.Kernel.Pdf.Canvas.Parser.ClipperLib {
8+
public class ClipperBridgeTest : ExtendedITextTest {
9+
[NUnit.Framework.Test]
10+
public virtual void SquareClippingTest() {
11+
Subpath squareSubpath = new Subpath(new Point(10, 10));
12+
squareSubpath.AddSegment(new Line(10, 10, 10, 30));
13+
squareSubpath.AddSegment(new Line(10, 30, 30, 30));
14+
squareSubpath.AddSegment(new Line(30, 30, 30, 10));
15+
squareSubpath.AddSegment(new Line(30, 10, 10, 10));
16+
squareSubpath.SetClosed(true);
17+
Path squarePath = new Path();
18+
squarePath.AddSubpath(squareSubpath);
19+
Subpath rectangleSubpath = new Subpath(new Point(20, 20));
20+
rectangleSubpath.AddSegment(new Line(20, 20, 20, 40));
21+
rectangleSubpath.AddSegment(new Line(20, 40, 30, 40));
22+
rectangleSubpath.AddSegment(new Line(30, 40, 30, 20));
23+
rectangleSubpath.AddSegment(new Line(30, 20, 20, 20));
24+
rectangleSubpath.SetClosed(true);
25+
Path rectanglePath = new Path();
26+
rectanglePath.AddSubpath(rectangleSubpath);
27+
Clipper clipper = new Clipper();
28+
ClipperBridge.AddPath(clipper, squarePath, PolyType.SUBJECT);
29+
ClipperBridge.AddPath(clipper, rectanglePath, PolyType.CLIP);
30+
PolyTree polyTree = new PolyTree();
31+
clipper.Execute(ClipType.UNION, polyTree);
32+
Path result = ClipperBridge.ConvertToPath(polyTree);
33+
NUnit.Framework.Assert.AreEqual(new Point(20, 40), result.GetCurrentPoint());
34+
NUnit.Framework.Assert.AreEqual(2, result.GetSubpaths().Count);
35+
Subpath closedPath = result.GetSubpaths()[0];
36+
NUnit.Framework.Assert.AreEqual(new Point(20, 40), closedPath.GetStartPoint());
37+
IList<IShape> closedPartSegments = closedPath.GetSegments();
38+
NUnit.Framework.Assert.AreEqual(5, closedPartSegments.Count);
39+
NUnit.Framework.Assert.IsTrue(AreShapesEqual(new Line(20, 40, 20, 30), closedPartSegments[0]));
40+
NUnit.Framework.Assert.IsTrue(AreShapesEqual(new Line(20, 30, 10, 30), closedPartSegments[1]));
41+
NUnit.Framework.Assert.IsTrue(AreShapesEqual(new Line(10, 30, 10, 10), closedPartSegments[2]));
42+
NUnit.Framework.Assert.IsTrue(AreShapesEqual(new Line(10, 10, 30, 10), closedPartSegments[3]));
43+
NUnit.Framework.Assert.IsTrue(AreShapesEqual(new Line(30, 10, 30, 40), closedPartSegments[4]));
44+
NUnit.Framework.Assert.IsTrue(closedPath.IsClosed());
45+
Subpath openPart = result.GetSubpaths()[1];
46+
NUnit.Framework.Assert.AreEqual(new Point(20, 40), openPart.GetStartPoint());
47+
NUnit.Framework.Assert.AreEqual(0, openPart.GetSegments().Count);
48+
NUnit.Framework.Assert.IsFalse(openPart.IsClosed());
49+
}
50+
51+
[NUnit.Framework.Test]
52+
public virtual void GetJoinTypeTest() {
53+
NUnit.Framework.Assert.AreEqual(JoinType.BEVEL, ClipperBridge.GetJoinType(PdfCanvasConstants.LineJoinStyle
54+
.BEVEL));
55+
NUnit.Framework.Assert.AreEqual(JoinType.MITER, ClipperBridge.GetJoinType(PdfCanvasConstants.LineJoinStyle
56+
.MITER));
57+
NUnit.Framework.Assert.AreEqual(JoinType.ROUND, ClipperBridge.GetJoinType(PdfCanvasConstants.LineJoinStyle
58+
.ROUND));
59+
}
60+
61+
[NUnit.Framework.Test]
62+
public virtual void GetEndTypeTest() {
63+
NUnit.Framework.Assert.AreEqual(EndType.OPEN_BUTT, ClipperBridge.GetEndType(PdfCanvasConstants.LineCapStyle
64+
.BUTT));
65+
NUnit.Framework.Assert.AreEqual(EndType.OPEN_SQUARE, ClipperBridge.GetEndType(PdfCanvasConstants.LineCapStyle
66+
.PROJECTING_SQUARE));
67+
NUnit.Framework.Assert.AreEqual(EndType.OPEN_ROUND, ClipperBridge.GetEndType(PdfCanvasConstants.LineCapStyle
68+
.ROUND));
69+
}
70+
71+
private bool AreShapesEqual(IShape expected, IShape actual) {
72+
if (expected == actual) {
73+
return true;
74+
}
75+
if (actual == null || expected.GetType() != actual.GetType()) {
76+
return false;
77+
}
78+
return Enumerable.SequenceEqual(expected.GetBasePoints(), actual.GetBasePoints());
79+
}
80+
}
81+
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bd1ac0434e24f939a5d3df1d3d0f1c3b1b7f9a67
1+
f1b6019542fc685d64a4448494d96225c033686b

0 commit comments

Comments
 (0)