Skip to content

Commit 1534c4e

Browse files
guustysebieiText-CI
authored andcommitted
Add width and height calculation
DEVSIX-8365 Autoported commit. Original commit hash: [e054c7abf]
1 parent 590f4fb commit 1534c4e

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

itext.tests/itext.kernel.tests/itext/kernel/pdf/canvas/parser/clipperlib/ClipperBridgeTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ public virtual void GetEndTypeTest() {
9191
.ROUND));
9292
}
9393

94+
[NUnit.Framework.Test]
95+
public virtual void LongRectWidthTest() {
96+
IntRect longRect = new IntRect(14900000000000000L, 21275000000000000L, 71065802001953128L, 71075000000000000L
97+
);
98+
NUnit.Framework.Assert.AreEqual(561.658, ClipperBridge.LongRectCalculateWidth(longRect), 0.001f);
99+
}
100+
101+
[NUnit.Framework.Test]
102+
public virtual void LongRectHeightTest() {
103+
IntRect longRect = new IntRect(14900000000000000L, 21275000000000000L, 71065802001953128L, 71075000000000000L
104+
);
105+
NUnit.Framework.Assert.AreEqual(498, ClipperBridge.LongRectCalculateHeight(longRect), 0.001f);
106+
}
107+
94108
private bool AreShapesEqual(IShape expected, IShape actual) {
95109
if (expected == actual) {
96110
return true;

itext/itext.kernel/itext/kernel/pdf/canvas/parser/clipperlib/ClipperBridge.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,38 @@ public static bool AddPolylineSubjectToClipper(Clipper clipper, Point[] lineVert
423423
)))), PolyType.SUBJECT, false);
424424
}
425425

426+
/// <summary>
427+
/// Calculates the width of the rectangle represented by the
428+
/// <see cref="IntRect"/>
429+
/// object.
430+
/// </summary>
431+
/// <param name="rect">
432+
/// the
433+
/// <see cref="IntRect"/>
434+
/// object representing the rectangle.
435+
/// </param>
436+
/// <returns>the width of the rectangle.</returns>
437+
public static float LongRectCalculateWidth(IntRect rect) {
438+
return (float)(Math.Abs(rect.left - rect.right) / iText.Kernel.Pdf.Canvas.Parser.ClipperLib.ClipperBridge.
439+
floatMultiplier);
440+
}
441+
442+
/// <summary>
443+
/// Calculates the height of the rectangle represented by the
444+
/// <see cref="IntRect"/>
445+
/// object.
446+
/// </summary>
447+
/// <param name="rect">
448+
/// the
449+
/// <see cref="IntRect"/>
450+
/// object representing the rectangle.
451+
/// </param>
452+
/// <returns>the height of the rectangle.</returns>
453+
public static float LongRectCalculateHeight(IntRect rect) {
454+
return (float)(Math.Abs(rect.top - rect.bottom) / iText.Kernel.Pdf.Canvas.Parser.ClipperLib.ClipperBridge.
455+
floatMultiplier);
456+
}
457+
426458
//\cond DO_NOT_DOCUMENT
427459
internal static void AddContour(Path path, IList<IntPoint> contour, bool close) {
428460
IList<Point> floatContour = ConvertToFloatPoints(contour);

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7bf6f0defb541e16cd1470ac7555cbf8dc92bb6d
1+
e054c7abf957145ef4dcd2d3a8628b7c8bf24b7a

0 commit comments

Comments
 (0)